Пример #1
0
        public RiakBucketProperties RemovePostCommitHook(IRiakPostCommitHook commitHook)
        {
            if (PostCommitHooks != null)
            {
                PostCommitHooks.RemoveAll(x => Equals(x, commitHook));
            }

            return(this);
        }
        /// <summary>
        /// Remove a post-commit hook from the bucket properties.
        /// </summary>
        /// <param name="commitHook">The <see cref="IRiakPreCommitHook"/> to remove.</param>
        /// <returns>A reference to the current properties object.</returns>
        /// <remarks>
        /// Pre/Post-commit hooks are not typically modified.
        /// </remarks>
        public RiakBucketProperties RemovePostCommitHook(IRiakPostCommitHook commitHook)
        {
            if (PostCommitHooks != null)
            {
                PostCommitHooks.RemoveAll(x => Equals(x, commitHook));

                if (PostCommitHooks.Count == 0)
                {
                    HasPostcommit = false;
                }
            }

            return(this);
        }
        internal string ToJsonString()
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                using (JsonWriter jw = new JsonTextWriter(sw))
                {
                    jw.WriteStartObject();
                    jw.WritePropertyName("props");
                    jw.WriteStartObject();
                    jw.WriteNullableProperty("n_val", NVal)
                    .WriteNullableProperty("allow_mult", AllowMultiple)
                    .WriteNullableProperty("last_write_wins", LastWriteWins)
                    .WriteNullableProperty("r", RVal)
                    .WriteNullableProperty("rw", RwVal)
                    .WriteNullableProperty("dw", DwVal)
                    .WriteNullableProperty("w", WVal)
                    .WriteNullableProperty("pr", PrVal)
                    .WriteNullableProperty("pw", PwVal)
                    .WriteNonNullProperty("backend", Backend)
                    .WriteNullableProperty("notfound_ok", NotFoundOk)
                    .WriteNullableProperty("basic_quorum", BasicQuorum)
                    .WriteNullableProperty("has_precommit", HasPrecommit)
                    .WriteNullableProperty("has_postcommit", HasPostcommit);

                    if (PreCommitHooks != null)
                    {
                        jw.WritePropertyName("precommit");
                        jw.WriteStartArray();
                        PreCommitHooks.ForEach(hook => hook.WriteJson(jw));
                        jw.WriteEndArray();
                    }

                    if (PostCommitHooks != null)
                    {
                        jw.WritePropertyName("postcommit");
                        jw.WriteStartArray();
                        PostCommitHooks.ForEach(hook => hook.WriteJson(jw));
                        jw.WriteEndArray();
                    }

                    jw.WriteEndObject();
                    jw.WriteEndObject();
                }

            return(sb.ToString());
        }
        internal RpbBucketProps ToMessage()
        {
            var message = new RpbBucketProps();

            message.allow_multSpecified = false;
            if (AllowMultiple.HasValue)
            {
                message.allow_mult = AllowMultiple.Value;
            }

            message.n_valSpecified = false;
            if (NVal != null)
            {
                message.n_val = NVal;
            }

            message.last_write_winsSpecified = false;
            if (LastWriteWins.HasValue)
            {
                message.last_write_wins = LastWriteWins.Value;
            }

            message.rSpecified = false;
            if (R != null)
            {
                message.r = R;
            }

            message.rwSpecified = false;
            if (Rw != null)
            {
                message.rw = Rw;
            }

            message.dwSpecified = false;
            if (Dw != null)
            {
                message.dw = Dw;
            }

            message.wSpecified = false;
            if (W != null)
            {
                message.w = W;
            }

            message.prSpecified = false;
            if (Pr != null)
            {
                message.pr = Pr;
            }

            message.pwSpecified = false;
            if (Pw != null)
            {
                message.pw = Pw;
            }

            message.searchSpecified = false;
            if (LegacySearch.HasValue)
            {
                message.search = LegacySearch.Value;
            }

            message.has_precommitSpecified = false;
            if (HasPrecommit.HasValue)
            {
                message.has_precommit = HasPrecommit.Value;
            }

            // Due to the amusing differences between 1.3 and 1.4 we've added
            // this elegant shim to figure out if we should add commit hooks,
            // remove them, or just wander around setting the Search boolean.
            if (addHooks.HasValue)
            {
                if (addHooks.Value)
                {
                    AddPreCommitHook(RiakErlangCommitHook.RiakLegacySearchCommitHook);
                }
                else
                {
                    RemovePreCommitHook(RiakErlangCommitHook.RiakLegacySearchCommitHook);
                }
            }

            if (PreCommitHooks != null)
            {
                PreCommitHooks.ForEach(h =>
                {
                    var hook = h.ToRpbCommitHook();
                    if (!message.precommit.Any(x => Equals(x, hook)))
                    {
                        message.precommit.Add(hook);
                    }
                });
            }

            message.has_postcommitSpecified = false;
            if (HasPostcommit.HasValue)
            {
                message.has_postcommit = HasPostcommit.Value;
            }

            if (PostCommitHooks != null)
            {
                PostCommitHooks.ForEach(h =>
                {
                    var hook = h.ToRpbCommitHook();
                    if (!message.postcommit.Any(x => Equals(x, hook)))
                    {
                        message.postcommit.Add(hook);
                    }
                });
            }

            message.search_indexSpecified = false;
            if (!string.IsNullOrEmpty(SearchIndex))
            {
                message.search_index = SearchIndex.ToRiakString();
            }

            if (HllPrecision.HasValue)
            {
                message.hll_precision = (uint)HllPrecision;
            }

            return(message);
        }
        internal RpbBucketProps ToMessage()
        {
            var message = new RpbBucketProps();

            if (AllowMultiple.HasValue)
            {
                message.allow_mult = AllowMultiple.Value;
            }

            if (NVal.HasValue)
            {
                message.n_val = NVal.Value;
            }

            if (LastWriteWins.HasValue)
            {
                message.last_write_wins = LastWriteWins.Value;
            }

            if (RVal.HasValue)
            {
                message.r = RVal.Value;
            }

            if (RwVal.HasValue)
            {
                message.rw = RwVal.Value;
            }

            if (DwVal.HasValue)
            {
                message.dw = DwVal.Value;
            }

            if (WVal.HasValue)
            {
                message.w = WVal.Value;
            }

            if (PrVal.HasValue)
            {
                message.pr = PrVal.Value;
            }

            if (PwVal.HasValue)
            {
                message.pw = PwVal.Value;
            }

            if (Search.HasValue)
            {
                message.search = Search.Value;
            }

            if (HasPrecommit.HasValue)
            {
                message.has_precommit = HasPrecommit.Value;
            }

            // Due to the amusing differences between 1.3 and 1.4 we've added
            // this elegant shim to figure out if we should add commit hooks,
            // remove them, or just wander around setting the Search boolean.
            if (_addHooks.HasValue)
            {
                if (_addHooks.Value)
                {
                    AddPreCommitHook(RiakErlangCommitHook.RiakSearchCommitHook);
                }
                else
                {
                    RemovePreCommitHook(RiakErlangCommitHook.RiakSearchCommitHook);
                }
            }

            if (PreCommitHooks != null)
            {
                PreCommitHooks.ForEach(h =>
                {
                    var hook = h.ToRpbCommitHook();
                    if (!message.precommit.Any(x => Equals(x, hook)))
                    {
                        message.precommit.Add(hook);
                    }
                });
            }

            if (HasPostcommit.HasValue)
            {
                message.has_postcommit = HasPostcommit.Value;
            }

            if (PostCommitHooks != null)
            {
                PostCommitHooks.ForEach(h =>
                {
                    var hook = h.ToRpbCommitHook();
                    if (!message.postcommit.Any(x => Equals(x, hook)))
                    {
                        message.postcommit.Add(hook);
                    }
                });
            }

            return(message);
        }