/// <summary> /// Creates the channel. /// </summary> /// <param name="config">The configuration.</param> /// <returns>The channel.</returns> private static Channel CreateChannel(GoogleAdsConfig config) { ChannelCredentials channelCredentials = null; if (config.AuthorizationMethod == AuthorizationMethod.Insecure) { channelCredentials = ChannelCredentials.Insecure; } else // if config.AuthenticationMode == AuthenticationMode.OAUTH) { channelCredentials = GoogleGrpcCredentials.ToChannelCredentials(config.Credentials); } Uri uri = new Uri(config.ServerUrl); return(new Channel(uri.Host, uri.Port, channelCredentials, new List <ChannelOption>() { new ChannelOption(GRPC_MAX_RECEIVE_MESSAGE_LENGTH_IN_BYTES_SETTING_NAME, MAX_RECEIVE_MESSAGE_LENGTH_IN_BYTES), new ChannelOption(GRPC_MAX_METADATA_SIZE_IN_BYTES_SETTING_NAME, MAX_METADATA_SIZE_IN_BYTES), } )); }
/// <summary> /// Creates the channel. /// </summary> /// <param name="config">The configuration.</param> /// <returns>The channel.</returns> private ChannelBase CreateChannel(GoogleAdsConfig config) { ChannelCredentials channelCredentials; if (config.AuthorizationMethod == AuthorizationMethod.Insecure) { channelCredentials = ChannelCredentials.Insecure; } else // if config.AuthenticationMode == AuthenticationMode.OAUTH) { channelCredentials = GoogleGrpcCredentials.ToChannelCredentials(config.Credentials); } Uri uri = new Uri(config.ServerUrl); List <ChannelOption> options = new List <ChannelOption>() { new ChannelOption(GRPC_MAX_RECEIVE_MESSAGE_LENGTH_IN_BYTES_SETTING_NAME, config.MaxReceiveMessageSizeInBytes), new ChannelOption(GRPC_MAX_METADATA_SIZE_IN_BYTES_SETTING_NAME, config.MaxMetadataSizeInBytes), }; if (config.Proxy != null) { options.Add(new ChannelOption(GRPC_HTTP_PROXY_SETTING_NAME, config.Proxy.Address.ToString())); } return(new Channel(uri.Host, uri.Port, channelCredentials, options)); }
/// <summary> /// Creates the channel. /// </summary> /// <param name="config">The configuration.</param> /// <returns>The channel.</returns> private static Channel CreateChannel(GoogleAdsConfig config) { ChannelCredentials channelCredentials = GoogleGrpcCredentials.ToChannelCredentials(config.Credentials); Uri uri = new Uri(config.ServerUrl); return(new Channel(uri.Host, uri.Port, channelCredentials, new List <ChannelOption>() { new ChannelOption(GRPC_MAX_RECEIVE_MESSAGE_LENGTH_IN_BYTES_SETTING_NAME, MAX_RECEIVE_MESSAGE_LENGTH_IN_BYTES.ToString()), new ChannelOption(GRPC_MAX_METADATA_SIZE_IN_BYTES_SETTING_NAME, MAX_METADATA_SIZE_IN_BYTES.ToString()), } )); }
public static void Main(string[] args) { Console.Title = typeof(MainClass).Name; var parent = "projects/mch-test-49bba/databases/(default)"; Console.Title = parent; Boolean debug = false; if (args.Length > 0 && args[0] == "--debug") { debug = true; } if (debug) { Console.WriteLine("GOOGLE_APPLICATION_CREDENTIALS: " + Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")); var storage = StorageClient.Create(); var buckets = storage.ListBuckets("mch-test-49bba"); foreach (var bucket in buckets) { Console.WriteLine(bucket.Name); } } GoogleCredential credential = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")); if (credential == null) { Console.WriteLine("Could not create credential from file."); Console.WriteLine("GOOGLE_APPLICATION_CREDENTIALS: " + Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")); } Grpc.Core.Channel channel = new Grpc.Core.Channel( "firestore.googleapis.com:443", GoogleGrpcCredentials.ToChannelCredentials(credential) ); Firestore.FirestoreClient fsClient = new Firestore.FirestoreClient(channel); FirestoreAdmin.FirestoreAdminClient fsAdminClient = new FirestoreAdmin.FirestoreAdminClient(channel); String baseCollectionId = "GrpcTestData"; Ftc = new FirestoreTestClass(parent, fsClient, fsAdminClient, baseCollectionId); Run(); }
/// <summary> /// Creates the channel for the new service, and sets the proxy server. /// </summary> /// <param name="config">The configuration.</param> /// <returns>The new channel.</returns> private Channel CreateChannel(GoogleAdsConfig config) { ChannelCredentials channelCredentials = GoogleGrpcCredentials.ToChannelCredentials(config.Credentials); if (config.Proxy == null) { Environment.SetEnvironmentVariable("http_proxy", null); } else { Environment.SetEnvironmentVariable("http_proxy", config.Proxy.Address.ToString()); } Uri uri = new Uri(config.ServerUrl); return(new Channel(uri.Host, uri.Port, channelCredentials, null)); }
/// <summary> /// Starting point of the Google Streaming Speech-to-Text program. /// </summary> /// <param name="args">First argument must be the path to the credentials JSON file.</param> static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage: GoogleCloudSpeech.exe [path to credentials JSON file]"); } else { // Create client var fileStream = new FileStream(args[0], FileMode.Open); GoogleCredential googleCredential = GoogleCredential.FromStream(fileStream); ChannelCredentials channelCredentials = GoogleGrpcCredentials.ToChannelCredentials(googleCredential); m_Channel = new Channel("speech.googleapis.com", channelCredentials); m_Client = new Speech.SpeechClient(m_Channel); // Wait to begin streaming Console.WriteLine("ready to start"); while (Console.ReadLine() != "start") { ; } Console.WriteLine("start streaming"); Task streamingTask = StreamingRequest(); // Check for input files string input; while ((input = Console.ReadLine()) != "stop") { m_AudioChunksQueue.Enqueue(ByteString.CopyFrom(File.ReadAllBytes(input))); Console.WriteLine("received audio file input"); } // Finish streaming and wait for the request to finish Console.WriteLine("stop streaming"); m_DoneStreaming = true; streamingTask.Wait(); m_Channel.ShutdownAsync().Wait(); } }
public static void executeProbes(string api) { StackdriverUtilClass util = new StackdriverUtilClass(api); GoogleCredential auth = GoogleCredential.GetApplicationDefault(); //GoogleCredential auth = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")); ClientBase client; ProbeTestsBaseClass test; System.Type type; Dictionary <string, string> probe_functions = new Dictionary <string, string>(); if (api == "firestore") { Grpc.Core.Channel channel = new Grpc.Core.Channel(_FIRESTORE_TARGET, GoogleGrpcCredentials.ToChannelCredentials(auth)); client = new Firestore.FirestoreClient(channel); test = new FirestoreProbesTestClass(); probe_functions = (test as FirestoreProbesTestClass).GetProbFunctions(); type = typeof(FirestoreProbesTestClass); } else if (api == "spanner") { Grpc.Core.Channel channel = new Grpc.Core.Channel(_SPANNER_TARGET, GoogleGrpcCredentials.ToChannelCredentials(auth)); client = new Spanner.SpannerClient(channel); test = new SpannerProbesTestClass(); probe_functions = (test as SpannerProbesTestClass).GetProbFunctions(); type = typeof(SpannerProbesTestClass); } else { Console.WriteLine("grpc not implemented for {0}", api); return; } //object value = test.GetType().GetMethod("GetProbFunctions").Invoke(test,null); //probe_functions = value.GetType().GetProperties() int total = probe_functions.Count; int success = 0; Dictionary <string, long> metrics = new Dictionary <string, long>(); foreach (var probe in probe_functions) { Console.WriteLine("{0}", probe.Key); MethodInfo fun = type.GetMethod(probe.Value); object[] parameters = new object[] { client, metrics }; try { if (api == "firestore") { fun.Invoke((test as FirestoreProbesTestClass), parameters); } else { fun.Invoke((test as SpannerProbesTestClass), parameters); } success++; } catch (Exception error) { Console.WriteLine("{0}", error); util.reportError(error); } } if (success == total) { util.setSuccess(true); } util.addMetrics(metrics); util.outputMetrics(); if (success != total) { return; } }
public static ChannelCredentials ToChannelCredential(this GoogleCredential credential) { return(GoogleGrpcCredentials.ToChannelCredentials(credential)); }