/// <summary> /// Initializes a new instance of <see cref="StackdriverTraceExporter"/> class. /// </summary> /// <param name="projectId">Project ID to send telemetry to.</param> public StackdriverTraceExporter(string projectId) { this.googleCloudProjectId = new Google.Api.Gax.ResourceNames.ProjectName(projectId); // Set header mutation for every outgoing API call to Stackdriver so the BE knows // which version of OC client is calling it as well as which version of the exporter var callSettings = CallSettings.FromHeaderMutation(StackdriverCallHeaderAppender); this.traceServiceSettings = new TraceServiceSettings(); this.traceServiceSettings.CallSettings = callSettings; }
/// <summary>Snippet for BatchGetAssetsHistory</summary> public void BatchGetAssetsHistory() { // Snippet: BatchGetAssetsHistory(string,CallSettings) // Create client AssetServiceClient assetServiceClient = AssetServiceClient.Create(); // Initialize request argument(s) string formattedParent = new Google.Api.Gax.ResourceNames.ProjectName("[PROJECT]").ToString(); // Make the request BatchGetAssetsHistoryResponse response = assetServiceClient.BatchGetAssetsHistory(formattedParent); // End snippet }
/// <summary>Snippet for BatchGetAssetsHistoryAsync</summary> public async Task BatchGetAssetsHistoryAsync() { // Snippet: BatchGetAssetsHistoryAsync(string,CallSettings) // Additional: BatchGetAssetsHistoryAsync(string,CancellationToken) // Create client AssetServiceClient assetServiceClient = await AssetServiceClient.CreateAsync(); // Initialize request argument(s) string formattedParent = new Google.Api.Gax.ResourceNames.ProjectName("[PROJECT]").ToString(); // Make the request BatchGetAssetsHistoryResponse response = await assetServiceClient.BatchGetAssetsHistoryAsync(formattedParent); // End snippet }
public async Task BatchGetAssetsHistoryAsync() { Mock <AssetService.AssetServiceClient> mockGrpcClient = new Mock <AssetService.AssetServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); BatchGetAssetsHistoryRequest expectedRequest = new BatchGetAssetsHistoryRequest { Parent = new Google.Api.Gax.ResourceNames.ProjectName("[PROJECT]").ToString(), }; BatchGetAssetsHistoryResponse expectedResponse = new BatchGetAssetsHistoryResponse(); mockGrpcClient.Setup(x => x.BatchGetAssetsHistoryAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <BatchGetAssetsHistoryResponse>(Task.FromResult(expectedResponse), null, null, null, null)); AssetServiceClient client = new AssetServiceClientImpl(mockGrpcClient.Object, null); string formattedParent = new Google.Api.Gax.ResourceNames.ProjectName("[PROJECT]").ToString(); BatchGetAssetsHistoryResponse response = await client.BatchGetAssetsHistoryAsync(formattedParent); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary> /// /// <para>BTracingServiceGC: Parametered Constructor for Managed Service by Google</para> /// /// <para>Parameters:</para> /// <para><paramref name="_ProjectID"/> GC Project ID</para> /// <para><paramref name="_ProgramUniqueID"/> Program Unique ID</para> /// <para><paramref name="_ErrorMessageAction"/> Error messages will be pushed to this action</para> /// /// </summary> public BTracingServiceGC( string _ProjectID, string _ProgramUniqueID, Action <string> _ErrorMessageAction = null) { ProgramUniqueID = _ProgramUniqueID; ErrorMessageAction = _ErrorMessageAction; try { string ApplicationCredentials = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"); string ApplicationCredentialsPlain = Environment.GetEnvironmentVariable("GOOGLE_PLAIN_CREDENTIALS"); if (ApplicationCredentials == null && ApplicationCredentialsPlain == null) { _ErrorMessageAction?.Invoke("BTracingServiceGC->Constructor: GOOGLE_APPLICATION_CREDENTIALS (or GOOGLE_PLAIN_CREDENTIALS) environment variable is not defined."); bInitializationSucceed = false; } else { var Scopes = new List <string>(); foreach (var Scope in TraceServiceClient.DefaultScopes) { if (!Scopes.Contains(Scope)) { Scopes.Add(Scope); } } if (ApplicationCredentials == null) { if (!BUtility.HexDecode(out ApplicationCredentialsPlain, ApplicationCredentialsPlain, _ErrorMessageAction)) { throw new Exception("Hex decode operation for application credentials plain has failed."); } Credential = GoogleCredential.FromJson(ApplicationCredentialsPlain) .CreateScoped( Scopes.ToArray()) .UnderlyingCredential as ServiceAccountCredential; } else { using (var Stream = new FileStream(ApplicationCredentials, FileMode.Open, FileAccess.Read)) { Credential = GoogleCredential.FromStream(Stream) .CreateScoped( Scopes.ToArray()) .UnderlyingCredential as ServiceAccountCredential; } } if (Credential != null) { Channel = new Grpc.Core.Channel( TraceServiceClient.DefaultEndpoint.ToString(), Credential.ToChannelCredentials()); } if (Channel != null) { TraceClient = TraceServiceClient.Create(Channel); ProjectName = new Google.Api.Gax.ResourceNames.ProjectName(_ProjectID); bInitializationSucceed = TraceClient != null; UploadTimer = new Timer(1_000); UploadTimer.Elapsed += OnTimedEvent; UploadTimer.AutoReset = true; UploadTimer.Enabled = true; } else { bInitializationSucceed = false; } } } catch (Exception e) { _ErrorMessageAction?.Invoke("BTracingServiceGC->Constructor: " + e.Message + ", Trace: " + e.StackTrace); bInitializationSucceed = false; } }