예제 #1
0
        private Task <RiakResult <IEnumerable <RiakResult> > > Delete(IRiakConnection conn,
                                                                      IEnumerable <RiakObjectId> objectIds,
                                                                      RiakDeleteOptions options = null)
        {
            options = options ?? new RiakDeleteOptions();
            return(AfterAll(objectIds.Select(id => {
                if (!IsValidBucketOrKey(id.Bucket))
                {
                    return RiakResult.ErrorTask(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false);
                }

                if (!IsValidBucketOrKey(id.Key))
                {
                    return RiakResult.ErrorTask(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false);
                }

                var req = new RpbDelReq {
                    bucket = id.Bucket.ToRiakString(), key = id.Key.ToRiakString()
                };
                options.Populate(req);
                return conn.PbcWriteRead(req, MessageCode.DelResp);
            })).ContinueWith((Task <IEnumerable <RiakResult> > finishedTask) => {
                return RiakResult <IEnumerable <RiakResult> > .Success(finishedTask.Result);
            }));
        }
예제 #2
0
        public async Task <Either <RiakException, RiakObjectId> > Delete(string bucket, string key, RiakDeleteOptions options = null)
        {
            if (!IsValidBucketOrKey(bucket))
            {
                return(new Either <RiakException, RiakObjectId>(new RiakException((uint)ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)));
            }

            if (!IsValidBucketOrKey(key))
            {
                return(new Either <RiakException, RiakObjectId>(new RiakException((uint)ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)));
            }

            options = options ?? new RiakDeleteOptions();

            var request = new RpbDelReq {
                bucket = bucket.ToRiakString(), key = key.ToRiakString()
            };

            options.Populate(request);

            try
            {
                await _connection.PbcWriteRead(_endPoint, request, MessageCode.DelResp).ConfigureAwait(false);

                return(new Either <RiakException, RiakObjectId>(new RiakObjectId(bucket, key)));
            }
            catch (RiakException riakException)
            {
                return(new Either <RiakException, RiakObjectId>(riakException));
            }
        }
예제 #3
0
        private static RiakResult <IEnumerable <RiakResult> > Delete(IRiakConnection conn,
                                                                     IEnumerable <RiakObjectId> objectIds, RiakDeleteOptions options = null)
        {
            options = options ?? new RiakDeleteOptions();

            var responses = objectIds.Select(id =>
            {
                if (!IsValidBucketOrKey(id.Bucket))
                {
                    return(RiakResult.Error(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false));
                }

                if (!IsValidBucketOrKey(id.Key))
                {
                    return(RiakResult.Error(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false));
                }

                var req = new RpbDelReq {
                    bucket = id.Bucket.ToRiakString(), key = id.Key.ToRiakString()
                };
                options.Populate(req);
                return(conn.PbcWriteRead(req, MessageCode.DelResp));
            }).ToList();

            return(RiakResult <IEnumerable <RiakResult> > .Success(responses));
        }
예제 #4
0
        /// <summary>
        /// Delete the record identified by <paramref name="key"/> from a <paramref name="bucket"/>.
        /// </summary>
        /// <param name='bucket'>
        /// The name of the bucket that contains the record to be deleted.
        /// </param>
        /// <param name='key'>
        /// The key identifying the record to be deleted.
        /// </param>
        /// <param name='options'>
        /// Delete options
        /// </param>
        public RiakResult Delete(string bucket, string key, RiakDeleteOptions options = null)
        {
            options = options ?? new RiakDeleteOptions();

            var request = new RpbDelReq {
                Bucket = bucket.ToRiakString(), Key = key.ToRiakString()
            };

            options.Populate(request);
            var result = UseConnection(conn => conn.PbcWriteRead <RpbDelReq, RpbDelResp>(request));

            return(result);
        }
예제 #5
0
        public IObservable <Either <RiakException, RiakObjectId> > Delete(IEnumerable <RiakObjectId> objectIds, RiakDeleteOptions options = null)
        {
            var observables = Observable.Create <Either <RiakException, RiakObjectId> >(async obs =>
            {
                try
                {
                    options = options ?? new RiakDeleteOptions();

                    foreach (var id in objectIds)
                    {
                        if (!IsValidBucketOrKey(id.Bucket))
                        {
                            obs.OnNext(new Either <RiakException, RiakObjectId>(new RiakException((uint)ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)));
                            continue;
                        }

                        if (!IsValidBucketOrKey(id.Key))
                        {
                            obs.OnNext(new Either <RiakException, RiakObjectId>(new RiakException((uint)ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)));
                            continue;
                        }

                        var req = new RpbDelReq {
                            bucket = id.Bucket.ToRiakString(), key = id.Key.ToRiakString()
                        };
                        options.Populate(req);

                        try
                        {
                            await _connection.PbcWriteRead(_endPoint, req, MessageCode.DelResp).ConfigureAwait(false);
                        }
                        catch (RiakException riakException)
                        {
                            obs.OnNext(new Either <RiakException, RiakObjectId>(riakException));
                            continue;
                        }

                        obs.OnNext(new Either <RiakException, RiakObjectId>(id));
                    }
                    obs.OnCompleted();
                }
                catch (Exception exception)
                {
                    obs.OnError(exception);
                }
                return(Disposable.Empty);
            });

            return(observables);
        }
예제 #6
0
        internal void Populate(RpbDelReq request)
        {
            request.r  = R.IsLeft ? R.Left : R.Right.ToRpbOption();
            request.pr = Pr.IsLeft ? Pr.Left : Pr.Right.ToRpbOption();
            request.rw = Rw.IsLeft ? Rw.Left : Rw.Right.ToRpbOption();
            request.w  = W.IsLeft ? W.Left : W.Right.ToRpbOption();
            request.pw = Pw.IsLeft ? Pw.Left : Pw.Right.ToRpbOption();
            request.dw = Dw.IsLeft ? Dw.Left : Dw.Right.ToRpbOption();

            if (Vclock != null)
            {
                request.vclock = Vclock;
            }
        }
예제 #7
0
 internal void Populate(RpbDelReq request)
 {
     request.r       = R;
     request.pr      = Pr;
     request.rw      = Rw;
     request.w       = W;
     request.pw      = Pw;
     request.dw      = Dw;
     request.timeout = (uint)Timeout;
     if (Vclock != null)
     {
         request.vclock = Vclock;
     }
 }
예제 #8
0
        public Task <RiakResult> Delete(string bucket, string key, RiakDeleteOptions options = null)
        {
            if (!IsValidBucketOrKey(bucket))
            {
                return(RiakResult.ErrorTask(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false));
            }

            if (!IsValidBucketOrKey(key))
            {
                return(RiakResult.ErrorTask(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false));
            }

            var request = new RpbDelReq {
                bucket = bucket.ToRiakString(), key = key.ToRiakString()
            };

            options = options ?? new RiakDeleteOptions();
            options.Populate(request);
            return(UseConnection(conn => conn.PbcWriteRead(request, MessageCode.DelResp)));
        }
예제 #9
0
        /// <summary>
        /// delete
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="key"></param>
        /// <param name="setOptions"></param>
        /// <param name="millisecondsReceiveTimeout"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        public Task Delete(string bucket,
                           byte[] key,
                           Action <DeleteOptions> setOptions = null,
                           int millisecondsReceiveTimeout    = 3000,
                           object asyncState = null)
        {
            var source = new TaskCompletionSource <bool>(asyncState);
            var req    = new RpbDelReq {
                bucket = bucket.GetBytes(), key = key
            };

            if (setOptions != null)
            {
                setOptions(new DeleteOptions(req));
            }

            this._socket.Execute <RpbDelReq>(Codes.DelReq, Codes.DelResp, req,
                                             ex => source.TrySetException(ex),
                                             () => source.TrySetResult(true),
                                             millisecondsReceiveTimeout);
            return(source.Task);
        }
예제 #10
0
        internal void Populate(RpbDelReq request)
        {
            if (Rw.HasValue)
            {
                request.Rw = Rw.Value;
            }

            if (Vclock != null)
            {
                request.Vclock = Vclock;
            }

            if (R.HasValue)
            {
                request.R = R.Value;
            }

            if (W.HasValue)
            {
                request.W = W.Value;
            }

            if (Pr.HasValue)
            {
                request.Pr = Pr.Value;
            }

            if (Pw.HasValue)
            {
                request.Pw = Pw.Value;
            }

            if (Dw.HasValue)
            {
                request.Dw = Dw.Value;
            }
        }