示例#1
0
    public static async Task <Operation> PollUntilCompletedAsync(this Operation operation, string projectId, string zone)
    {
        ZoneOperationsClient operationClient = await ZoneOperationsClient.CreateAsync();

        GetZoneOperationRequest pollRequest = new GetZoneOperationRequest
        {
            Operation = operation.Name,
            Zone      = zone,
            Project   = projectId,
        };

        TimeSpan timeOut      = TimeSpan.FromMinutes(3);
        TimeSpan pollInterval = TimeSpan.FromSeconds(15);

        DateTime deadline = DateTime.UtcNow + timeOut;

        while (operation.Status != Operation.Types.Status.Done)
        {
            operation = await operationClient.GetAsync(pollRequest);

            if (operation.Status == Operation.Types.Status.Done)
            {
                break;
            }

            if (DateTime.UtcNow + pollInterval > deadline)
            {
                throw new InvalidOperationException("Timeout hit while polling for the status of the operation.");
            }

            await Task.Delay(pollInterval);
        }

        return(operation);
    }
示例#2
0
    public static async Task <Operation> PollUntilCompletedAsync(this Operation operation, string projectId, string zone)
    {
        ZoneOperationsClient operationsClient = await ZoneOperationsClient.CreateAsync();

        GetZoneOperationRequest pollRequest = new GetZoneOperationRequest
        {
            Operation = operation.Name,
            Zone      = zone,
            Project   = projectId,
        };

        async Task <Operation> Poller() => await operationsClient.GetAsync(pollRequest);

        return(await operation.PollUntilCompletedAsync(Poller));
    }
示例#3
0
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetZoneOperationRequest, CallSettings)
     // Create client
     ZoneOperationsClient zoneOperationsClient = ZoneOperationsClient.Create();
     // Initialize request argument(s)
     GetZoneOperationRequest request = new GetZoneOperationRequest
     {
         Zone      = "",
         Operation = "",
         Project   = "",
     };
     // Make the request
     Operation response = zoneOperationsClient.Get(request);
     // End snippet
 }
示例#4
0
        public async stt::Task GetAsync()
        {
            moq::Mock <ZoneOperations.ZoneOperationsClient> mockGrpcClient = new moq::Mock <ZoneOperations.ZoneOperationsClient>(moq::MockBehavior.Strict);
            GetZoneOperationRequest request = new GetZoneOperationRequest
            {
                Zone      = "zone255f4ea8",
                Operation = "operation615a23f7",
                Project   = "projectaa6ff846",
            };
            Operation expectedResponse = new Operation
            {
                Id   = 11672635353343658936UL,
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                User = "******",
                Zone = "zone255f4ea8",
                CreationTimestamp   = "creation_timestamp235e59a1",
                StartTime           = "start_timebd8dd9c4",
                OperationGroupId    = "operation_group_idd2040cf0",
                TargetLink          = "target_link9b435dc0",
                Progress            = 278622268,
                Error               = new Error(),
                EndTime             = "end_time89285d30",
                Region              = "regionedb20d96",
                OperationType       = "operation_typeece9e153",
                Status              = Operation.Types.Status.Pending,
                HttpErrorMessage    = "http_error_messageb5ef3c7f",
                TargetId            = 6263187990225347157UL,
                ClientOperationId   = "client_operation_id4e51b631",
                StatusMessage       = "status_message2c618f86",
                HttpErrorStatusCode = 1766362655,
                Description         = "description2cf9da67",
                InsertTime          = "insert_time7467185a",
                SelfLink            = "self_link7e87f12d",
                Warnings            = { new Warnings(), },
            };

            mockGrpcClient.Setup(x => x.GetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Operation>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            ZoneOperationsClient client = new ZoneOperationsClientImpl(mockGrpcClient.Object, null);
            Operation            responseCallSettings = await client.GetAsync(request.Project, request.Zone, request.Operation, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Operation responseCancellationToken = await client.GetAsync(request.Project, request.Zone, request.Operation, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public void Get()
        {
            moq::Mock <ZoneOperations.ZoneOperationsClient> mockGrpcClient = new moq::Mock <ZoneOperations.ZoneOperationsClient>(moq::MockBehavior.Strict);
            GetZoneOperationRequest request = new GetZoneOperationRequest
            {
                Zone      = "zone255f4ea8",
                Operation = "operation615a23f7",
                Project   = "projectaa6ff846",
            };
            Operation expectedResponse = new Operation
            {
                Id   = "id74b70bb8",
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                User = "******",
                Zone = "zone255f4ea8",
                CreationTimestamp   = "creation_timestamp235e59a1",
                StartTime           = "start_timebd8dd9c4",
                OperationGroupId    = "operation_group_idd2040cf0",
                TargetLink          = "target_link9b435dc0",
                Progress            = 278622268,
                Error               = new Error(),
                EndTime             = "end_time89285d30",
                Region              = "regionedb20d96",
                OperationType       = "operation_typeece9e153",
                Status              = Operation.Types.Status.Pending,
                HttpErrorMessage    = "http_error_messageb5ef3c7f",
                TargetId            = "target_id16dfe255",
                ClientOperationId   = "client_operation_id4e51b631",
                StatusMessage       = "status_message2c618f86",
                HttpErrorStatusCode = 1766362655,
                Description         = "description2cf9da67",
                InsertTime          = "insert_time7467185a",
                SelfLink            = "self_link7e87f12d",
                Warnings            = { new Warnings(), },
            };

            mockGrpcClient.Setup(x => x.Get(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ZoneOperationsClient client   = new ZoneOperationsClientImpl(mockGrpcClient.Object, null);
            Operation            response = client.Get(request.Project, request.Zone, request.Operation);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#6
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetZoneOperationRequest, CallSettings)
            // Additional: GetAsync(GetZoneOperationRequest, CancellationToken)
            // Create client
            ZoneOperationsClient zoneOperationsClient = await ZoneOperationsClient.CreateAsync();

            // Initialize request argument(s)
            GetZoneOperationRequest request = new GetZoneOperationRequest
            {
                Zone      = "",
                Operation = "",
                Project   = "",
            };
            // Make the request
            Operation response = await zoneOperationsClient.GetAsync(request);

            // End snippet
        }
示例#7
0
 private Func <Operation> CreatePoller(Operation operation)
 {
     if (operation.HasRegion && !operation.HasZone)
     {
         RegionOperationsClient    client  = RegionOperationsClient.Create();
         GetRegionOperationRequest request = new GetRegionOperationRequest
         {
             Operation = operation.Name,
             Region    = Region,
             Project   = ProjectId,
         };
         return(() => client.Get(request));
     }
     else if (operation.HasZone && !operation.HasRegion)
     {
         ZoneOperationsClient    client  = ZoneOperationsClient.Create();
         GetZoneOperationRequest request = new GetZoneOperationRequest
         {
             Operation = operation.Name,
             Zone      = Zone,
             Project   = ProjectId,
         };
         return(() => client.Get(request));
     }
     else if (!operation.HasZone && !operation.HasRegion)
     {
         GlobalOperationsClient    client  = GlobalOperationsClient.Create();
         GetGlobalOperationRequest request = new GetGlobalOperationRequest
         {
             Operation = operation.Name,
             Project   = ProjectId,
         };
         return(() => client.Get(request));
     }
     throw new ArgumentException($"Unable to determine operation type for {operation}");
 }
示例#8
0
 /// <summary>
 /// Retrieves the specified zone-specific Operations resource.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public override stt::Task <Operation> GetAsync(GetZoneOperationRequest request, gaxgrpc::CallSettings callSettings = null)
 {
     Modify_GetZoneOperationRequest(ref request, ref callSettings);
     return(_callGet.Async(request, callSettings));
 }
示例#9
0
 /// <summary>
 /// Retrieves the specified zone-specific Operations resource.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public override Operation Get(GetZoneOperationRequest request, gaxgrpc::CallSettings callSettings = null)
 {
     Modify_GetZoneOperationRequest(ref request, ref callSettings);
     return(_callGet.Sync(request, callSettings));
 }
示例#10
0
 partial void Modify_GetZoneOperationRequest(ref GetZoneOperationRequest request, ref gaxgrpc::CallSettings settings);
示例#11
0
 /// <summary>
 /// Retrieves the specified zone-specific Operations resource.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Operation> GetAsync(GetZoneOperationRequest request, st::CancellationToken cancellationToken) =>
 GetAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
示例#12
0
 /// <summary>
 /// Retrieves the specified zone-specific Operations resource.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Operation> GetAsync(GetZoneOperationRequest request, gaxgrpc::CallSettings callSettings = null) =>
 throw new sys::NotImplementedException();
示例#13
0
 /// <summary>
 /// Retrieves the specified zone-specific Operations resource.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public virtual Operation Get(GetZoneOperationRequest request, gaxgrpc::CallSettings callSettings = null) =>
 throw new sys::NotImplementedException();