Skip to content

Commit

Permalink
''
Browse files Browse the repository at this point in the history
  • Loading branch information
Release-Agent committed Apr 16, 2024
1 parent 33b6089 commit e051e02
Show file tree
Hide file tree
Showing 19 changed files with 827 additions and 99 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Ignore Spelling: Dataverse

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.PowerPlatform.Dataverse.Client.Builder
{
/// <summary>
/// Request builder class for submitting requests to Dataverse.
/// </summary>
public class ServiceClientRequestBuilder : AbstractClientRequestBuilder<ServiceClientRequestBuilder>
{
internal ServiceClientRequestBuilder(IOrganizationServiceAsync2 client)
: base(client)
{ }
}
}
29 changes: 18 additions & 11 deletions src/GeneralTools/DataverseClient/Client/ConnectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ internal IEnumerable<Tuple<DateTime, string>> GetAllLogs()
/// <summary>
/// if set to true, the log provider is set locally
/// </summary>
public bool isLogEntryCreatedLocaly { get; set; }
public bool isLogEntryCreatedLocally { get; set; }

/// <summary>
/// Get and Set of network credentials...
Expand Down Expand Up @@ -687,7 +687,7 @@ internal ConnectionService(IOrganizationService testIOrganziationSvc, string bas
_testSupportIOrg = testIOrganziationSvc;
WebApiHttpClient = mockClient;
logEntry = new DataverseTraceLogger(logger);
isLogEntryCreatedLocaly = true;
isLogEntryCreatedLocally = true;

_OrgDetail = new OrganizationDetail();
_OrgDetail.Endpoints.Add(EndpointType.OrganizationDataService, baseConnectUrl);
Expand All @@ -708,12 +708,12 @@ internal ConnectionService(OrganizationWebProxyClientAsync externalOrgWebProxyCl
if (logSink == null)
{
logEntry = new DataverseTraceLogger();
isLogEntryCreatedLocaly = true;
isLogEntryCreatedLocally = true;
}
else
{
logEntry = logSink;
isLogEntryCreatedLocaly = false;
isLogEntryCreatedLocally = false;
}

// is this a clone request
Expand Down Expand Up @@ -765,12 +765,12 @@ internal ConnectionService(
if (logSink == null)
{
logEntry = new DataverseTraceLogger();
isLogEntryCreatedLocaly = true;
isLogEntryCreatedLocally = true;
}
else
{
logEntry = logSink;
isLogEntryCreatedLocaly = false;
isLogEntryCreatedLocally = false;
}

// is this a clone request
Expand Down Expand Up @@ -838,12 +838,12 @@ internal ConnectionService(
if (logSink == null)
{
logEntry = new DataverseTraceLogger();
isLogEntryCreatedLocaly = true;
isLogEntryCreatedLocally = true;
}
else
{
logEntry = logSink;
isLogEntryCreatedLocaly = false;
isLogEntryCreatedLocally = false;
}

// is this a clone request
Expand Down Expand Up @@ -908,12 +908,12 @@ internal ConnectionService(
if (logSink == null)
{
logEntry = new DataverseTraceLogger();
isLogEntryCreatedLocaly = true;
isLogEntryCreatedLocally = true;
}
else
{
logEntry = logSink;
isLogEntryCreatedLocaly = false;
isLogEntryCreatedLocally = false;
}

// is this a clone request
Expand Down Expand Up @@ -2086,6 +2086,8 @@ internal async Task<OrganizationResponse> Command_WebAPIProcess_ExecuteAsync(Org
userProvidedRequestId = req.RequestId.Value;
}

RequestBinderUtil.GetAdditionalHeaders(headers, req);

// Execute request
var sResp = await Command_WebExecuteAsync(postUri, bodyOfRequest, methodToExecute, headers, "application/json", logMessageTag, callerId, disableConnectionLocking, maxRetryCount, retryPauseTime, uriOfInstance, cancellationToken: cancellationToken, requestTrackingId: userProvidedRequestId).ConfigureAwait(false);
if (sResp != null && sResp.IsSuccessStatusCode)
Expand Down Expand Up @@ -3008,6 +3010,11 @@ private static async Task<OrganizationDetailCollection> QueryGlobalDiscoveryAsyn
proInfo.SetValue(d, ep, null);
}

if (!Utilities.IsValidOrganizationUrl(d))
{
logSink.Log(string.Format(CultureInfo.InvariantCulture, "QueryGlobalDiscovery - Invalid Url returned from Discovery ({0})", d.Endpoints[EndpointType.OrganizationService]));
continue;
}
orgList.Add(d);
}
dtStartQuery.Stop();
Expand Down Expand Up @@ -3762,7 +3769,7 @@ void Dispose(bool disposing)
if (disposing)
{
disposedValue = true;
if (isLogEntryCreatedLocaly)
if (isLogEntryCreatedLocally)
{
logEntry?.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ namespace Microsoft.PowerPlatform.Dataverse.Client.Connector
using System.Net;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Threading.Tasks;
using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.PowerPlatform.Dataverse.Client.Utils;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
Expand Down Expand Up @@ -189,12 +192,20 @@ protected internal virtual Task DeleteAsyncCore(string entityName, Guid id)

protected internal virtual OrganizationResponse ExecuteCore(OrganizationRequest request)
{
return ExecuteAction(() => Channel.Execute(request));
return ExecuteAction(() =>
{
ProcessRequestBinderProperties(request);
return Channel.Execute(request);
});
}

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

protected internal virtual void AssociateCore(string entityName, Guid entityId, Relationship relationship,
Expand Down Expand Up @@ -241,6 +252,15 @@ protected override WebProxyClientContextAsyncInitializer<IOrganizationServiceAsy
}

#endregion

private void ProcessRequestBinderProperties(OrganizationRequest request)
{
if (OperationContext.Current != null)
{
HttpRequestMessageProperty messageProp = (HttpRequestMessageProperty)OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name];
RequestBinderUtil.ProcessRequestBinderProperties(messageProp, request);
}
}
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal TResult ExecuteAction<TResult>(Func<TResult> action)
}

#if NETCOREAPP
protected async internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
protected internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
{
if (asyncAction == null)
{
Expand All @@ -92,7 +92,7 @@ protected async internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)

using (CreateNewInitializer())
{
return await asyncAction().ConfigureAwait(continueOnCapturedContext: true);
return asyncAction();
}
}
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Microsoft.PowerPlatform.Dataverse.Client.InternalExtensions
{
/// <summary>
/// Organization request/response extenstions
/// Organization request/response extensions
/// </summary>
internal static class RequestResponseExtenstions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="$(PackageVersion_RestClientRuntime)" />
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="$(PackageVersion_Newtonsoft)" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(PackageVersion_SystemConfigurationConfigurationManager)" />
<!--<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.10.2" />
<PackageReference Include="System.Security.Permissions" Version="$(PackageVersion_SystemSecurityPermissions)" /> -->
<PackageReference Include="System.Text.Json" Version="$(PackageVersion_SystemTextJson)" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.56.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="$(PackageVersion_MSAL)" />
<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.Drawing.Common" Version="5.0.3" />--> <!-- explict add to deal with CVE-2021-24112 -->
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net472' or '$(TargetFramework)' == 'net48'">
Expand Down
20 changes: 12 additions & 8 deletions src/GeneralTools/DataverseClient/Client/ServiceClient.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// Ignore Spelling: Dataverse

#region using
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Xml;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.WebServiceClient;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using System.Net.Http;
Expand All @@ -28,10 +24,9 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.PowerPlatform.Dataverse.Client.Model;
using System.Reflection;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.PowerPlatform.Dataverse.Client.Connector;
using Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises;
using Microsoft.PowerPlatform.Dataverse.Client.Builder;
#endregion

namespace Microsoft.PowerPlatform.Dataverse.Client
Expand Down Expand Up @@ -1444,6 +1439,15 @@ public ServiceClient Clone(System.Reflection.Assembly strongTypeAsm, ILogger log
}
}

/// <summary>
/// Creates a ServiceClient Request builder that allows you to customize a specific request sent to dataverse. This should be used only for a single request and then released.
/// </summary>
/// <returns>Service Request builder that is used to create and submit a single request.</returns>
public ServiceClientRequestBuilder CreateRequestBuilder()
{
return new ServiceClientRequestBuilder(this);
}

#region Dataverse DiscoveryServerMethods

/// <summary>
Expand Down
Loading

0 comments on commit e051e02

Please sign in to comment.