Пример #1
0
        /// <summary>
        /// Persist a <see cref="CorrugatedIron.Models.RiakObject"/> to Riak using the specific <see cref="CorrugatedIron.Models.RiakPutOptions" />.
        /// </summary>
        /// <param name='value'>
        /// The <see cref="CorrugatedIron.Models.RiakObject"/> to save.
        /// </param>
        /// <param name='options'>
        /// Put options
        /// </param>
        public RiakResult <RiakObject> Put(RiakObject value, RiakPutOptions options = null)
        {
            options = options ?? new RiakPutOptions();

            var request = value.ToMessage();

            options.Populate(request);

            var result = UseConnection(conn => conn.PbcWriteRead <RpbPutReq, RpbPutResp>(request));

            if (!result.IsSuccess)
            {
                return(RiakResult <RiakObject> .Error(result.ResultCode, result.ErrorMessage));
            }

            var finalResult = options.ReturnBody
                ? new RiakObject(value.Bucket, value.Key, result.Value.Content.First(), result.Value.VectorClock)
                : value;

            if (options.ReturnBody && result.Value.Content.Count > 1)
            {
                finalResult.Siblings = result.Value.Content.Select(c =>
                                                                   new RiakObject(value.Bucket, value.Key, c, result.Value.VectorClock)).ToList();
            }

            value.MarkClean();

            return(RiakResult <RiakObject> .Success(finalResult));
        }