/// <summary> /// Gets an instance of the specified service. /// </summary> /// <param name="serviceTemplate">The service template.</param> /// <param name="config">The configuration.</param> /// <returns>A service instance.</returns> internal TService GetService <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config) where TServiceSetting : ServiceSettingsBase, new() where TService : GoogleAdsServiceClientBase { Channel channel = CreateChannel(config); CallInvoker callInvoker = channel.Intercept( LoggingInterceptor.GetInstance(config)); // Build a service context to bind the service, configuration and CallSettings. GoogleAdsServiceContext serviceContext = new GoogleAdsServiceContext(); // Build the call settings. CallSettings callSettings = CreateCallSettings <TServiceSetting>(config, serviceContext); serviceContext.CallSettings = callSettings; // Create the service settings. TServiceSetting serviceSettings = CreateServiceSettings <TServiceSetting>( serviceContext); // Create the service. TService service = Create(serviceTemplate, callInvoker, serviceSettings); serviceContext.Service = service; service.ServiceContext = serviceContext; return(service); }
/// <summary> /// Gets an instance of the specified service. /// </summary> /// <param name="serviceTemplate">The service template.</param> /// <param name="config">The configuration.</param> /// <returns>A service instance.</returns> internal TService GetService <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config) where TServiceSetting : ServiceSettingsBase, new() where TService : GoogleAdsServiceClientBase { return(GetService(serviceTemplate, null, config)); }
/// <summary> /// Gets an instance of the specified service. /// </summary> /// <param name="serviceTemplate">The service template.</param> /// <returns>A service instance.</returns> public TService GetService <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting> serviceTemplate) where TServiceSetting : ServiceSettingsBase, new() where TService : GoogleAdsServiceClientBase { return(GetService(serviceTemplate, null)); }
/// <summary> /// Creates the specified service. /// </summary> /// <typeparam name="TService">The service type.</typeparam> /// <typeparam name="TServiceSetting">The service setting type.</typeparam> /// <param name="callInvoker">The call invoker for service.</param> /// <param name="serviceSettings">The service settings.</param> /// <param name="serviceTemplate">The service template.</param> /// <returns>The newly created service instance.</returns> private TService Create <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting> serviceTemplate, CallInvoker callInvoker, ServiceSettingsBase serviceSettings) where TService : GoogleAdsServiceClientBase where TServiceSetting : ServiceSettingsBase, new() { return((TService)serviceTemplate.CreateService(serviceTemplate.ServiceTypeName, callInvoker, serviceSettings)); }
/// <summary> /// <para>Gets an instance of the specified service. Use this method with a predefined /// list of templates available for each supported version. E.g.</para> /// <para> /// // Gets an instance of V3.GoogleAdsServiceClient<br/> /// GoogleAdsServiceClient googleAdsService = client.GetService(Services.V3.GoogleAdsService); /// </para> /// </summary> /// <param name="serviceTemplate"><para>The template that corresponds to the service to /// be created. Predefined service templates are available for each supported version, as /// a nested class within the <see cref="Services"/> class.</para> /// <para>E.g. <see cref="Services.V3"/> class contains predefined templates for v3 of the /// Google Ads API.</para> /// </param> /// <returns>A service instance.</returns> public TService GetService <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting> serviceTemplate) where TServiceSetting : ServiceSettingsBase, new() where TService : GoogleAdsServiceClientBase { GoogleAdsServiceClientFactory factory = new GoogleAdsServiceClientFactory(); TService service = factory.GetService(serviceTemplate, Config); service.ServiceContext.Client = this; return(service); }
/// <summary> /// Gets an instance of the specified service. /// </summary> /// <param name="serviceTemplate">The service template.</param> /// <param name="config">The configuration.</param> /// <returns>A service instance.</returns> internal TService GetService <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config) where TServiceSetting : ServiceSettingsBase, new() where TService : GoogleAdsServiceClientBase { Channel channel = CreateChannel(config); CallInvoker callInvoker = channel.Intercept( LoggingInterceptor.GetInstance(config)); GoogleAdsServiceContext serviceContext = CreateServiceContext(config); TServiceSetting serviceSettings = CreateServiceSettings <TServiceSetting>( serviceContext); TService service = Create <TService, TServiceSetting>( callInvoker, serviceSettings); serviceContext.Service = service; service.ServiceContext = serviceContext; return(service); }
/// <summary> /// Gets an instance of the specified service. /// </summary> /// <param name="serviceTemplate">The service template.</param> /// <param name="config">The configuration.</param> /// <returns>A service instance.</returns> internal TService GetService <TService, TServiceSetting>( ServiceTemplate <TService, TServiceSetting, GoogleAdsConfig> serviceTemplate, GoogleAdsConfig config) where TServiceSetting : ServiceSettingsBase, new() where TService : GoogleAdsServiceClientBase { ChannelBase channel = CreateChannel(config); CallInvoker interceptedInvoker = channel .Intercept(new GoogleAdsGrpcInterceptor(config)); CallInvoker callInvoker = config.EnableProfiling ? new ProfilingCallInvoker(interceptedInvoker, config) : interceptedInvoker; // Build a service context to bind the service, configuration and CallSettings. GoogleAdsServiceContext serviceContext = new GoogleAdsServiceContext(); // Build the call settings. CallSettings callSettings = CreateCallSettings <TServiceSetting>(config, serviceContext); serviceContext.CallSettings = callSettings; // Create the service settings. TServiceSetting serviceSettings = CreateServiceSettings <TServiceSetting, GoogleAdsConfig>(serviceContext); serviceSettings.VersionHeaderBuilder.AppendAssemblyVersion("gccl", this.GetType()); serviceSettings.VersionHeaderBuilder.AppendAssemblyVersion("protobuf", typeof(IMessage)); // Create the service. TService service = Create(serviceTemplate, callInvoker, serviceSettings); serviceContext.Service = service; service.ServiceContext = serviceContext; service.ServiceContext.ChannelBase = channel; return(service); }