Beispiel #1
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(GoogleAdsConfig.DEVELOPER_TOKEN_KEYNAME,
                                                   config.DeveloperToken)
                           .WithResponseMetadataHandler(delegate(Metadata metadata)
            {
                GoogleAdsResponseMetadata responseMetadata =
                    new GoogleAdsResponseMetadata(metadata);
                serviceContext.OnResponseMetadataReceived(responseMetadata);
            });

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

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

            callSettings = callSettings.WithCallTiming(CallTiming.FromTimeout(
                                                           TimeSpan.FromMilliseconds(config.Timeout)));

            return(callSettings);
        }
Beispiel #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);
        }
        /// <summary>
        /// Creates a service context that binds the service, callsettings and the client.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <returns>The service context.</returns>
        private GoogleAdsServiceContext CreateServiceContext(GoogleAdsConfig config)
        {
            GoogleAdsServiceContext serviceContext = new GoogleAdsServiceContext();
            CallSettings            callSettings   = CallSettings.FromCallTiming(
                CallTiming.FromRetry(new RetrySettings(
                                         retryBackoff : backoffSettings,
                                         timeoutBackoff : backoffSettings,
                                         totalExpiration : Expiration.FromTimeout(TimeSpan.FromMilliseconds(
                                                                                      config.Timeout)),
                                         retryFilter : retryFilter
                                         )))
                                                     .WithHeader(GoogleAdsConfig.DEVELOPER_TOKEN_KEYNAME, config.DeveloperToken)
                                                     .WithResponseMetadataHandler(delegate(Metadata metadata)
            {
                GoogleAdsResponseMetadata responseMetadata = new GoogleAdsResponseMetadata(metadata);
                serviceContext.OnResponseMetadataReceived(responseMetadata);
            });

            if (!string.IsNullOrEmpty(config.LoginCustomerId))
            {
                callSettings.WithHeader("login-customer-id", config.LoginCustomerId);
            }

            serviceContext.CallSettings = callSettings;
            return(serviceContext);
        }
Beispiel #4
0
        public void WithHeader_NullSettings()
        {
            CallSettings settings = null;
            var          result   = settings.WithHeader("name", "value");
            var          metadata = new Metadata();

            result.HeaderMutation(metadata);
            Assert.Equal("name", metadata[0].Key);
            Assert.Equal("value", metadata[0].Value);
        }
Beispiel #5
0
        // TODO: Consider Write and Listen, where the settings and the requests are separate.

        private static void ApplyResourcePrefixHeader(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just let the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }
            string database = GetDatabaseResourceName(resource);

            settings = settings.WithHeader(ResourcePrefixHeader, database);
        }
Beispiel #6
0
        public void WithHeader_NonNullSettings()
        {
            CallSettings settings = CallSettings.FromHeader("name1", "value1");
            var          result   = settings.WithHeader("name2", "value2");
            var          metadata = new Metadata();

            result.HeaderMutation(metadata);
            Assert.Equal("name1", metadata[0].Key);
            Assert.Equal("value1", metadata[0].Value);
            Assert.Equal("name2", metadata[1].Key);
            Assert.Equal("value2", metadata[1].Value);
        }
        private static void ApplyResourcePrefixHeaderFromProject(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just leave the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }

            if (ProjectName.TryParse(resource, out ProjectName project))
            {
                settings = settings.WithHeader(ResourcePrefixHeader, project.ToString());
            }
        }
        internal static void ApplyResourcePrefixHeaderFromDatabase(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just leave the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }

            if (DatabaseName.TryParse(resource, out DatabaseName database))
            {
                settings = settings.WithHeader(ResourcePrefixHeader, database.ToString());
            }
        }
        private static void ApplyResourcePrefixHeaderFromInstanceConfig(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just leave the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }

            if (InstanceConfigName.TryParse(resource, out InstanceConfigName instanceConfig))
            {
                var project = ProjectName.FromProject(instanceConfig.ProjectId);
                settings = settings.WithHeader(ResourcePrefixHeader, project.ToString());
            }
        }
        private static void ApplyResourcePrefixHeaderFromBackup(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just leave the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }

            if (BackupName.TryParse(resource, out BackupName backup))
            {
                var instance = InstanceName.FromProjectInstance(backup.ProjectId, backup.InstanceId);
                settings = settings.WithHeader(ResourcePrefixHeader, instance.ToString());
            }
        }
        internal static void ApplyResourcePrefixHeaderFromSession(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just leave the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }

            if (SessionName.TryParse(resource, out SessionName session))
            {
                var database = DatabaseName.FromProjectInstanceDatabase(
                    session.ProjectId, session.InstanceId, session.DatabaseId);
                settings = settings.WithHeader(ResourcePrefixHeader, database.ToString());
            }
        }
 private static void ApplyResourcePrefixHeader(ref CallSettings settings, string resource)
 {
     settings = settings.WithHeader(ResourcePrefixHeader, resource);
 }
Beispiel #13
0
 partial void Modify_RunQueryRequest(ref RunQueryRequest request, ref CallSettings settings)
 {
     settings = settings.WithHeader(ResourcePrefixHeader, "projects/" + request.ProjectId);
 }
Beispiel #14
0
 partial void Modify_BeginTransactionRequest(ref BeginTransactionRequest request, ref CallSettings settings)
 {
     settings = settings.WithHeader(ResourcePrefixHeader, "projects/" + request.ProjectId);
 }
Beispiel #15
0
 partial void Modify_AllocateIdsRequest(ref AllocateIdsRequest request, ref CallSettings settings)
 {
     settings = settings.WithHeader(ResourcePrefixHeader, "projects/" + request.ProjectId);
 }