Ejemplo n.º 1
0
 private LanguageServiceSettings(LanguageServiceSettings existing) : base(existing)
 {
     GaxPreconditions.CheckNotNull(existing, nameof(existing));
     AnalyzeSentimentSettings = existing.AnalyzeSentimentSettings?.Clone();
     AnalyzeEntitiesSettings  = existing.AnalyzeEntitiesSettings?.Clone();
     AnnotateTextSettings     = existing.AnnotateTextSettings?.Clone();
 }
Ejemplo n.º 2
0
        public LanguageServiceClientImpl(LanguageService.LanguageServiceClient grpcClient, LanguageServiceSettings settings)
        {
            this.GrpcClient = grpcClient;
            LanguageServiceSettings effectiveSettings = settings ?? LanguageServiceSettings.GetDefault();

            _clientHelper         = new ClientHelper(effectiveSettings);
            _callAnalyzeSentiment = _clientHelper.BuildApiCall <AnalyzeSentimentRequest, AnalyzeSentimentResponse>(
                GrpcClient.AnalyzeSentimentAsync, GrpcClient.AnalyzeSentiment, effectiveSettings.AnalyzeSentimentSettings);
            _callAnalyzeEntities = _clientHelper.BuildApiCall <AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>(
                GrpcClient.AnalyzeEntitiesAsync, GrpcClient.AnalyzeEntities, effectiveSettings.AnalyzeEntitiesSettings);
            _callAnnotateText = _clientHelper.BuildApiCall <AnnotateTextRequest, AnnotateTextResponse>(
                GrpcClient.AnnotateTextAsync, GrpcClient.AnnotateText, effectiveSettings.AnnotateTextSettings);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Wrap a GRPC LanguageService client for more convenient use.
 /// </summary>
 /// <param name="grpcClient">A GRPC client to wrap.</param>
 /// <param name="settings">
 /// An optional <see cref="LanguageServiceSettings"/> to configure this wrapper.
 /// If null or not specified, then the default settings are used.
 /// </param>
 /// <returns>A <see cref="LanguageServiceClient"/> that wraps the specified GRPC client.</returns>
 public static LanguageServiceClient ToClient(
     this LanguageService.LanguageServiceClient grpcClient,
     LanguageServiceSettings settings = null
     ) => new LanguageServiceClientImpl(grpcClient, settings);
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a <see cref="LanguageServiceClient"/> which uses the specified channel for remote operations.
 /// </summary>
 /// <param name="channel">The <see cref="Channel"/> for remote operations. Must not be null.</param>
 /// <param name="settings">Optional <see cref="LanguageServiceSettings"/>.</param>
 /// <returns>The created <see cref="LanguageServiceClient"/>.</returns>
 public static LanguageServiceClient Create(Channel channel, LanguageServiceSettings settings = null)
 {
     GaxPreconditions.CheckNotNull(channel, nameof(channel));
     LanguageService.LanguageServiceClient grpcClient = new LanguageService.LanguageServiceClient(channel);
     return(new LanguageServiceClientImpl(grpcClient, settings));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Synchronously creates a <see cref="LanguageServiceClient"/>, applying defaults for all unspecified settings,
        /// and creating a channel connecting to the given endpoint with application default credentials where
        /// necessary.
        /// </summary>
        /// <param name="endpoint">Optional <see cref="ServiceEndpoint"/>.</param>
        /// <param name="settings">Optional <see cref="LanguageServiceSettings"/>.</param>
        /// <returns>The created <see cref="LanguageServiceClient"/>.</returns>
        public static LanguageServiceClient Create(ServiceEndpoint endpoint = null, LanguageServiceSettings settings = null)
        {
            Channel channel = s_channelPool.GetChannel(endpoint ?? DefaultEndpoint);

            return(Create(channel, settings));
        }
Ejemplo n.º 6
0
        // Note: we could have parameterless overloads of Create and CreateAsync,
        // documented to just use the default endpoint, settings and credentials.
        // Pros:
        // - Might be more reassuring on first use
        // - Allows method group conversions
        // Con: overloads!

        /// <summary>
        /// Asynchronously creates a <see cref="LanguageServiceClient"/>, applying defaults for all unspecified settings,
        /// and creating a channel connecting to the given endpoint with application default credentials where
        /// necessary.
        /// </summary>
        /// <param name="endpoint">Optional <see cref="ServiceEndpoint"/>.</param>
        /// <param name="settings">Optional <see cref="LanguageServiceSettings"/>.</param>
        /// <returns>The task representing the created <see cref="LanguageServiceClient"/>.</returns>
        public static async Task <LanguageServiceClient> CreateAsync(ServiceEndpoint endpoint = null, LanguageServiceSettings settings = null)
        {
            Channel channel = await s_channelPool.GetChannelAsync(endpoint ?? DefaultEndpoint).ConfigureAwait(false);

            return(Create(channel, settings));
        }