Skip to content

Commit 3af97c1

Browse files
authored
Merge pull request #444 from microsoft/release/update/240416093314
20240416 Resync from Main
2 parents 33b6089 + e051e02 commit 3af97c1

19 files changed

+827
-99
lines changed

src/GeneralTools/DataverseClient/Client/Builder/AbstractClientRequestBuilder.cs

Lines changed: 482 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Ignore Spelling: Dataverse
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Microsoft.PowerPlatform.Dataverse.Client.Builder
10+
{
11+
/// <summary>
12+
/// Request builder class for submitting requests to Dataverse.
13+
/// </summary>
14+
public class ServiceClientRequestBuilder : AbstractClientRequestBuilder<ServiceClientRequestBuilder>
15+
{
16+
internal ServiceClientRequestBuilder(IOrganizationServiceAsync2 client)
17+
: base(client)
18+
{ }
19+
}
20+
}

src/GeneralTools/DataverseClient/Client/ConnectionService.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ internal IEnumerable<Tuple<DateTime, string>> GetAllLogs()
380380
/// <summary>
381381
/// if set to true, the log provider is set locally
382382
/// </summary>
383-
public bool isLogEntryCreatedLocaly { get; set; }
383+
public bool isLogEntryCreatedLocally { get; set; }
384384

385385
/// <summary>
386386
/// Get and Set of network credentials...
@@ -687,7 +687,7 @@ internal ConnectionService(IOrganizationService testIOrganziationSvc, string bas
687687
_testSupportIOrg = testIOrganziationSvc;
688688
WebApiHttpClient = mockClient;
689689
logEntry = new DataverseTraceLogger(logger);
690-
isLogEntryCreatedLocaly = true;
690+
isLogEntryCreatedLocally = true;
691691

692692
_OrgDetail = new OrganizationDetail();
693693
_OrgDetail.Endpoints.Add(EndpointType.OrganizationDataService, baseConnectUrl);
@@ -708,12 +708,12 @@ internal ConnectionService(OrganizationWebProxyClientAsync externalOrgWebProxyCl
708708
if (logSink == null)
709709
{
710710
logEntry = new DataverseTraceLogger();
711-
isLogEntryCreatedLocaly = true;
711+
isLogEntryCreatedLocally = true;
712712
}
713713
else
714714
{
715715
logEntry = logSink;
716-
isLogEntryCreatedLocaly = false;
716+
isLogEntryCreatedLocally = false;
717717
}
718718

719719
// is this a clone request
@@ -765,12 +765,12 @@ internal ConnectionService(
765765
if (logSink == null)
766766
{
767767
logEntry = new DataverseTraceLogger();
768-
isLogEntryCreatedLocaly = true;
768+
isLogEntryCreatedLocally = true;
769769
}
770770
else
771771
{
772772
logEntry = logSink;
773-
isLogEntryCreatedLocaly = false;
773+
isLogEntryCreatedLocally = false;
774774
}
775775

776776
// is this a clone request
@@ -838,12 +838,12 @@ internal ConnectionService(
838838
if (logSink == null)
839839
{
840840
logEntry = new DataverseTraceLogger();
841-
isLogEntryCreatedLocaly = true;
841+
isLogEntryCreatedLocally = true;
842842
}
843843
else
844844
{
845845
logEntry = logSink;
846-
isLogEntryCreatedLocaly = false;
846+
isLogEntryCreatedLocally = false;
847847
}
848848

849849
// is this a clone request
@@ -908,12 +908,12 @@ internal ConnectionService(
908908
if (logSink == null)
909909
{
910910
logEntry = new DataverseTraceLogger();
911-
isLogEntryCreatedLocaly = true;
911+
isLogEntryCreatedLocally = true;
912912
}
913913
else
914914
{
915915
logEntry = logSink;
916-
isLogEntryCreatedLocaly = false;
916+
isLogEntryCreatedLocally = false;
917917
}
918918

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

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

3013+
if (!Utilities.IsValidOrganizationUrl(d))
3014+
{
3015+
logSink.Log(string.Format(CultureInfo.InvariantCulture, "QueryGlobalDiscovery - Invalid Url returned from Discovery ({0})", d.Endpoints[EndpointType.OrganizationService]));
3016+
continue;
3017+
}
30113018
orgList.Add(d);
30123019
}
30133020
dtStartQuery.Stop();
@@ -3762,7 +3769,7 @@ void Dispose(bool disposing)
37623769
if (disposing)
37633770
{
37643771
disposedValue = true;
3765-
if (isLogEntryCreatedLocaly)
3772+
if (isLogEntryCreatedLocally)
37663773
{
37673774
logEntry?.Dispose();
37683775
}

src/GeneralTools/DataverseClient/Client/Connector/OrganizationWebProxyClientAsync.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ namespace Microsoft.PowerPlatform.Dataverse.Client.Connector
55
using System.Net;
66
using System.Reflection;
77
using System.ServiceModel;
8+
using System.ServiceModel.Channels;
89
using System.ServiceModel.Description;
910
using System.Threading.Tasks;
1011
using Microsoft.PowerPlatform.Dataverse.Client;
12+
using Microsoft.PowerPlatform.Dataverse.Client.Utils;
1113
using Microsoft.Xrm.Sdk;
1214
using Microsoft.Xrm.Sdk.Client;
15+
using Microsoft.Xrm.Sdk.Messages;
1316
using Microsoft.Xrm.Sdk.Query;
1417

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

190193
protected internal virtual OrganizationResponse ExecuteCore(OrganizationRequest request)
191194
{
192-
return ExecuteAction(() => Channel.Execute(request));
195+
return ExecuteAction(() =>
196+
{
197+
ProcessRequestBinderProperties(request);
198+
return Channel.Execute(request);
199+
});
193200
}
194201

195202
protected internal virtual Task<OrganizationResponse> ExecuteAsyncCore(OrganizationRequest request)
196203
{
197-
return ExecuteOperation(() => Channel.ExecuteAsync(request));
204+
return ExecuteOperation(() =>
205+
{
206+
ProcessRequestBinderProperties(request);
207+
return Channel.ExecuteAsync(request);
208+
});
198209
}
199210

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

243254
#endregion
255+
256+
private void ProcessRequestBinderProperties(OrganizationRequest request)
257+
{
258+
if (OperationContext.Current != null)
259+
{
260+
HttpRequestMessageProperty messageProp = (HttpRequestMessageProperty)OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name];
261+
RequestBinderUtil.ProcessRequestBinderProperties(messageProp, request);
262+
}
263+
}
244264
}
245265
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
246266

src/GeneralTools/DataverseClient/Client/Connector/WebProxyClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal TResult ExecuteAction<TResult>(Func<TResult> action)
8383
}
8484

8585
#if NETCOREAPP
86-
protected async internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
86+
protected internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
8787
{
8888
if (asyncAction == null)
8989
{
@@ -92,7 +92,7 @@ protected async internal Task<T> ExecuteOperation<T>(Func<Task<T>> asyncAction)
9292

9393
using (CreateNewInitializer())
9494
{
95-
return await asyncAction().ConfigureAwait(continueOnCapturedContext: true);
95+
return asyncAction();
9696
}
9797
}
9898
#else

src/GeneralTools/DataverseClient/Client/InternalExtensions/RequestResponseExtenstions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Microsoft.PowerPlatform.Dataverse.Client.InternalExtensions
1212
{
1313
/// <summary>
14-
/// Organization request/response extenstions
14+
/// Organization request/response extensions
1515
/// </summary>
1616
internal static class RequestResponseExtenstions
1717
{

src/GeneralTools/DataverseClient/Client/Microsoft.PowerPlatform.Dataverse.Client.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@
3535
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="$(PackageVersion_RestClientRuntime)" />
3636
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
3737
<PackageReference Include="Newtonsoft.Json" Version="$(PackageVersion_Newtonsoft)" />
38-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
39-
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
38+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(PackageVersion_SystemConfigurationConfigurationManager)" />
39+
<!--<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
4040
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
41-
<PackageReference Include="System.Security.Permissions" Version="5.0.0" />
42-
<PackageReference Include="System.ServiceModel.Http" Version="4.10.2" />
41+
<PackageReference Include="System.Security.Permissions" Version="$(PackageVersion_SystemSecurityPermissions)" /> -->
4342
<PackageReference Include="System.Text.Json" Version="$(PackageVersion_SystemTextJson)" />
44-
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.56.0" />
43+
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="$(PackageVersion_MSAL)" />
4544
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(PackageVersion_Microsoft_Extensions)" />
46-
<PackageReference Include="System.Drawing.Common" Version="5.0.3" /> <!-- explict add to deal with CVE-2021-24112 -->
45+
<!--<PackageReference Include="System.Drawing.Common" Version="5.0.3" />--> <!-- explict add to deal with CVE-2021-24112 -->
4746
</ItemGroup>
4847

4948
<ItemGroup Condition="'$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'net472' or '$(TargetFramework)' == 'net48'">

src/GeneralTools/DataverseClient/Client/ServiceClient.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1+
// Ignore Spelling: Dataverse
2+
13
#region using
24
using System;
35
using System.Collections.Generic;
4-
using System.Collections.ObjectModel;
56
using System.Diagnostics;
6-
using System.Diagnostics.CodeAnalysis;
77
using System.Globalization;
8-
using System.IO;
98
using System.Linq;
109
using System.Security;
1110
using System.ServiceModel;
1211
using System.ServiceModel.Description;
13-
using System.Xml;
1412
using Microsoft.Crm.Sdk.Messages;
1513
using Microsoft.Xrm.Sdk;
1614
using Microsoft.Xrm.Sdk.Discovery;
1715
using Microsoft.Xrm.Sdk.Messages;
18-
using Microsoft.Xrm.Sdk.Metadata;
1916
using Microsoft.Xrm.Sdk.Query;
20-
using Microsoft.Xrm.Sdk.WebServiceClient;
2117
using System.Security.Cryptography.X509Certificates;
2218
using System.Threading.Tasks;
2319
using System.Net.Http;
@@ -28,10 +24,9 @@
2824
using Microsoft.Extensions.Logging;
2925
using Microsoft.Extensions.Options;
3026
using Microsoft.PowerPlatform.Dataverse.Client.Model;
31-
using System.Reflection;
32-
using Microsoft.Extensions.Caching.Memory;
3327
using Microsoft.PowerPlatform.Dataverse.Client.Connector;
3428
using Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises;
29+
using Microsoft.PowerPlatform.Dataverse.Client.Builder;
3530
#endregion
3631

3732
namespace Microsoft.PowerPlatform.Dataverse.Client
@@ -1444,6 +1439,15 @@ public ServiceClient Clone(System.Reflection.Assembly strongTypeAsm, ILogger log
14441439
}
14451440
}
14461441

1442+
/// <summary>
1443+
/// 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.
1444+
/// </summary>
1445+
/// <returns>Service Request builder that is used to create and submit a single request.</returns>
1446+
public ServiceClientRequestBuilder CreateRequestBuilder()
1447+
{
1448+
return new ServiceClientRequestBuilder(this);
1449+
}
1450+
14471451
#region Dataverse DiscoveryServerMethods
14481452

14491453
/// <summary>

0 commit comments

Comments
 (0)