@@ -117,7 +117,6 @@ internal sealed class ConnectionService : IConnectionService, IDisposable
117
117
private PromptBehavior _promptBehavior ; // prompt behavior
118
118
private string _tokenCachePath ; // user specified token cache file path
119
119
private bool _isOnPremOAuth = false ; // Identifies whether the connection is for OnPrem or Online Deployment for OAuth
120
- private static string _userId = null ; //cached userid reading from config file
121
120
private bool _isCalledbyExecuteRequest = false ; //Flag indicating that the an request called by Execute_Command
122
121
private bool _isDefaultCredsLoginForOAuth = false ; //Flag indicating that the user is trying to login with the current user id.
123
122
@@ -342,7 +341,7 @@ internal sealed class ConnectionService : IConnectionService, IDisposable
342
341
/// <summary>
343
342
/// Cached userid
344
343
/// </summary>
345
- internal string UserId { get { return _userId ; } }
344
+ internal string UserId { get { return _userAccount != null ? _userAccount . Username : string . Empty ; } }
346
345
347
346
/// <summary>
348
347
/// Flag indicating that the an request called by Execute_Command used for OAuth
@@ -957,7 +956,6 @@ private void GenerateCacheKeys(bool useUniqueCacheName)
957
956
{
958
957
//unqueInstance = true; // this instance is unique.
959
958
_authority = string . Empty ;
960
- _userId = null ;
961
959
Guid guID = Guid . NewGuid ( ) ;
962
960
_ServiceCACHEName = _ServiceCACHEName + guID . ToString ( ) ; // Creating a unique instance name for the cache object.
963
961
}
@@ -1064,7 +1062,7 @@ private async Task<IOrganizationService> InitServiceAsync()
1064
1062
{
1065
1063
// Dataverse Service Endpoint to work with
1066
1064
IOrganizationService dvService = null ;
1067
- Stopwatch dtQueryTimer = new Stopwatch ( ) ;
1065
+ Stopwatch dtQueryTimer = Stopwatch . StartNew ( ) ;
1068
1066
try
1069
1067
{
1070
1068
if ( ! IsAClone )
@@ -1406,21 +1404,6 @@ private async Task<IOrganizationService> InitServiceAsync()
1406
1404
return null ;
1407
1405
}
1408
1406
1409
- //// Do a WHO AM I request to make sure the connection is good.
1410
- //if (!UseExternalConnection)
1411
- //{
1412
- // Guid guIntialTrackingID = Guid.NewGuid();
1413
- // logEntry.Log(string.Format("Beginning Validation of Dataverse Connection. RequestID: {0}", guIntialTrackingID.ToString()));
1414
- // dtQueryTimer.Restart();
1415
- // user = await GetWhoAmIDetails(dvService, guIntialTrackingID).ConfigureAwait(false);
1416
- // dtQueryTimer.Stop();
1417
- // logEntry.Log(string.Format(CultureInfo.InvariantCulture, "Validation of Dataverse Connection Complete, total duration: {0}", dtQueryTimer.Elapsed.ToString()));
1418
- //}
1419
- //else
1420
- //{
1421
- // logEntry.Log("External Dataverse Connection Provided, Skipping Validation");
1422
- //}
1423
-
1424
1407
return ( IOrganizationService ) dvService ;
1425
1408
1426
1409
}
@@ -1483,8 +1466,7 @@ private async Task<IOrganizationService> InitServiceAsync()
1483
1466
private async Task < IOrganizationService > DoDirectLoginAsync ( bool IsOnPrem = false )
1484
1467
{
1485
1468
logEntry . Log ( "Direct Login Process Started" , TraceEventType . Verbose ) ;
1486
- Stopwatch sw = new Stopwatch ( ) ;
1487
- sw . Start ( ) ;
1469
+ Stopwatch sw = Stopwatch . StartNew ( ) ;
1488
1470
1489
1471
IOrganizationService dvService = null ;
1490
1472
Uri OrgWorkingURI = null ;
@@ -1600,8 +1582,7 @@ private async Task GetServerVersion(IOrganizationService dvService, Uri uriOfIns
1600
1582
{
1601
1583
Guid trackingID = Guid . NewGuid ( ) ;
1602
1584
logEntry . Log ( string . Format ( "Querying Organization Version. Request ID: {0}" , trackingID ) ) ;
1603
- Stopwatch dtQueryTimer = new Stopwatch ( ) ;
1604
- dtQueryTimer . Restart ( ) ;
1585
+ Stopwatch dtQueryTimer = Stopwatch . StartNew ( ) ;
1605
1586
1606
1587
RetrieveVersionResponse getVersionResp = null ;
1607
1588
var request = new RetrieveVersionRequest ( ) { RequestId = trackingID } ;
@@ -1680,8 +1661,7 @@ private async Task RefreshInstanceDetails(IOrganizationService dvService, Uri ur
1680
1661
//TODO:// Add Logic here to improve perf by connecting to global disco.
1681
1662
Guid trackingID = Guid . NewGuid ( ) ;
1682
1663
logEntry . Log ( string . Format ( "Querying Organization Instance Details. Request ID: {0}" , trackingID ) ) ;
1683
- Stopwatch dtQueryTimer = new Stopwatch ( ) ;
1684
- dtQueryTimer . Restart ( ) ;
1664
+ Stopwatch dtQueryTimer = Stopwatch . StartNew ( ) ;
1685
1665
1686
1666
var request = new RetrieveCurrentOrganizationRequest ( ) { AccessType = 0 , RequestId = trackingID } ;
1687
1667
RetrieveCurrentOrganizationResponse resp ;
@@ -1795,8 +1775,7 @@ internal async Task<WhoAmIResponse> GetWhoAmIDetails(IOrganizationService dvServ
1795
1775
{
1796
1776
if ( dvService != null )
1797
1777
{
1798
- Stopwatch dtQueryTimer = new Stopwatch ( ) ;
1799
- dtQueryTimer . Restart ( ) ;
1778
+ Stopwatch dtQueryTimer = Stopwatch . StartNew ( ) ;
1800
1779
try
1801
1780
{
1802
1781
if ( trackingID == Guid . Empty )
@@ -1894,6 +1873,8 @@ internal void SetClonedProperties(ServiceClient sourceClient)
1894
1873
debugingCloneStateFilter ++ ;
1895
1874
EnableCookieRelay = sourceClient . _connectionSvc . EnableCookieRelay ;
1896
1875
debugingCloneStateFilter ++ ;
1876
+ RequestAdditionalHeadersAsync = sourceClient . _connectionSvc . RequestAdditionalHeadersAsync ;
1877
+ debugingCloneStateFilter ++ ;
1897
1878
}
1898
1879
catch ( Exception ex )
1899
1880
{
@@ -2098,8 +2079,15 @@ internal async Task<OrganizationResponse> Command_WebAPIProcess_ExecuteAsync(Org
2098
2079
{
2099
2080
postUri = $ "{ postUri } ?{ addedQueryParams } ";
2100
2081
}
2082
+
2083
+ Guid userProvidedRequestId = Guid . Empty ;
2084
+ if ( req . RequestId . HasValue && req . RequestId != Guid . Empty )
2085
+ {
2086
+ userProvidedRequestId = req . RequestId . Value ;
2087
+ }
2088
+
2101
2089
// Execute request
2102
- var sResp = await Command_WebExecuteAsync ( postUri , bodyOfRequest , methodToExecute , headers , "application/json" , logMessageTag , callerId , disableConnectionLocking , maxRetryCount , retryPauseTime , uriOfInstance , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
2090
+ var sResp = await Command_WebExecuteAsync ( postUri , bodyOfRequest , methodToExecute , headers , "application/json" , logMessageTag , callerId , disableConnectionLocking , maxRetryCount , retryPauseTime , uriOfInstance , cancellationToken : cancellationToken , requestTrackingId : userProvidedRequestId ) . ConfigureAwait ( false ) ;
2103
2091
if ( sResp != null && sResp . IsSuccessStatusCode )
2104
2092
{
2105
2093
if ( req is CreateRequest )
@@ -2182,7 +2170,7 @@ internal async Task<OrganizationResponse> Command_WebAPIProcess_ExecuteAsync(Org
2182
2170
internal async Task < HttpResponseMessage > Command_WebExecuteAsync ( string queryString , string body , HttpMethod method , Dictionary < string , List < string > > customHeaders ,
2183
2171
string contentType , string errorStringCheck , Guid callerId , bool disableConnectionLocking , int maxRetryCount , TimeSpan retryPauseTime , Uri uriOfInstance = null , Guid requestTrackingId = default , CancellationToken cancellationToken = default )
2184
2172
{
2185
- Stopwatch logDt = new Stopwatch ( ) ;
2173
+ Stopwatch logDt = Stopwatch . StartNew ( ) ;
2186
2174
int retryCount = 0 ;
2187
2175
bool retry = false ;
2188
2176
@@ -2350,8 +2338,8 @@ internal async Task<HttpResponseMessage> Command_WebExecuteAsync(string queryStr
2350
2338
// Add authorization header. - Here to catch the situation where a token expires during retry.
2351
2339
if ( ! customHeaders . ContainsKey ( Utilities . RequestHeaders . AUTHORIZATION_HEADER ) )
2352
2340
customHeaders . Add ( Utilities . RequestHeaders . AUTHORIZATION_HEADER , new List < string > ( ) { string . Format ( "Bearer {0}" , await RefreshClientTokenAsync ( ) . ConfigureAwait ( false ) ) } ) ;
2353
-
2354
- logDt . Restart ( ) ; // start clock.
2341
+ logDt . Stop ( ) ;
2342
+ logDt = Stopwatch . StartNew ( ) ;
2355
2343
2356
2344
logEntry . Log ( string . Format ( CultureInfo . InvariantCulture , "Execute Command - {0}{1}: {2}" ,
2357
2345
$ "{ method } { queryString } ",
@@ -2534,7 +2522,7 @@ private bool ShouldRetryWebAPI(Exception ex, int retryCount, int maxRetryCount,
2534
2522
RequestId = requestTrackingId . Value ;
2535
2523
2536
2524
HttpResponseMessage _httpResponse = null ;
2537
- Stopwatch logDt = new Stopwatch ( ) ;
2525
+ Stopwatch logDt = Stopwatch . StartNew ( ) ;
2538
2526
try
2539
2527
{
2540
2528
using ( var _httpRequest = new HttpRequestMessage ( ) )
@@ -2596,7 +2584,8 @@ private bool ShouldRetryWebAPI(Exception ex, int retryCount, int maxRetryCount,
2596
2584
2597
2585
if ( providedHttpClient != null )
2598
2586
{
2599
- logDt . Restart ( ) ;
2587
+ logDt . Stop ( ) ;
2588
+ logDt = Stopwatch . StartNew ( ) ;
2600
2589
try
2601
2590
{
2602
2591
if ( providedHttpClient . Timeout != MaxConnectionTimeout )
@@ -2613,7 +2602,8 @@ private bool ShouldRetryWebAPI(Exception ex, int retryCount, int maxRetryCount,
2613
2602
// Fall though logic to deal with an Http client not being passed in.
2614
2603
using ( HttpClient httpCli = new HttpClient ( ) )
2615
2604
{
2616
- logDt . Restart ( ) ;
2605
+ logDt . Stop ( ) ;
2606
+ logDt = Stopwatch . StartNew ( ) ;
2617
2607
try
2618
2608
{
2619
2609
if ( httpCli . Timeout != MaxConnectionTimeout )
@@ -2805,7 +2795,7 @@ internal static async Task<OrganizationDetailCollection> DiscoverGlobalOrganizat
2805
2795
private static async Task < DiscoverOrganizationsResult > DiscoverOrganizations_InternalAsync ( Uri discoveryServiceUri , ClientCredentials clientCredentials , X509Certificate2 loginCertificate , string clientId , Uri redirectUri , PromptBehavior promptBehavior , bool isOnPrem , string authority , bool useDefaultCreds = false , string tokenCacheStorePath = null , DataverseTraceLogger logSink = null , CancellationToken cancellationToken = default )
2806
2796
{
2807
2797
bool createdLogSource = false ;
2808
- Stopwatch dtStartQuery = new Stopwatch ( ) ;
2798
+ Stopwatch dtStartQuery = Stopwatch . StartNew ( ) ;
2809
2799
try
2810
2800
{
2811
2801
if ( logSink == null )
@@ -2845,7 +2835,8 @@ private static async Task<DiscoverOrganizationsResult> DiscoverOrganizations_Int
2845
2835
2846
2836
try
2847
2837
{
2848
- dtStartQuery . Restart ( ) ;
2838
+ dtStartQuery . Stop ( ) ;
2839
+ dtStartQuery = Stopwatch . StartNew ( ) ;
2849
2840
RetrieveOrganizationsResponse orgResponse = ( RetrieveOrganizationsResponse ) svcDiscoveryProxy . Execute ( orgRequest ) ;
2850
2841
dtStartQuery . Stop ( ) ;
2851
2842
@@ -2973,8 +2964,7 @@ private static async Task<OrganizationDetailCollection> QueryGlobalDiscoveryAsyn
2973
2964
if ( discoveryServiceUri == null )
2974
2965
throw new ArgumentNullException ( nameof ( discoveryServiceUri ) , "Discovery service uri cannot be null." ) ;
2975
2966
2976
- Stopwatch dtStartQuery = new Stopwatch ( ) ;
2977
- dtStartQuery . Start ( ) ;
2967
+ Stopwatch dtStartQuery = Stopwatch . StartNew ( ) ;
2978
2968
// Initialize discovery service proxy.
2979
2969
logSink . Log ( "QueryGlobalDiscovery - Initializing Discovery Server Uri with " + discoveryServiceUri . ToString ( ) ) ;
2980
2970
@@ -3143,10 +3133,9 @@ private async Task<IOrganizationService> ConnectAndInitServiceAsync(Organization
3143
3133
3144
3134
// Set the Org into system config
3145
3135
_organization = orgdata . UniqueName ;
3146
- ConnectedOrganizationDetail = orgdata ;
3136
+ ConnectedOrganizationDetail = orgdata ;
3147
3137
3148
- var logDt = new Stopwatch ( ) ;
3149
- logDt . Start ( ) ;
3138
+ var logDt = Stopwatch . StartNew ( ) ;
3150
3139
// Build User Credential
3151
3140
logEntry . Log ( "ConnectAndInitService - Initializing Organization Service Object" , TraceEventType . Verbose ) ;
3152
3141
// this to provide trouble shooting information when determining org connect failures.
0 commit comments