Ejemplo n.º 1
0
 /// <summary>
 /// Sets the key value in etcd
 /// </summary>
 /// <param name="key">Key for which value need to be set</param>
 /// <param name="val">Value corresponding the key</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public PutResponse Put(string key, string val, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
                        CancellationToken cancellationToken = default)
 {
     return(Put(new PutRequest
     {
         Key = ByteString.CopyFromUtf8(key),
         Value = ByteString.CopyFromUtf8(val)
     }, headers, deadline, cancellationToken));
 }
Ejemplo n.º 2
0
        public async Task <Photo> UpdateAsync(Photo photo, string tokenValue)
        {
            Grpc.Core.Metadata headers = new Grpc.Core.Metadata();
            headers.Add("Authorization", $"Bearer {tokenValue}");

            UpdateReply p = await photosThingClient.UpdateAsync(photo.ToUpdateRequest(), headers);

            return(p.ToPhoto());
        }
Ejemplo n.º 3
0
        public async Task <Comment> UpdateAsync(Comment comment, string tokenValue)
        {
            Grpc.Core.Metadata headers = new Grpc.Core.Metadata();
            headers.Add("Authorization", $"Bearer {tokenValue}");

            UpdateReply c = await commentsThingClient.UpdateAsync(comment.ToUpdateRequest(), headers);

            return(c.ToComment());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the key value in etcd in async
 /// </summary>
 /// <param name="key">Key for which value need to be set</param>
 /// <param name="val">Value corresponding the key</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public async Task <PutResponse> PutAsync(string key, string val, Grpc.Core.Metadata headers = null,
                                          DateTime?deadline = null,
                                          CancellationToken cancellationToken = default)
 {
     return(await PutAsync(new PutRequest
     {
         Key = ByteString.CopyFromUtf8(key),
         Value = ByteString.CopyFromUtf8(val)
     }, headers, deadline, cancellationToken).ConfigureAwait(false));
 }
        protected Grpc.Core.Metadata GetRequestMetadata()
        {
            var metadata = new Grpc.Core.Metadata();
            var routeAs  = _httpContextAccessor.HttpContext.Request.Headers["azds-route-as"].ToString();

            if (!string.IsNullOrEmpty(routeAs))
            {
                metadata.Add("azds-route-as", routeAs);
            }
            return(metadata);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the range of keys with the specified prefix
        /// </summary>
        /// <param name="prefixKey">Prefix key</param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>RangeResponse containing range of key-values</returns>
        public RangeResponse GetRange(string prefixKey, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
                                      CancellationToken cancellationToken          = default)
        {
            string rangeEnd = GetRangeEnd(prefixKey);

            return(Get(new RangeRequest
            {
                Key = GetStringByteForRangeRequests(prefixKey),
                RangeEnd = ByteString.CopyFromUtf8(rangeEnd),
            }, headers, deadline, cancellationToken));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the range of keys with the specified prefix in async
        /// </summary>
        /// <param name="prefixKey">Prefix key</param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>RangeResponse containing range of key-values</returns>
        public async Task <RangeResponse> GetRangeAsync(string prefixKey, Grpc.Core.Metadata headers = null,
                                                        DateTime?deadline = null,
                                                        CancellationToken cancellationToken = default)
        {
            string rangeEnd = GetRangeEnd(prefixKey);

            return(await GetAsync(new RangeRequest
            {
                Key = GetStringByteForRangeRequests(prefixKey),
                RangeEnd = ByteString.CopyFromUtf8(rangeEnd)
            }, headers, deadline, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the range of keys with the specified prefix in async
        /// </summary>
        /// <param name="prefixKey">Prefix key</param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>Dictionary containing range of key-values</returns>
        public async Task <IDictionary <string, string> > GetRangeValAsync(string prefixKey,
                                                                           Grpc.Core.Metadata headers          = null, DateTime?deadline = null,
                                                                           CancellationToken cancellationToken = default)
        {
            string rangeEnd = GetRangeEnd(prefixKey);

            return(RangeRespondToDictionary(await GetAsync(new RangeRequest
            {
                Key = GetStringByteForRangeRequests(prefixKey),
                RangeEnd = ByteString.CopyFromUtf8(rangeEnd)
            }, headers, deadline, cancellationToken)));
        }
Ejemplo n.º 9
0
        public async Task <Comment> RemoveAsync(int id, string tokenValue)
        {
            Grpc.Core.Metadata headers = new Grpc.Core.Metadata();
            headers.Add("Authorization", $"Bearer {tokenValue}");

            RemoveReply c = await commentsThingClient.RemoveAsync(new RemoveRequest()
            {
                Id = id
            }, headers);

            return(c.ToComment());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Deletes all keys with the specified prefix in async
        /// </summary>
        /// <param name="prefixKey">Commin prefix of all keys that need to be deleted</param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>The response received from the server.</returns>
        public async Task <DeleteRangeResponse> DeleteRangeAsync(string prefixKey, Grpc.Core.Metadata headers = null,
                                                                 DateTime?deadline = null,
                                                                 CancellationToken cancellationToken = default)
        {
            string rangeEnd = GetRangeEnd(prefixKey);

            return(await DeleteAsync(new DeleteRangeRequest
            {
                Key = ByteString.CopyFromUtf8(prefixKey),
                RangeEnd = ByteString.CopyFromUtf8(rangeEnd)
            }, headers, deadline, cancellationToken));
        }
Ejemplo n.º 11
0
        public async Task <UserPagedOutput> GetUserPaged(int paged = 1, int rows = 20)
        {
            var _header = new Grpc.Core.Metadata()
            {
                { "Authorization", $"{HttpContext.Request.Headers["Authorization"]}" }
            };
            var userServiceClient = await grpcServiceHelper.GetUserService();

            return(await userServiceClient.GetUserListAsync(new GetUserPagedForm()
            {
                Paged = paged,
                Rows = rows
            }, _header));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Snapshot sends a snapshot of the entire backend from a member over a stream to a client.
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="method"></param>
 /// <param name="cancellationToken"></param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 public async Task Snapshot(SnapshotRequest request, Action <SnapshotResponse> method,
                            CancellationToken cancellationToken, Grpc.Core.Metadata headers = null, DateTime?deadline = null)
 {
     await CallEtcdAsync(async (connection) =>
     {
         using (AsyncServerStreamingCall <SnapshotResponse> snapshotter = connection
                                                                          .maintenanceClient.Snapshot(request, headers, deadline, cancellationToken))
         {
             while (await snapshotter.ResponseStream.MoveNext(cancellationToken))
             {
                 SnapshotResponse update = snapshotter.ResponseStream.Current;
                 method(update);
             }
         }
     });
 }
Ejemplo n.º 13
0
        // Additional configuration is required to successfully run gRPC on macOS.
        // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
        public static IHostBuilder CreateHostBuilder(string[] args, K2Config config)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                .UseKestrel(options =>
                {
                    options.ListenAnyIP(config.ListeningPort);
                })
                .ConfigureServices(sc =>
                {
                    var backendHeader = new Grpc.Core.Metadata();
                    backendHeader.Add(nameof(config.BackendGroupId), config.BackendGroupId);         // key 는 소문자로 변환되어 들어간다

                    // K2Config 종속적인 resource 들 ; asp.net core 3.0 이후 직접 StartUp 에 parameter 를 전달할 수 없음 (https://andrewlock.net/avoiding-startup-service-injection-in-asp-net-core-3/)
                    sc.AddSingleton(config);
                    sc.AddSingleton(backendHeader);
                })
                .UseStartup <Startup>()
                ;
            }));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client
        /// to the server and streaming keep alive responses from the server to the client.
        /// </summary>
        /// <param name="request">The request to send to the server.</param>
        /// <param name="method"></param>
        /// <param name="cancellationToken"></param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        public async Task LeaseKeepAlive(LeaseKeepAliveRequest request, Action<LeaseKeepAliveResponse> method,
            CancellationToken cancellationToken, Grpc.Core.Metadata headers = null)
        {
            await CallEtcdAsync(async (connection) =>
            {
                using (AsyncDuplexStreamingCall<LeaseKeepAliveRequest, LeaseKeepAliveResponse> leaser =
                    connection.leaseClient
                        .LeaseKeepAlive(headers, cancellationToken: cancellationToken))
                {
                    Task leaserTask = Task.Run(async () =>
                    {
                        while (await leaser.ResponseStream.MoveNext(cancellationToken))
                        {
                            LeaseKeepAliveResponse update = leaser.ResponseStream.Current;
                            method(update);
                        }
                    }, cancellationToken);

                    await leaser.RequestStream.WriteAsync(request);
                    await leaser.RequestStream.CompleteAsync();
                    await leaserTask;
                }
            });
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Compact compacts the event history in the etcd key-value store. The key-value
 /// store should be periodically compacted or the event history will continue to grow
 /// indefinitely.
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public CompactionResponse Compact(CompactionRequest request, Grpc.Core.Metadata headers = null,
                                   DateTime?deadline = null,
                                   CancellationToken cancellationToken = default) => CallEtcd((connection) => connection._kvClient
                                                                                              .Compact(request, headers, deadline, cancellationToken));
Ejemplo n.º 16
0
 /// <summary>
 /// UserChangePasswordAsync changes the password of a specified user in async
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public async Task <AuthUserChangePasswordResponse> UserChangePasswordAsync(AuthUserChangePasswordRequest request,
                                                                            Grpc.Core.Metadata headers          = null, DateTime?deadline = null,
                                                                            CancellationToken cancellationToken = default) => await CallEtcdAsync(async (connection) => await connection._authClient
                                                                                                                                                  .UserChangePasswordAsync(request, headers, deadline, cancellationToken)).ConfigureAwait(false);
Ejemplo n.º 17
0
 /// <summary>
 /// Unlock takes a key returned by Lock and releases the hold on lock. The
 /// next Lock caller waiting for the lock will then be woken up and given
 /// ownership of the lock.
 /// </summary>
 /// <param name="request">The request to send to the server</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public UnlockResponse Unlock(UnlockRequest request, Grpc.Core.Metadata headers = null,
                              DateTime?deadline = null, CancellationToken cancellationToken = default)
 {
     return(CallEtcd((connection) => connection.lockClient
                     .Unlock(request, headers, deadline, cancellationToken)));
 }
        private async void UploadFile(string fileName)
        {
            var md5             = Helper.GetMD5HashFromFile(fileName);
            var checkFileResult = client.CheckFileExist(new CheckFileExistRequest()
            {
                Md5 = md5
            });

            if (!checkFileResult.Result)
            {
                if (checkFileResult.ErrorCode != ErrorCodes.NoError)
                {
                    Console.WriteLine($"check file:{fileName} error,error code:{checkFileResult.ErrorCode}");
                    return;
                }
                CancellationTokenSource tokenSource = new CancellationTokenSource()
                {
                };
                var header = new Grpc.Core.Metadata();
                header.Add(Const.MD5_KEY, md5);
                var call   = client.UploadWithStream(cancellationToken: tokenSource.Token, headers: header);
                var result = await call.ResponseStream.MoveNext(tokenSource.Token);

                if (!call.ResponseStream.Current.Result)
                {
                    return;
                }

                int  size             = 102400;
                long totalLenth       = new FileInfo(fileName).Length;
                long hasUploadedLenth = 0;

                using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    while (hasUploadedLenth < totalLenth)
                    {
                        byte[] bytes = new byte[size];
                        var    count = fs.Read(bytes, 0, size);
                        if (count > 0)
                        {
                            var bytesToSend = new byte[count];
                            Array.Copy(bytes, 0, bytesToSend, 0, count);

                            await call.RequestStream.WriteAsync(new UploadWithStreamRequest()
                            {
                                Data = Google.Protobuf.ByteString.CopyFrom(bytesToSend)
                            });

                            if (await call.ResponseStream.MoveNext(tokenSource.Token))
                            {
                                var response = call.ResponseStream.Current;

                                if (!response.Result)
                                {
                                    Console.WriteLine("传输失败:" + response.ErrorCode);
                                    break;
                                }
                            }
                            hasUploadedLenth += count;
                        }
                    }
                }

                await call.RequestStream.CompleteAsync();

                if (hasUploadedLenth == totalLenth)
                {
                    client.FinishUpload(new FinishUploadRequest()
                    {
                        ClientFileName = fileName,
                        IsFastUpload   = false,
                        Md5            = md5,
                        RecognizeId    = 123456789,
                    });
                }
            }
            else
            {
                client.FinishUpload(new FinishUploadRequest()
                {
                    ClientFileName = fileName + "test",
                    IsFastUpload   = true,
                    Md5            = md5,
                    RecognizeId    = 123456789,
                });
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// RoleRevokePermission revokes a key or range permission of a specified role
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public AuthRoleRevokePermissionResponse RoleRevokePermission(AuthRoleRevokePermissionRequest request,
                                                              Grpc.Core.Metadata headers          = null, DateTime?deadline = null,
                                                              CancellationToken cancellationToken = default) => CallEtcd((connection) => connection._authClient
                                                                                                                         .RoleRevokePermission(request, headers, deadline, cancellationToken));
Ejemplo n.º 20
0
 /// <summary>
 /// UserAdd adds a new user
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public AuthUserAddResponse UserAdd(AuthUserAddRequest request, Grpc.Core.Metadata headers = null,
                                    DateTime?deadline = null,
                                    CancellationToken cancellationToken = default) => CallEtcd((connection) => connection._authClient
                                                                                               .UserAdd(request, headers, deadline, cancellationToken));
Ejemplo n.º 21
0
 /// <summary>
 /// RoleRevokePermissionAsync revokes a key or range permission of a specified role in async
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public async Task <AuthRoleRevokePermissionResponse> RoleRevokePermissionAsync(
     AuthRoleRevokePermissionRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
     CancellationToken cancellationToken = default) => await CallEtcdAsync(async (connection) => await connection._authClient
                                                                           .RoleRevokePermissionAsync(request, headers, deadline, cancellationToken)).ConfigureAwait(false);
Ejemplo n.º 22
0
 /// <summary>
 /// Sets the key value in etcd
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public PutResponse Put(PutRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
                        CancellationToken cancellationToken            = default)
 {
     return(CallEtcd((connection) => connection._kvClient.Put(request, headers, deadline, cancellationToken)));
 }
Ejemplo n.º 23
0
 /// <summary>
 ///  Alarm activates, deactivates, and queries alarms regarding cluster health
 /// </summary>
 /// <param name="request">Alarm request</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>Alarm Response</returns>
 public AlarmResponse Alarm(AlarmRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
                            CancellationToken cancellationToken = default)
 {
     return(CallEtcd((connection) => connection.maintenanceClient
                     .Alarm(request, headers, deadline, cancellationToken)));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Delete the specified key in etcd
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public DeleteRangeResponse Delete(DeleteRangeRequest request, Grpc.Core.Metadata headers = null,
                                   DateTime?deadline = null,
                                   CancellationToken cancellationToken = default) => CallEtcd((connection) => connection._kvClient
                                                                                              .DeleteRange(request, headers, deadline, cancellationToken));
Ejemplo n.º 25
0
 /// <summary>
 /// Get the etcd response for a specified key
 /// </summary>
 /// <param name="key">Key for which value need to be fetched</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The etcd response for the specified key</returns>
 public RangeResponse Get(string key, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
                          CancellationToken cancellationToken    = default) => Get(new RangeRequest
 {
     Key = ByteString.CopyFromUtf8(key)
 }, headers, deadline, cancellationToken);
Ejemplo n.º 26
0
 /// <summary>
 ///  Txn processes multiple requests in a single transaction.
 /// A txn request increments the revision of the key-value store
 /// and generates events with the same revision for every completed request.
 /// It is not allowed to modify the same key several times within one txn.
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public TxnResponse Transaction(TxnRequest request, Grpc.Core.Metadata headers = null, DateTime?deadline = null,
                                CancellationToken cancellationToken            = default)
 {
     return(CallEtcd((connection) => connection.kvClient.Txn(request, headers, deadline, cancellationToken)));
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Compact compacts the event history in the etcd key-value store in async. The key-value
 /// store should be periodically compacted or the event history will continue to grow
 /// indefinitely.
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public async Task <CompactionResponse> CompactAsync(CompactionRequest request, Grpc.Core.Metadata headers = null,
                                                     DateTime?deadline = null,
                                                     CancellationToken cancellationToken = default)
 {
     return(await CallEtcdAsync(async (connection) => await connection.kvClient
                                .CompactAsync(request, headers, deadline, cancellationToken)));
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Get the etcd response for a specified key in async
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The etcd response for the specified request</returns>
 public async Task <RangeResponse> GetAsync(RangeRequest request, Grpc.Core.Metadata headers = null,
                                            DateTime?deadline = null,
                                            CancellationToken cancellationToken = default) => await CallEtcdAsync(async (connection) => await connection._kvClient
                                                                                                                  .RangeAsync(request, headers, deadline, cancellationToken)).ConfigureAwait(false);
Ejemplo n.º 29
0
 /// <summary>
 /// MemberAddAsync adds a member into the cluster in async
 /// </summary>
 /// <param name="request">The request to send to the server.</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The response received from the server.</returns>
 public async Task <MemberAddResponse> MemberAddAsync(MemberAddRequest request, Grpc.Core.Metadata headers = null,
                                                      DateTime?deadline = null,
                                                      CancellationToken cancellationToken = default)
 {
     return(await CallEtcdAsync(async (connection) => await connection.clusterClient
                                .MemberAddAsync(request, headers, deadline, cancellationToken)));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Get the etcd response for a specified key in async
 /// </summary>
 /// <param name="key">Key for which value need to be fetched</param>
 /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
 /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
 /// <param name="cancellationToken">An optional token for canceling the call.</param>
 /// <returns>The etcd response for the specified key</returns>
 public async Task <RangeResponse> GetAsync(string key, Grpc.Core.Metadata headers = null,
                                            DateTime?deadline = null,
                                            CancellationToken cancellationToken = default) => await GetAsync(new RangeRequest
 {
     Key = ByteString.CopyFromUtf8(key)
 }, headers, deadline, cancellationToken).ConfigureAwait(false);