/// <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)); }
public async Task <Either <RiakException, RiakObject> > Put(RiakObject value, RiakPutOptions options = null) { if (!IsValidBucketOrKey(value.Bucket)) { return(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.InvalidRequest, InvalidBucketErrorMessage, false))); } if (!IsValidBucketOrKey(value.Key)) { return(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.InvalidRequest, InvalidKeyErrorMessage, false))); } options = options ?? new RiakPutOptions(); var request = value.ToMessage(); options.Populate(request); try { var result = await _connection.PbcWriteRead <RpbPutReq, RpbPutResp>(_endPoint, request).ConfigureAwait(false); var finalResult = options.ReturnBody ? new RiakObject(value.Bucket, value.Key, result.content.First(), result.vclock) : value; if (options.ReturnBody && result.content.Count > 1) { finalResult.Siblings = result.content.Select(c => new RiakObject(value.Bucket, value.Key, c, result.vclock)).ToList(); } return(new Either <RiakException, RiakObject>(finalResult)); } catch (RiakException riakException) { return(new Either <RiakException, RiakObject>(riakException)); } }
public Task <RiakResult <RiakObject> > Put(RiakObject value, RiakPutOptions options = null) { if (!IsValidBucketOrKey(value.Bucket)) { return(RiakResult <RiakObject> .ErrorTask(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)); } if (!IsValidBucketOrKey(value.Key)) { return(RiakResult <RiakObject> .ErrorTask(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)); } var request = value.ToMessage(); options = options ?? new RiakPutOptions(); options.Populate(request); return(UseConnection(conn => conn.PbcWriteRead <RpbPutReq, RpbPutResp>(request)) .ContinueWith((Task <RiakResult <RpbPutResp> > finishedTask) => { var result = finishedTask.Result; if (!result.IsSuccess) { return RiakResult <RiakObject> .Error(result.ResultCode, result.ErrorMessage, result.NodeOffline); } var finalResult = options.ReturnBody ? new RiakObject(value.Bucket, value.Key, result.Value.content.First(), result.Value.vclock) : 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.vclock)).ToList(); } return RiakResult <RiakObject> .Success(finalResult); })); }