Ejemplo n.º 1
0
        /// <summary>
        /// Gets the request identifier associated with this API call.
        /// </summary>
        /// <returns>The request ID.</returns>
        internal string GetRequestId()
        {
            Metadata            trailers    = this.getTrailers();
            AdsResponseMetadata respHeaders = new AdsResponseMetadata(trailers);

            return(respHeaders.RequestId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the call settings with configuration parameters.
        /// </summary>
        /// <param name="callSettings">The call settings.</param>
        /// <param name="config">The configuration.</param>
        /// <param name="serviceContext">The service context.</param>
        /// <returns></returns>
        private CallSettings UpdateCallSettingsWithConfigParameters(CallSettings callSettings,
                                                                    GoogleAdsConfig config, GoogleAdsServiceContext serviceContext)
        {
            callSettings = callSettings.WithHeader(MetadataKeyNames.DeveloperToken,
                                                   config.DeveloperToken)
                           .WithResponseMetadataHandler(delegate(Metadata metadata)
            {
                AdsResponseMetadata responseMetadata = new AdsResponseMetadata(metadata);
                serviceContext.OnResponseMetadataReceived(responseMetadata);
            });

            if (!string.IsNullOrEmpty(config.LoginCustomerId))
            {
                callSettings = callSettings.WithHeader(MetadataKeyNames.LoginCustomerId,
                                                       config.LoginCustomerId);
            }

            if (!string.IsNullOrEmpty(config.LinkedCustomerId))
            {
                callSettings = callSettings.WithHeader(MetadataKeyNames.LinkedCustomerId,
                                                       config.LinkedCustomerId);
            }

            if (!string.IsNullOrEmpty(config.LibraryIdentifierOverride))
            {
                callSettings = callSettings.WithHeader(MetadataKeyNames.LibraryIdentifier,
                                                       config.LibraryIdentifierOverride);
            }

            callSettings = callSettings.WithExpiration(Expiration.FromTimeout(
                                                           TimeSpan.FromMilliseconds(config.Timeout)));

            return(callSettings);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the request ID for logging.
        /// </summary>
        /// <param name="responseHeaders">The response headers.</param>
        /// <param name="response">The response.</param>
        /// <param name="exception">The exception, if available.</param>
        /// <returns>The request ID.</returns>
        public string GetRequestId(Metadata responseHeaders, object response,
                                   RpcException exception)
        {
            string requestId = new AdsResponseMetadata(responseHeaders).RequestId;

            // For streaming calls, the trailing response headers are returned only after
            // the entire stream is read, whereas we write summary logs each time we retrieve
            // a response object from the stream. As a result, the requestId in summary logs
            // appear blank in all except the last entry. As a fix, we read the request Id
            // from the stream response object as a fallback.
            if (string.IsNullOrEmpty(requestId))
            {
                IResponseMetadata responseMetadata = response as IResponseMetadata;
                if (responseMetadata != null)
                {
                    requestId = responseMetadata.RequestId;
                }
            }
            if (string.IsNullOrEmpty(requestId))
            {
                AdsBaseException adsException = exception as AdsBaseException;
                if (adsException != null)
                {
                    requestId = adsException.RequestId;
                }
            }
            return(requestId);
        }