List <Key> allocateIds(DatastoreService datasstore, List <Key> keys, string projectId) { var alloc = new AllocateIdsRequest() { Keys = keys }; var worker = datasstore.Projects.AllocateIds(alloc, projectId); var res = worker.Execute(); return(keys); }
public void AllocateIds_RequestObject() { // Snippet: AllocateIds(AllocateIdsRequest,CallSettings) // Create client DatastoreClient datastoreClient = DatastoreClient.Create(); // Initialize request argument(s) AllocateIdsRequest request = new AllocateIdsRequest { ProjectId = "", Keys = { }, }; // Make the request AllocateIdsResponse response = datastoreClient.AllocateIds(request); // End snippet }
/// <summary> /// Allocate IDs for the given keys (useful for referencing an entity before /// it is inserted). /// </summary> /// <param name="project_id">Project ID against which to make the request.</param> /// <param name="keys"> /// A list of keys with incomplete key paths for which to allocate IDs. /// No key may be reserved/read-only. /// </param> /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> /// <returns>The RPC response.</returns> public override AllocateIdsResponse AllocateIds( string projectId, IEnumerable <Key> keys, CallSettings callSettings = null) { AllocateIdsRequest request = new AllocateIdsRequest { ProjectId = projectId, Keys = { keys }, }; return(GrpcClient.AllocateIds( request, _clientHelper.BuildCallOptions(null, callSettings))); }
public async Task AllocateIdsAsync_RequestObject() { // Snippet: AllocateIdsAsync(AllocateIdsRequest,CallSettings) // Create client DatastoreClient datastoreClient = await DatastoreClient.CreateAsync(); // Initialize request argument(s) AllocateIdsRequest request = new AllocateIdsRequest { ProjectId = "", Keys = { }, }; // Make the request AllocateIdsResponse response = await datastoreClient.AllocateIdsAsync(request); // End snippet }
/// <summary> /// Allocate IDs for the given keys (useful for referencing an entity before /// it is inserted). /// </summary> /// <param name="project_id">Project ID against which to make the request.</param> /// <param name="keys"> /// A list of keys with incomplete key paths for which to allocate IDs. /// No key may be reserved/read-only. /// </param> /// <param name="cancellationToken">If not null, a <see cref="CancellationToken"/> to use for this RPC.</param> /// <param name="callSettings">If not null, applies overrides to this RPC call.</param> /// <returns>A Task containing the RPC response.</returns> public override Task <AllocateIdsResponse> AllocateIdsAsync( string projectId, IEnumerable <Key> keys, CancellationToken?cancellationToken = null, CallSettings callSettings = null) { AllocateIdsRequest request = new AllocateIdsRequest { ProjectId = projectId, Keys = { keys }, }; return(GrpcClient.AllocateIdsAsync( request, _clientHelper.BuildCallOptions(cancellationToken, callSettings) ).ResponseAsync); }
public async Task AllocateIdsAsync2() { Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict); AllocateIdsRequest request = new AllocateIdsRequest { ProjectId = "projectId-1969970175", Keys = { }, }; AllocateIdsResponse expectedResponse = new AllocateIdsResponse(); mockGrpcClient.Setup(x => x.AllocateIdsAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <AllocateIdsResponse>(Task.FromResult(expectedResponse), null, null, null, null)); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); AllocateIdsResponse response = await client.AllocateIdsAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void AllocateIds2() { Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict); AllocateIdsRequest request = new AllocateIdsRequest { ProjectId = "projectId-1969970175", Keys = { }, }; AllocateIdsResponse expectedResponse = new AllocateIdsResponse(); mockGrpcClient.Setup(x => x.AllocateIds(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); AllocateIdsResponse response = client.AllocateIds(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for AllocateIdsAsync</summary> public async Task AllocateIdsRequestObjectAsync() { // Snippet: AllocateIdsAsync(AllocateIdsRequest, CallSettings) // Additional: AllocateIdsAsync(AllocateIdsRequest, CancellationToken) // Create client DatastoreClient datastoreClient = await DatastoreClient.CreateAsync(); // Initialize request argument(s) AllocateIdsRequest request = new AllocateIdsRequest { Keys = { new Key(), }, ProjectId = "", }; // Make the request AllocateIdsResponse response = await datastoreClient.AllocateIdsAsync(request); // End snippet }
public void AllocateIds() { moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict); AllocateIdsRequest request = new AllocateIdsRequest { Keys = { new Key(), }, ProjectId = "project_id43ad98b0", }; AllocateIdsResponse expectedResponse = new AllocateIdsResponse { Keys = { new Key(), }, }; mockGrpcClient.Setup(x => x.AllocateIds(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); AllocateIdsResponse response = client.AllocateIds(request.ProjectId, request.Keys); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task AllocateIdsAsync() { moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict); AllocateIdsRequest request = new AllocateIdsRequest { Keys = { new Key(), }, ProjectId = "project_id43ad98b0", }; AllocateIdsResponse expectedResponse = new AllocateIdsResponse { Keys = { new Key(), }, }; mockGrpcClient.Setup(x => x.AllocateIdsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AllocateIdsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); AllocateIdsResponse responseCallSettings = await client.AllocateIdsAsync(request.ProjectId, request.Keys, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); AllocateIdsResponse responseCancellationToken = await client.AllocateIdsAsync(request.ProjectId, request.Keys, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
/// Documentation https://developers.google.com/datastore/v1beta3/reference/projects/allocateIds /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated datastore service.</param> /// <param name="projectId">The ID of the project against which to make the request.</param> /// <param name="body">A valid datastore v1beta3 body.</param> /// <returns>AllocateIdsResponseResponse</returns> public static AllocateIdsResponse AllocateIds(datastoreService service, string projectId, AllocateIdsRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (projectId == null) { throw new ArgumentNullException(projectId); } // Make the request. return(service.Projects.AllocateIds(body, projectId).Execute()); } catch (Exception ex) { throw new Exception("Request Projects.AllocateIds failed.", ex); } }
partial void Modify_AllocateIdsRequest(ref AllocateIdsRequest request, ref CallSettings settings) { settings = settings.WithHeader(ResourcePrefixHeader, "projects/" + request.ProjectId); }