Exemplo n.º 1
0
            public static object UpsertResponse(string keyPath, string value, string previousValue = null)
            {
                var hasPreviousValue = !string.IsNullOrWhiteSpace(previousValue);
                var modifiedIndex = Fixture.Create<long>();
                var createdIndex = hasPreviousValue ? modifiedIndex - 10 : modifiedIndex;

                var nodeValues = new FormBodyBuilder()
                    .Add("createdIndex", createdIndex)
                    .Add("key", keyPath)
                    .Add("modifiedIndex", modifiedIndex)
                    .Add("value", value)
                    .Build();

                var response = new FormBodyBuilder()
                    .Add("action", "set")
                    .Add("node", nodeValues)
                    .Build();

                if (hasPreviousValue)
                {
                    response["prevNode"] = new FormBodyBuilder()
                        .Add("createdIndex", createdIndex)
                        .Add("key", keyPath)
                        .Add("modifiedIndex", createdIndex)
                        .Add("value", previousValue)
                        .Build();
                }

                return response;
            }
Exemplo n.º 2
0
            public static object UpsertResponse(string keyPath, string value, string previousValue = null)
            {
                var hasPreviousValue = !string.IsNullOrWhiteSpace(previousValue);
                var modifiedIndex    = Fixture.Create <long>();
                var createdIndex     = hasPreviousValue ? modifiedIndex - 10 : modifiedIndex;

                var nodeValues = new FormBodyBuilder()
                                 .Add("createdIndex", createdIndex)
                                 .Add("key", keyPath)
                                 .Add("modifiedIndex", modifiedIndex)
                                 .Add("value", value)
                                 .Build();

                var response = new FormBodyBuilder()
                               .Add("action", "set")
                               .Add("node", nodeValues)
                               .Build();

                if (hasPreviousValue)
                {
                    response["prevNode"] = new FormBodyBuilder()
                                           .Add("createdIndex", createdIndex)
                                           .Add("key", keyPath)
                                           .Add("modifiedIndex", createdIndex)
                                           .Add("value", previousValue)
                                           .Build();
                }

                return(response);
            }
        public async Task<IClusterMember> Execute()
        {
            var values = new FormBodyBuilder()
                .Add(Constants.Etcd.Parameter_PeerURLs, Uris.Select(x => x.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)).ToArray())
                .Build();

            try
            {
                return await TargetUrl
                    .AppendPathSegment(MemberId)
                    .PutJsonAsync(values)
                    .ReceiveJson<ClusterMember>();
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 4
0
        public async Task<IClusterMember> Execute()
        {
            var values = new FormBodyBuilder()
                .Add(Constants.Etcd.Parameter_Name, Name)
                .Add(Constants.Etcd.Parameter_PeerURLs, Uris.ToArray())
                .Build();

            try
            {
                return await TargetUrl
                    .PostJsonAsync(values)
                    .ReceiveJson<ClusterMember>();
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 5
0
        public async Task <IClusterMember> Execute()
        {
            var values = new FormBodyBuilder()
                         .Add(Constants.Etcd.Parameter_Name, Name)
                         .Add(Constants.Etcd.Parameter_PeerURLs, Uris.Select(x => x.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)).ToArray())
                         .Build();

            try
            {
                return(await TargetUrl
                       .PostJsonAsync(values)
                       .ReceiveJson <ClusterMember>());
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 6
0
        private async Task <IKeyEvent> Execute(bool isByValue)
        {
            var values = new FormBodyBuilder()
                         .Add(Constants.Etcd.Parameter_Value, Value)
                         // ReSharper disable once PossibleInvalidOperationException
                         .Add(Ttl.HasValue, Constants.Etcd.Parameter_Ttl, () => Ttl.Value)
                         .Build();

            try
            {
                return(await TargetUrl
                       .Conditionally(isByValue, x => x.SetQueryParam(Constants.Etcd.Parameter_PrevValue, ExpectedValue))
                       .Conditionally(!isByValue, x => x.SetQueryParam(Constants.Etcd.Parameter_PrevIndex, ExpectedIndex))
                       .SendUrlEncodedAsync(HttpMethod.Put, values)
                       .ReceiveEtcdResponse <KeyEvent>(EtcdClient));
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 7
0
        public async Task<IKeyEvent> Execute()
        {
            var values = new FormBodyBuilder()
                .Add(
                    IsDirectory ? Constants.Etcd.Parameter_Directory : Constants.Etcd.Parameter_Value,
                    IsDirectory ? Constants.Etcd.Parameter_True : Value
                )
                // ReSharper disable once PossibleInvalidOperationException
                .Add(Existing.HasValue, Constants.Etcd.Parameter_PrevExist, () => Existing.Value ? Constants.Etcd.Parameter_True : Constants.Etcd.Parameter_False)
                // ReSharper disable once PossibleInvalidOperationException
                .Add(Ttl.HasValue, Constants.Etcd.Parameter_Ttl, () => Ttl.Value)
                .Build();

            try
            {
                return await TargetUrl
                    .Conditionally(IsQueue, values, (x, v) => x.PostUrlEncodedAsync(v), (x, v) => x.PutUrlEncodedAsync(v))
                    .ReceiveEtcdResponse<KeyEvent>(EtcdClient);
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 8
0
        public async Task <IKeyEvent> Execute()
        {
            var values = new FormBodyBuilder()
                         .Add(
                IsDirectory ? Constants.Etcd.Parameter_Directory : Constants.Etcd.Parameter_Value,
                IsDirectory ? Constants.Etcd.Parameter_True : Value
                )
                         // ReSharper disable once PossibleInvalidOperationException
                         .Add(Existing.HasValue, Constants.Etcd.Parameter_PrevExist, () => Existing.Value ? Constants.Etcd.Parameter_True : Constants.Etcd.Parameter_False)
                         // ReSharper disable once PossibleInvalidOperationException
                         .Add(Ttl.HasValue, Constants.Etcd.Parameter_Ttl, () => Ttl.Value)
                         .Build();

            try
            {
                return(await TargetUrl
                       .Conditionally(IsQueue, values, (x, v) => x.PostUrlEncodedAsync(v), (x, v) => x.SendUrlEncodedAsync(HttpMethod.Put, v))
                       .ReceiveEtcdResponse <KeyEvent>(EtcdClient));
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 9
0
        private async Task<IKeyEvent> Execute(bool isByValue)
        {
            var values = new FormBodyBuilder()
                .Add(Constants.Etcd.Parameter_Value, Value)
                // ReSharper disable once PossibleInvalidOperationException
                .Add(Ttl.HasValue, Constants.Etcd.Parameter_Ttl, () => Ttl.Value)
                .Build();

            try
            {
                return await TargetUrl
                    .Conditionally(isByValue, x => x.SetQueryParam(Constants.Etcd.Parameter_PrevValue, ExpectedValue))
                    .Conditionally(!isByValue, x => x.SetQueryParam(Constants.Etcd.Parameter_PrevIndex, ExpectedIndex))
                    .PutUrlEncodedAsync(values)
                    .ReceiveEtcdResponse<KeyEvent>(EtcdClient);
            }
            catch (FlurlHttpException e)
            {
                throw e.ProcessException();
            }
        }
Exemplo n.º 10
0
 public static string AsRequestBody(this FormBodyBuilder This)
 {
     return(This.Build().AsRequestBody());
 }