public async Task CreateLogMetricAsync() { Mock <MetricsServiceV2.MetricsServiceV2Client> mockGrpcClient = new Mock <MetricsServiceV2.MetricsServiceV2Client>(MockBehavior.Strict); CreateLogMetricRequest expectedRequest = new CreateLogMetricRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Metric = new LogMetric(), }; LogMetric expectedResponse = new LogMetric { MetricNameOneof = MetricNameOneof.From(new MetricName("[PROJECT]", "[METRIC]")), Description = "description-1724546052", Filter = "filter-1274492040", ValueExtractor = "valueExtractor2047672534", }; mockGrpcClient.Setup(x => x.CreateLogMetricAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LogMetric>(Task.FromResult(expectedResponse), null, null, null, null)); MetricsServiceV2Client client = new MetricsServiceV2ClientImpl(mockGrpcClient.Object, null); ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogMetric metric = new LogMetric(); LogMetric response = await client.CreateLogMetricAsync(parent, metric); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public static int Main(string[] args) { // Read projectId from args if (args.Length != 1) { Console.WriteLine("Usage: Project ID must be passed as first argument."); Console.WriteLine(); return(1); } string projectId = args[0]; // Create client DataTransferServiceClient client = DataTransferServiceClient.Create(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new LocationName(projectId, "us-central1")); // Call API method PagedEnumerable <ListDataSourcesResponse, DataSource> pagedResponse = client.ListDataSources(parent); // Show the result foreach (var item in pagedResponse) { Console.WriteLine(item); } // Success Console.WriteLine("Smoke test passed OK"); return(0); }
public void CreateLogMetric() { Mock <MetricsServiceV2.MetricsServiceV2Client> mockGrpcClient = new Mock <MetricsServiceV2.MetricsServiceV2Client>(MockBehavior.Strict); CreateLogMetricRequest expectedRequest = new CreateLogMetricRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Metric = new LogMetric(), }; LogMetric expectedResponse = new LogMetric { Name = "name3373707", Description = "description-1724546052", Filter = "filter-1274492040", ValueExtractor = "valueExtractor2047672534", }; mockGrpcClient.Setup(x => x.CreateLogMetric(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); MetricsServiceV2Client client = new MetricsServiceV2ClientImpl(mockGrpcClient.Object, null); ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogMetric metric = new LogMetric(); LogMetric response = client.CreateLogMetric(parent, metric); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task CreateExclusionAsync() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); CreateExclusionRequest expectedRequest = new CreateExclusionRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Exclusion = new LogExclusion(), }; LogExclusion expectedResponse = new LogExclusion { Name = "name3373707", Description = "description-1724546052", Filter = "filter-1274492040", Disabled = true, }; mockGrpcClient.Setup(x => x.CreateExclusionAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LogExclusion>(Task.FromResult(expectedResponse), null, null, null, null)); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogExclusion exclusion = new LogExclusion(); LogExclusion response = await client.CreateExclusionAsync(parent, exclusion); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
// [END logging_list_log_entries] // [START create_log_sink] private void CreateSink(string sinkId, string logId) { var sinkClient = ConfigServiceV2Client.Create(); CreateSinkRequest sinkRequest = new CreateSinkRequest(); LogSink myLogSink = new LogSink(); myLogSink.Name = sinkId; // This creates a sink using a Google Cloud Storage bucket // named the same as the projectId. // This requires editing the bucket's permissions to add the Entity Group // named '*****@*****.**' with 'Owner' access for the bucket. // If this is being run with a Google Cloud service account, // that account will need to be granted 'Owner' access to the Project. // In Powershell, use this command: // PS > Add-GcsBucketAcl <your-bucket-name> -Role OWNER -Group [email protected] myLogSink.Destination = "storage.googleapis.com/" + s_projectId; LogName logName = new LogName(s_projectId, logId); myLogSink.Filter = $"logName={logName.ToString()}AND severity<=ERROR"; ProjectName projectName = new ProjectName(s_projectId); sinkRequest.Sink = myLogSink; sinkClient.CreateSink(ParentNameOneof.From(projectName), myLogSink, _retryAWhile); Console.WriteLine($"Created sink: {sinkId}."); }
public async Task CreateSinkAsync2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; LogSink expectedResponse = new LogSink { Name = "name3373707", DestinationAsResourceName = new BillingName("[BILLING_ACCOUNT]"), Filter = "filter-1274492040", WriterIdentity = "writerIdentity775638794", IncludeChildren = true, }; mockGrpcClient.Setup(x => x.CreateSinkAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LogSink>(Task.FromResult(expectedResponse), null, null, null, null)); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogSink response = await client.CreateSinkAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void CreateSink2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; LogSink expectedResponse = new LogSink { Name = "name3373707", DestinationAsResourceName = new ProjectName("[PROJECT]"), Filter = "filter-1274492040", WriterIdentity = "writerIdentity775638794", IncludeChildren = true, }; mockGrpcClient.Setup(x => x.CreateSink(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogSink response = client.CreateSink(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for CreateLogMetric</summary> public void CreateLogMetric() { // Snippet: CreateLogMetric(ParentNameOneof,LogMetric,CallSettings) // Create client MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.Create(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogMetric metric = new LogMetric(); // Make the request LogMetric response = metricsServiceV2Client.CreateLogMetric(parent, metric); // End snippet }
// [END create_log_sink] // [START list_log_sinks] private void ListSinks() { var sinkClient = ConfigServiceV2Client.Create(); ProjectName projectName = new ProjectName(s_projectId); var listOfSinks = sinkClient.ListSinks(ParentNameOneof.From(projectName), callSettings: _retryAWhile); foreach (var sink in listOfSinks) { Console.WriteLine($"{sink.Name} {sink.ToString()}"); } }
/// <summary>Snippet for CreateSink</summary> public void CreateSink() { // Snippet: CreateSink(ParentNameOneof,LogSink,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogSink sink = new LogSink(); // Make the request LogSink response = configServiceV2Client.CreateSink(parent, sink); // End snippet }
/// <summary>Snippet for CreateExclusion</summary> public void CreateExclusion() { // Snippet: CreateExclusion(ParentNameOneof,LogExclusion,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogExclusion exclusion = new LogExclusion(); // Make the request LogExclusion response = configServiceV2Client.CreateExclusion(parent, exclusion); // End snippet }
/// <summary>Snippet for CreateLogMetricAsync</summary> public async Task CreateLogMetricAsync() { // Snippet: CreateLogMetricAsync(ParentNameOneof,LogMetric,CallSettings) // Additional: CreateLogMetricAsync(ParentNameOneof,LogMetric,CancellationToken) // Create client MetricsServiceV2Client metricsServiceV2Client = await MetricsServiceV2Client.CreateAsync(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogMetric metric = new LogMetric(); // Make the request LogMetric response = await metricsServiceV2Client.CreateLogMetricAsync(parent, metric); // End snippet }
/// <summary>Snippet for CreateExclusion</summary> public void CreateExclusion_RequestObject() { // Snippet: CreateExclusion(CreateExclusionRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) CreateExclusionRequest request = new CreateExclusionRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Exclusion = new LogExclusion(), }; // Make the request LogExclusion response = configServiceV2Client.CreateExclusion(request); // End snippet }
/// <summary>Snippet for CreateLogMetric</summary> public void CreateLogMetric_RequestObject() { // Snippet: CreateLogMetric(CreateLogMetricRequest,CallSettings) // Create client MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.Create(); // Initialize request argument(s) CreateLogMetricRequest request = new CreateLogMetricRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Metric = new LogMetric(), }; // Make the request LogMetric response = metricsServiceV2Client.CreateLogMetric(request); // End snippet }
/// <summary>Snippet for CreateExclusionAsync</summary> public async Task CreateExclusionAsync() { // Snippet: CreateExclusionAsync(ParentNameOneof,LogExclusion,CallSettings) // Additional: CreateExclusionAsync(ParentNameOneof,LogExclusion,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogExclusion exclusion = new LogExclusion(); // Make the request LogExclusion response = await configServiceV2Client.CreateExclusionAsync(parent, exclusion); // End snippet }
/// <summary>Snippet for ListExclusionsAsync</summary> public async Task ListExclusionsAsync_RequestObject() { // Snippet: ListExclusionsAsync(ListExclusionsRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) ListExclusionsRequest request = new ListExclusionsRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), }; // Make the request PagedAsyncEnumerable <ListExclusionsResponse, LogExclusion> response = configServiceV2Client.ListExclusionsAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((LogExclusion item) => { // Do something with each item Console.WriteLine(item); }); // Or iterate over pages (of server-defined size), performing one RPC per page await response.AsRawResponses().ForEachAsync((ListExclusionsResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (LogExclusion item in page) { Console.WriteLine(item); } }); // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <LogExclusion> singlePage = await response.ReadPageAsync(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (LogExclusion item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for CreateSinkAsync</summary> public async Task CreateSinkAsync_RequestObject() { // Snippet: CreateSinkAsync(CreateSinkRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; // Make the request LogSink response = await configServiceV2Client.CreateSinkAsync(request); // End snippet }
/// <summary>Snippet for ListLogMetrics</summary> public void ListLogMetrics_RequestObject() { // Snippet: ListLogMetrics(ListLogMetricsRequest,CallSettings) // Create client MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.Create(); // Initialize request argument(s) ListLogMetricsRequest request = new ListLogMetricsRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), }; // Make the request PagedEnumerable <ListLogMetricsResponse, LogMetric> response = metricsServiceV2Client.ListLogMetrics(request); // Iterate over all response items, lazily performing RPCs as required foreach (LogMetric item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (ListLogMetricsResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (LogMetric item in page) { Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <LogMetric> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (LogMetric item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for CreateExclusionAsync</summary> public async Task CreateExclusionAsync_RequestObject() { // Snippet: CreateExclusionAsync(CreateExclusionRequest,CallSettings) // Additional: CreateExclusionAsync(CreateExclusionRequest,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) CreateExclusionRequest request = new CreateExclusionRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Exclusion = new LogExclusion(), }; // Make the request LogExclusion response = await configServiceV2Client.CreateExclusionAsync(request); // End snippet }
/// <summary>Snippet for CreateLogMetricAsync</summary> public async Task CreateLogMetricAsync_RequestObject() { // Snippet: CreateLogMetricAsync(CreateLogMetricRequest,CallSettings) // Additional: CreateLogMetricAsync(CreateLogMetricRequest,CancellationToken) // Create client MetricsServiceV2Client metricsServiceV2Client = await MetricsServiceV2Client.CreateAsync(); // Initialize request argument(s) CreateLogMetricRequest request = new CreateLogMetricRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Metric = new LogMetric(), }; // Make the request LogMetric response = await metricsServiceV2Client.CreateLogMetricAsync(request); // End snippet }
public static void Main(string[] args) { // Instantiates a client DataTransferServiceClient client = DataTransferServiceClient.Create(); // Your Google Cloud Platform project ID string projectId = "YOUR-PROJECT-ID"; ProjectName project = new ProjectName(projectId); var sources = client.ListDataSources(ParentNameOneof.From(project)); Console.WriteLine("Supported Data Sources:"); foreach (DataSource source in sources) { Console.WriteLine( $"{source.DataSourceId}: " + $"{source.DisplayName} ({source.Description})"); } }
public void CreateExclusion2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); CreateExclusionRequest request = new CreateExclusionRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Exclusion = new LogExclusion(), }; LogExclusion expectedResponse = new LogExclusion { Name = "name3373707", Description = "description-1724546052", Filter = "filter-1274492040", Disabled = true, }; mockGrpcClient.Setup(x => x.CreateExclusion(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogExclusion response = client.CreateExclusion(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
static void Main(string[] args) { var authFile = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"); if (string.IsNullOrEmpty(authFile)) { Console.WriteLine("Please set the GOOGLE_APPLICATION_CREDENTIALS environment variable and rerun"); return; } var projectId = Environment.GetEnvironmentVariable("TEST_PROJECT"); if (string.IsNullOrEmpty(projectId)) { Console.WriteLine("Please set the TEST_PROJECT environment variable and rerun"); return; } var apis = new List <Api> { (BigtableInstanceAdminClient client) => client.ListInstances(new Bigtable.Admin.V2.ProjectName(projectId)), (BigtableClient client) => client.ReadRows(new ReadRowsRequest { TableName = "table" }), (DatastoreClient client) => client.AllocateIds(projectId, new[] { new Datastore.V1.Key() }), (Debugger2Client client) => client.ListDebuggees(projectId, "0.0"), (DlpServiceClient client) => client.ListRootCategories("en"), (ErrorStatsServiceClient client) => client.ListGroupStats(new ErrorReporting.V1Beta1.ProjectName(projectId), new QueryTimeRange { Period = Period._30Days }).Count(), (LanguageServiceClient client) => client.AnalyzeSentiment(Document.FromPlainText("This is good")), (LoggingServiceV2Client client) => client.ListLogs(ParentNameOneof.From(new Logging.V2.ProjectName(projectId))).Count(), (MetricServiceClient client) => client.ListMetricDescriptors(new Monitoring.V3.ProjectName(projectId)).Count(), (PublisherClient client) => client.ListTopics(new PubSub.V1.ProjectName(projectId)), (SubscriberClient client) => client.ListSubscriptions(new PubSub.V1.ProjectName(projectId)), (DatabaseAdminClient client) => client.ListDatabases(new Spanner.Admin.Database.V1.InstanceName(projectId, "instance")).Count(), (InstanceAdminClient client) => client.ListInstances(new Spanner.Admin.Instance.V1.ProjectName(projectId)).Count(), (SpannerClient client) => client.GetSession(new SessionName(projectId, "instance", "database", "session")), (SpeechClient client) => client.Recognize( new RecognitionConfig { Encoding = AudioEncoding.Linear16, SampleRateHertz = 16000, LanguageCode = LanguageCodes.English.UnitedStates }, RecognitionAudio.FromStorageUri("gs://nodatime/releases/NodaTime-1.0.0.zip")), (TraceServiceClient client) => client.ListTraces(projectId).Count(), (VideoIntelligence.V1Beta1.VideoIntelligenceServiceClient client) => client.AnnotateVideo( new VideoIntelligence.V1Beta1.AnnotateVideoRequest { InputUri = "gs://cloudmleap/video/next/gbikes_dinosaur.mp4", Features = { VideoIntelligence.V1Beta1.Feature.LabelDetection } }), (VideoIntelligence.V1Beta2.VideoIntelligenceServiceClient client) => client.AnnotateVideo( new VideoIntelligence.V1Beta2.AnnotateVideoRequest { InputUri = "gs://cloudmleap/video/next/gbikes_dinosaur.mp4", Features = { VideoIntelligence.V1Beta2.Feature.LabelDetection } }), (ImageAnnotatorClient client) => client.DetectText(Image.FromUri("https://cloud.google.com/images/devtools-icon-64x64.png")).Count() }; foreach (var api in apis) { Console.WriteLine(api); Console.WriteLine($"Default: {api.TestDefaultCreate()}"); Console.WriteLine($"Loaded credentials, no scopes: {api.TestWithCredentials(authFile)}"); Console.WriteLine($"Loaded credentials, with scopes: {api.TestWithCredentialsAndScopes(authFile)}"); Console.WriteLine(); } } }