Skip to content
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
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.202",
"version": "6.0.406",
"rollForward": "latestFeature",
"allowPrerelease": false
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build.Common.core.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(ProjectSpecificFx)' == ''">
<TargetFrameworks>net462;net472;net48;netcoreapp3.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net462;net472;net48;netcoreapp3.1;netstandard2.0;net6.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/Build.Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<PackageVersion_Adal>3.19.8</PackageVersion_Adal>
<PackageVersion_MSAL>4.35.1</PackageVersion_MSAL>
<PackageVersion_CdsSdk>4.7.11043-v9.0-weekly-2209.2</PackageVersion_CdsSdk>
<PackageVersion_CrmProxy>4.7.11043-v9.0-weekly-2209.2</PackageVersion_CrmProxy>
<PackageVersion_CdsSdk>4.9.665-v9.0-master</PackageVersion_CdsSdk>
<PackageVersion_CrmProxy>4.9.665-v9.0-master</PackageVersion_CrmProxy>
<PackageVersion_CDSServerNuget>4.6.6061-weekly-2108.5</PackageVersion_CDSServerNuget>
<PackageVersion_Newtonsoft>13.0.1</PackageVersion_Newtonsoft>
<PackageVersion_RestClientRuntime>2.3.20</PackageVersion_RestClientRuntime>
Expand All @@ -21,10 +21,10 @@
<PackageVersion_Microsoft_Extensions>3.1.8</PackageVersion_Microsoft_Extensions>

<!-- Test: -->
<PackageVersion_MicrosoftNETTestSdk>17.2.0</PackageVersion_MicrosoftNETTestSdk>
<PackageVersion_MicrosoftNETTestSdk>17.5.0</PackageVersion_MicrosoftNETTestSdk>
<PackageVersion_MSTest>2.2.10</PackageVersion_MSTest>
<PackageVersion_Moq>4.16.0</PackageVersion_Moq>
<PackageVersion_XUnit>2.4.1</PackageVersion_XUnit>
<PackageVersion_XUnit>2.4.2</PackageVersion_XUnit>
<PackageVersion_XUnitRunnerVS>2.4.5</PackageVersion_XUnitRunnerVS>
<PackageVersion_FluentAssertions>5.10.3</PackageVersion_FluentAssertions>

Expand Down
297 changes: 220 additions & 77 deletions src/GeneralTools/DataverseClient/Client/ConnectionService.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public void EnableProxyTypes(Assembly assembly)
/// For Sdk clients called via the OrganizationServiceProxy this is the version of the local Microsoft.Xrm.Sdk dll used by the Client App.
/// </summary>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2143:TransparentMethodsShouldNotDemandFxCopRule")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2141:TransparentMethodsMustNotSatisfyLinkDemandsFxCopRule")]
[PermissionSet(SecurityAction.Demand, Unrestricted = true)]
internal static string GetXrmSdkAssemblyFileVersion()
{
if (string.IsNullOrEmpty(_xrmSdkAssemblyFileVersion))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises
{
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
[SecuritySafeCritical]
internal sealed partial class ServiceConfiguration<TService>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Microsoft.PowerPlatform.Dataverse.Client.Connector
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading.Tasks;
using Microsoft.PowerPlatform.Dataverse.Client;
Expand Down Expand Up @@ -62,7 +63,8 @@ public void Associate(string entityName, Guid entityId, Relationship relationshi
public Task AssociateAsync(string entityName, Guid entityId, Relationship relationship,
EntityReferenceCollection relatedEntities)
{
return AssociateAsyncCore(entityName, entityId, relationship, relatedEntities);
AssociateAsyncCore(entityName, entityId, relationship, relatedEntities);
return Task.CompletedTask;
}

public Guid Create(Entity entity)
Expand All @@ -73,6 +75,7 @@ public Guid Create(Entity entity)
public Task<Guid> CreateAsync(Entity entity)
{
return CreateAsyncCore(entity);

}

public void Delete(string entityName, Guid id)
Expand All @@ -82,7 +85,8 @@ public void Delete(string entityName, Guid id)

public Task DeleteAsync(string entityName, Guid id)
{
return DeleteAsyncCore(entityName, id);
DeleteAsyncCore(entityName, id);
return Task.CompletedTask;
}

public void Disassociate(string entityName, Guid entityId, Relationship relationship,
Expand All @@ -94,7 +98,8 @@ public void Disassociate(string entityName, Guid entityId, Relationship relation
public Task DisassociateAsync(string entityName, Guid entityId, Relationship relationship,
EntityReferenceCollection relatedEntities)
{
return DisassociateAsyncCore(entityName, entityId, relationship, relatedEntities);
DisassociateAsyncCore(entityName, entityId, relationship, relatedEntities);
return Task.CompletedTask;
}

public OrganizationResponse Execute(OrganizationRequest request)
Expand Down Expand Up @@ -134,7 +139,8 @@ public void Update(Entity entity)

public Task UpdateAsync(Entity entity)
{
return UpdateAsyncCore(entity);
UpdateAsyncCore(entity);
return Task.CompletedTask;
}

#endregion
Expand All @@ -148,7 +154,7 @@ protected internal virtual Guid CreateCore(Entity entity)

protected Task<Guid> CreateAsyncCore(Entity entity)
{
return ExecuteAction(() => Channel.CreateAsync(entity));
return ExecuteOperation(() => Channel.CreateAsync(entity));
}

protected internal virtual Entity RetrieveCore(string entityName, Guid id, ColumnSet columnSet)
Expand All @@ -158,7 +164,7 @@ protected internal virtual Entity RetrieveCore(string entityName, Guid id, Colum

protected internal virtual Task<Entity> RetrieveAsyncCore(string entityName, Guid id, ColumnSet columnSet)
{
return ExecuteAction(() => Channel.RetrieveAsync(entityName, id, columnSet));
return ExecuteOperation(() => Channel.RetrieveAsync(entityName, id, columnSet));
}

protected internal virtual void UpdateCore(Entity entity)
Expand All @@ -168,7 +174,7 @@ protected internal virtual void UpdateCore(Entity entity)

protected internal virtual Task UpdateAsyncCore(Entity entity)
{
return ExecuteAction(() => Channel.UpdateAsync(entity));
return ExecuteOperation(() => {Channel.UpdateAsync(entity); return (Task<Task>)Task.CompletedTask;});
}

protected internal virtual void DeleteCore(string entityName, Guid id)
Expand All @@ -178,7 +184,7 @@ protected internal virtual void DeleteCore(string entityName, Guid id)

protected internal virtual Task DeleteAsyncCore(string entityName, Guid id)
{
return ExecuteAction(() => Channel.DeleteAsync(entityName, id));
return ExecuteOperation(() => { Channel.DeleteAsync(entityName, id); return (Task<Task>)Task.CompletedTask; });
}

protected internal virtual OrganizationResponse ExecuteCore(OrganizationRequest request)
Expand All @@ -188,7 +194,7 @@ protected internal virtual OrganizationResponse ExecuteCore(OrganizationRequest

protected internal virtual Task<OrganizationResponse> ExecuteAsyncCore(OrganizationRequest request)
{
return ExecuteAction(() => Channel.ExecuteAsync(request));
return ExecuteOperation(() => Channel.ExecuteAsync(request));
}

protected internal virtual void AssociateCore(string entityName, Guid entityId, Relationship relationship,
Expand All @@ -200,7 +206,7 @@ protected internal virtual void AssociateCore(string entityName, Guid entityId,
protected internal virtual Task AssociateAsyncCore(string entityName, Guid entityId, Relationship relationship,
EntityReferenceCollection relatedEntities)
{
return ExecuteAction(() => Channel.AssociateAsync(entityName, entityId, relationship, relatedEntities));
return ExecuteOperation(() => { Channel.AssociateAsync(entityName, entityId, relationship, relatedEntities); return (Task<Task>)Task.CompletedTask; });
}

protected internal virtual void DisassociateCore(string entityName, Guid entityId, Relationship relationship,
Expand All @@ -212,7 +218,7 @@ protected internal virtual void DisassociateCore(string entityName, Guid entityI
protected internal virtual Task DisassociateAsyncCore(string entityName, Guid entityId, Relationship relationship,
EntityReferenceCollection relatedEntities)
{
return ExecuteAction(() => Channel.DisassociateAsync(entityName, entityId, relationship, relatedEntities));
return ExecuteOperation(() => { Channel.DisassociateAsync(entityName, entityId, relationship, relatedEntities); return (Task<Task>)Task.CompletedTask; });
}

protected internal virtual EntityCollection RetrieveMultipleCore(QueryBase query)
Expand All @@ -222,7 +228,7 @@ protected internal virtual EntityCollection RetrieveMultipleCore(QueryBase query

protected internal virtual Task<EntityCollection> RetrieveMultipleAsyncCore(QueryBase query)
{
return ExecuteAction(() => Channel.RetrieveMultipleAsync(query));
return ExecuteOperation(() => Channel.RetrieveMultipleAsync(query));
}

#endregion Protected Members
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Permissions;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk.Client;

namespace Microsoft.PowerPlatform.Dataverse.Client.Connector
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.CodeQuality.Analyzers", "CA1063: Implement IDisposable correctly", Justification = "FxCop Bankruptcy")]
internal abstract class WebProxyClientAsync<TService> : ClientBase<TService>, IDisposable
where TService : class
{
Expand Down Expand Up @@ -83,6 +82,33 @@ internal TResult ExecuteAction<TResult>(Func<TResult> action)
}
}

#if NETCOREAPP
protected async internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
{
if (asyncAction == null)
{
throw new ArgumentNullException(nameof(asyncAction));
}

using (CreateNewInitializer())
{
return await asyncAction().ConfigureAwait(continueOnCapturedContext: true);
}
}
#else
protected internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
{
if (asyncAction == null)
{
throw new ArgumentNullException(nameof(asyncAction));
}

using (CreateNewInitializer())
{
return asyncAction();
}
}
#endif
protected static ServiceEndpoint CreateServiceEndpoint(Uri serviceUrl, bool useStrongTypes, TimeSpan timeout,
Assembly strongTypeAssembly)
{
Expand Down Expand Up @@ -162,9 +188,6 @@ protected static Binding GetBinding(Uri serviceUrl, TimeSpan timeout)
/// by the Client App.
/// </summary>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2143:TransparentMethodsShouldNotDemandFxCopRule")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2141:TransparentMethodsMustNotSatisfyLinkDemandsFxCopRule")]
[PermissionSet(SecurityAction.Demand, Unrestricted = true)]
internal string GetXrmSdkAssemblyFileVersion()
{
if (string.IsNullOrEmpty(_xrmSdkAssemblyFileVersion))
Expand All @@ -181,27 +204,27 @@ internal string GetXrmSdkAssemblyFileVersion()
return _xrmSdkAssemblyFileVersion;
}

#region IDisposable implementation
#region IDisposable implementation

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

#region Protected Methods
#region Protected Methods

protected virtual void Dispose(bool disposing)
{
}

#endregion
#endregion

~WebProxyClientAsync()
{
Dispose(false);
}

#endregion
#endregion
}
}
35 changes: 29 additions & 6 deletions src/GeneralTools/DataverseClient/Client/DataverseTraceLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ public override void Log(string message, TraceEventType eventType, Exception exc
// check and or alter the exception is its and HTTPOperationExecption.
if (exception is HttpOperationException httpOperationException)
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
Utils.DataverseOperationException webApiExcept = new Utils.DataverseOperationException(string.IsNullOrEmpty(contentBody["error"]["message"]?.ToString()) ? "Not Provided" : GetFirstLineFromString(contentBody["error"]["message"]?.ToString()).Trim(), httpOperationException);
string errorMessage = "Not Provided";
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
errorMessage = string.IsNullOrEmpty(contentBody["error"]["message"]?.ToString()) ? "Not Provided" : GetFirstLineFromString(contentBody["error"]["message"]?.ToString()).Trim();
}

Utils.DataverseOperationException webApiExcept = new Utils.DataverseOperationException(errorMessage, httpOperationException);
LastException = webApiExcept;
}
else
Expand Down Expand Up @@ -249,9 +255,19 @@ public void LogException(OrganizationRequest req, Exception ex, string errorStri
}
else if (ex is HttpOperationException httpOperationException)
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
string errorMessage;
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
errorMessage = DataverseTraceLogger.GetFirstLineFromString(contentBody["error"]["message"].ToString()).Trim();
}
else
{
errorMessage = httpOperationException.Response.StatusCode.ToString();
}

DataverseOperationException ex01 = DataverseOperationException.GenerateClientOperationException(httpOperationException);
Log(string.Format(CultureInfo.InvariantCulture, "************ {3} - {2} : {0} |=> {1}", errorStringCheck, DataverseTraceLogger.GetFirstLineFromString(contentBody["error"]["message"].ToString()).Trim(), webUriMessageReq, ex.GetType().Name), TraceEventType.Error, ex01);
Log(string.Format(CultureInfo.InvariantCulture, "************ {3} - {2} : {0} |=> {1}", errorStringCheck, errorMessage, webUriMessageReq, ex.GetType().Name), TraceEventType.Error, ex01);
}
else
{
Expand Down Expand Up @@ -294,8 +310,15 @@ public void LogFailure(OrganizationRequest req, Guid requestTrackingId, Guid? se
DataverseOperationException ex01 = DataverseOperationException.GenerateClientOperationException(httpOperationException);
try
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
errorMessage = DataverseTraceLogger.GetFirstLineFromString(contentBody["error"]["message"].ToString()).Trim();
if (!string.IsNullOrWhiteSpace(httpOperationException.Response.Content))
{
JObject contentBody = JObject.Parse(httpOperationException.Response.Content);
errorMessage = DataverseTraceLogger.GetFirstLineFromString(contentBody["error"]["message"].ToString()).Trim();
}
else
{
errorMessage = httpOperationException.Response.StatusCode.ToString();
}
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Microsoft.PowerPlatform.Dataverse.Client</RootNamespace>
Expand All @@ -11,6 +11,7 @@
<PropertyGroup>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<DocumentationFile>$(OutDir)\Microsoft.PowerPlatform.Dataverse.Client.xml</DocumentationFile>
<AnalysisLevel>6.0</AnalysisLevel>
</PropertyGroup>


Expand Down Expand Up @@ -38,12 +39,12 @@
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
<PackageReference Include="System.Security.Permissions" Version="5.0.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
<PackageReference Include="System.ServiceModel.Http" Version="4.10.0" />
<PackageReference Include="System.Text.Json" Version="6.0.7" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.18.9" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(PackageVersion_Microsoft_Extensions)" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" /> <!-- explict add to deal with CVE-2021-24112 -->
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.7.1" /> <!-- explict add to deal with CVE-2022-34716 -->
<PackageReference Include="System.Security.Cryptography.Xml" Version="6.0.1" /> <!-- explict add to deal with CVE-2022-34716 -->
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net472' or '$(TargetFramework)' == 'net48'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool UseWebApi
set => _useWebApi = value;
}

private bool _useWebApiLoginFlow = Utils.AppSettingsHelper.GetAppSetting<bool>("UseWebApiLoginFlow", false);
private bool _useWebApiLoginFlow = Utils.AppSettingsHelper.GetAppSetting<bool>("UseWebApiLoginFlow", true);
/// <summary>
/// Use Web API instead of org service for logging into and getting boot up data.
/// </summary>
Expand Down
Loading