Skip to content

Exposing Ilogger support on constructors and clone. #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Build.Common.StandardAndLegacy.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFrameworks)' == ''">
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks Condition="'$(OutputType)' != 'Exe'">netstandard2.0;net462</TargetFrameworks>
Expand Down
4 changes: 4 additions & 0 deletions src/Build.Common.core.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project>
<!-- dotnetCore specific msbuild properties: -->
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup Condition="'$(ProjectSpecificFx)' == ''">
<TargetFrameworks>net462;net472;net48;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down
1 change: 1 addition & 0 deletions src/Build.Common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<!-- .NET Classic (v5.62) specific msbuild properties: -->
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/Build.Shared.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<!-- msbuild properties shared for dotnetCore and .NET classic projects: -->
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<PackageVersion_AppInsights>2.9.1</PackageVersion_AppInsights>
<PackageVersion_Adal>3.19.8</PackageVersion_Adal>
<PackageVersion_MSAL>4.25.0</PackageVersion_MSAL>
Expand All @@ -17,7 +18,7 @@

<PropertyGroup>
<!-- this property must be re-defined in individual .csprojs or a .props file per component area -->
<ComponentAreaName Condition="'$(ComponentAreaName)' == ''">FORGOT-To-Set-ComponentAreaName</ComponentAreaName>
<ComponentAreaName Condition="'$(ComponentAreaName)' == ''">FORGOT-To-Set-ComponentAreaName</ComponentAreaName>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -44,7 +45,6 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down
416 changes: 210 additions & 206 deletions src/GeneralTools/DataverseClient/Client/ConnectionService.cs

Large diffs are not rendered by default.

900 changes: 461 additions & 439 deletions src/GeneralTools/DataverseClient/Client/ServiceClient.cs

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/GeneralTools/DataverseClient/Client/TraceLoggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Microsoft.PowerPlatform.Dataverse.Client
{
/// <summary>
/// TraceLoggerBase Class.
/// TraceLoggerBase Class.
/// </summary>
[LocalizableAttribute(false)]
#pragma warning disable CA1063 // Implement IDisposable Correctly
Expand All @@ -35,7 +35,7 @@ public abstract class TraceLoggerBase : IDisposable
private Exception _lastException = null;

private TraceSource _source;

#endregion

#region Protected fields
Expand All @@ -62,7 +62,7 @@ protected TraceSource Source
System.Diagnostics.EventLog.WriteEntry("application", errMsg, System.Diagnostics.EventLogEntryType.Error);
#endif
}
catch
catch
{
//error in writing to event log
string log = string.Format("UNABLE TO WRITE TO EVENT LOG FOR: {0}", errMsg);
Expand Down Expand Up @@ -109,7 +109,7 @@ public string LastError
set { _lastError = value; }
}
/// <summary>
/// Last Exception from CRM
/// Last Exception from CRM
/// </summary>
public Exception LastException
{
Expand All @@ -118,7 +118,7 @@ public Exception LastException
}

/// <summary>
/// Current Trace level
/// Current Trace level
/// </summary>
public SourceLevels CurrentTraceLevel
{
Expand All @@ -137,7 +137,7 @@ protected TraceLoggerBase()
}

/// <summary>
/// Initialize Trace Source
/// Initialize Trace Source
/// </summary>
protected void Initialize()
{
Expand All @@ -148,20 +148,20 @@ protected void Initialize()
RefreshListeners(TraceSourceSettingStore.TraceSourceSettingsCollection);
}
}

/// <summary>
/// Reset the last Stored Error
/// </summary>
public abstract void ResetLastError();

/// <summary>
/// Log a Message as an Information event.
/// Log a Message as an Information event.
/// </summary>
/// <param name="message"></param>
public abstract void Log(string message);

/// <summary>
/// Log a Trace event
/// Log a Trace event
/// </summary>
/// <param name="message"></param>
/// <param name="eventType"></param>
Expand Down Expand Up @@ -203,13 +203,13 @@ public void RefreshListeners(List<TraceSourceSetting> traceSourceSettingCollecti
#region IDisposable Support

/// <summary>
///
///
/// </summary>
#pragma warning disable CA1063 // Implement IDisposable Correctly
public void Dispose()
#pragma warning restore CA1063 // Implement IDisposable Correctly
{
// Always need this to be called.
// Always need this to be called.
TraceListenerBroker.UnRegisterTraceLogger(this);
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
using System.ServiceModel.Description;
using Microsoft.PowerPlatform.Dataverse.Client.Model;
using Microsoft.PowerPlatform.Dataverse.Client.Auth;
using Microsoft.Extensions.Logging;

namespace Microsoft.PowerPlatform.Dataverse.Client
{
/// <summary>
/// Stores Parsed connection info from the use of a CDS connection string.
/// This is only populated when the CDS Connection string object is used, this is read only.
/// Stores Parsed connection info from the use of a CDS connection string.
/// This is only populated when the CDS Connection string object is used, this is read only.
/// </summary>
internal class DataverseConnectionStringProcessor
{
Expand Down Expand Up @@ -120,7 +121,7 @@ internal string Password
internal string CertThumbprint { get; set; }

/// <summary>
/// if set to true, then the org URI should be used directly.
/// if set to true, then the org URI should be used directly.
/// </summary>
internal bool SkipDiscovery { get; set; }

Expand Down Expand Up @@ -188,20 +189,20 @@ public string TokenCacheStorePath
}

/// <summary>
/// When true, specifies a unique instance of the connection should be created.
/// When true, specifies a unique instance of the connection should be created.
/// </summary>
public bool UseUniqueConnectionInstance { get; internal set; }

/// <summary>
/// When set to true and oAuth Mode ( not Cert ) attempts to run the login using the current user identity.
/// When set to true and oAuth Mode ( not Cert ) attempts to run the login using the current user identity.
/// </summary>
public bool UseCurrentUser { get; set; }

public DataverseConnectionStringProcessor()
{
}

private DataverseConnectionStringProcessor(IDictionary<string, string> connection)
private DataverseConnectionStringProcessor(IDictionary<string, string> connection , ILogger logger)
: this(
connection.FirstNotNullOrEmpty(ConnectionStringConstants.ServiceUri),
connection.FirstNotNullOrEmpty(ConnectionStringConstants.UserName),
Expand All @@ -218,12 +219,13 @@ private DataverseConnectionStringProcessor(IDictionary<string, string> connectio
connection.FirstNotNullOrEmpty(ConnectionStringConstants.CertThumbprint),
connection.FirstNotNullOrEmpty(ConnectionStringConstants.SkipDiscovery),
connection.FirstNotNullOrEmpty(ConnectionStringConstants.IntegratedSecurity),
connection.FirstNotNullOrEmpty(ConnectionStringConstants.ClientSecret)
connection.FirstNotNullOrEmpty(ConnectionStringConstants.ClientSecret),
logger
)
{
}
private DataverseConnectionStringProcessor(string serviceUri, string userName, string password, string domain, string homeRealmUri, string authType, string requireNewInstance, string clientId, string redirectUri,
string tokenCacheStorePath, string loginPrompt, string certStoreName, string certThumbprint, string skipDiscovery, string IntegratedSecurity , string clientSecret)
string tokenCacheStorePath, string loginPrompt, string certStoreName, string certThumbprint, string skipDiscovery, string IntegratedSecurity , string clientSecret , ILogger logger)
{
DataverseTraceLogger logEntry = new DataverseTraceLogger();
Uri _serviceuriName, _realmUri;
Expand All @@ -232,7 +234,7 @@ private DataverseConnectionStringProcessor(string serviceUri, string userName, s
if (bool.TryParse(skipDiscovery, out tempbool))
SkipDiscovery = tempbool;
else
SkipDiscovery = true; // changed to change defaulting behavior of skip discovery.
SkipDiscovery = true; // changed to change defaulting behavior of skip discovery.


ServiceUri = GetValidUri(serviceUri, out _serviceuriName) ? _serviceuriName : null;
Expand All @@ -247,16 +249,16 @@ private DataverseConnectionStringProcessor(string serviceUri, string userName, s
CertStoreName = certStoreName;
CertThumbprint = certThumbprint;

// Check to see if use current user is configured.
// Check to see if use current user is configured.
bool _IntegratedSecurity = false;
if (!string.IsNullOrEmpty(IntegratedSecurity))
bool.TryParse(IntegratedSecurity, out _IntegratedSecurity);

bool useUniqueConnection = true; // Set default to true to follow the old behavior.
bool useUniqueConnection = true; // Set default to true to follow the old behavior.
if (!string.IsNullOrEmpty(requireNewInstance))
bool.TryParse(requireNewInstance, out useUniqueConnection);
UseUniqueConnectionInstance = useUniqueConnection;

//UserIdentifier = !string.IsNullOrWhiteSpace(UserId) ? new UserIdentifier(UserId, UserIdentifierType.OptionalDisplayableId) : null;

AuthenticationType authenticationType;
Expand Down Expand Up @@ -322,7 +324,7 @@ private bool GetValidUri(string uriSource, out Uri validUriResult)
/// <param name="serviceUri"></param>
private void SetOrgnameAndOnlineRegion(Uri serviceUri)
{
// uses publicaly exposed connection parser to parse
// uses publicaly exposed connection parser to parse
string orgRegion = string.Empty;
string orgName = string.Empty;
bool isOnPrem = false;
Expand All @@ -334,13 +336,14 @@ private void SetOrgnameAndOnlineRegion(Uri serviceUri)


/// <summary>
/// Parse the connection sting
/// Parse the connection sting
/// </summary>
/// <param name="connectionString"></param>
/// <param name="logger">Logging provider <see cref="ILogger"/></param>
/// <returns></returns>
public static DataverseConnectionStringProcessor Parse(string connectionString )
public static DataverseConnectionStringProcessor Parse(string connectionString , ILogger logger = null)
{
return new DataverseConnectionStringProcessor(connectionString.ToDictionary());
return new DataverseConnectionStringProcessor(connectionString.ToDictionary(), logger);
}

}
Expand Down
Loading