Example #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;
            }
Example #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();
            }
        }
        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();
            }
        }
Example #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();
            }
        }
Example #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();
            }
        }
Example #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();
            }
        }
Example #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();
            }
        }
        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();
            }
        }
Example #10
0
 public static string AsRequestBody(this FormBodyBuilder This)
 {
     return(This.Build().AsRequestBody());
 }