Microsoft.Identity.Client.Internal.ClientMetrics.EndClientMetricsRecord C# (CSharp) Method

EndClientMetricsRecord() public method

public EndClientMetricsRecord ( string endpoint, CallState callState ) : void
endpoint string
callState CallState
return void
        public void EndClientMetricsRecord(string endpoint, CallState callState)
        {
            if (callState != null && metricsTimer != null)
            {
                metricsTimer.Stop();
                lastResponseTime = metricsTimer.ElapsedMilliseconds;
                lastCorrelationId = callState.CorrelationId;
                lastEndpoint = endpoint;
                lock (PendingClientMetricsLock)
                {
                    if (pendingClientMetrics == null)
                    {
                        pendingClientMetrics = this;
                    }
                }
            }
        }

Usage Example

        public async Task <T> GetResponseAsync <T>(string endpointType)
        {
            T             typedResponse = default(T);
            ClientMetrics clientMetrics = new ClientMetrics();

            try
            {
                clientMetrics.BeginClientMetricsRecord(this.CallState);

                Dictionary <string, string> clientMetricsHeaders = clientMetrics.GetPreviousRequestRecord(this.CallState);
                foreach (KeyValuePair <string, string> kvp in clientMetricsHeaders)
                {
                    this.Client.Headers[kvp.Key] = kvp.Value;
                }

                IDictionary <string, string> adalIdHeaders = MsalIdHelper.GetMsalIdParameters();
                foreach (KeyValuePair <string, string> kvp in adalIdHeaders)
                {
                    this.Client.Headers[kvp.Key] = kvp.Value;
                }

                IHttpWebResponse response;
                using (response = await this.Client.GetResponseAsync().ConfigureAwait(false))
                {
                    typedResponse = DeserializeResponse <T>(response.ResponseStream);
                    clientMetrics.SetLastError(null);
                }
            }
            catch (HttpRequestWrapperException ex)
            {
                PlatformPlugin.Logger.Error(this.CallState, ex);
                MsalServiceException serviceEx;
                if (ex.WebResponse != null)
                {
                    TokenResponse tokenResponse = TokenResponse.CreateFromErrorResponse(ex.WebResponse);
                    string[]      errorCodes    = tokenResponse.ErrorCodes ?? new[] { ex.WebResponse.StatusCode.ToString() };
                    serviceEx = new MsalServiceException(tokenResponse.Error, tokenResponse.ErrorDescription,
                                                         errorCodes, ex);
                }
                else
                {
                    serviceEx = new MsalServiceException(MsalError.Unknown, ex);
                }

                clientMetrics.SetLastError(serviceEx.ServiceErrorCodes);
                PlatformPlugin.Logger.Error(CallState, serviceEx);
                throw serviceEx;
            }
            finally
            {
                clientMetrics.EndClientMetricsRecord(endpointType, this.CallState);
            }

            return(typedResponse);
        }