示例#1
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var result = new BinaryOperationResult();

#if EVEN_MORE_LOGGING
            if (log.IsDebugEnabled)
            {
                if (response.StatusCode == 0)
                {
                    log.DebugFormat("Delete succeeded for key '{0}'.", this.Key);
                }
                else
                {
                    log.DebugFormat("Delete failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
                }
            }
#endif
            if (response.StatusCode == 0)
            {
                return(result.Pass());
            }
            else
            {
                var message = ResultHelper.ProcessResponseData(response.Data);
                return(result.Fail(message));
            }
        }
示例#2
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var status = response.StatusCode;
            var result = new BinaryOperationResult();

            this.StatusCode = status;

            if (status == 0)
            {
                int flags = BinaryConverter.DecodeInt32(response.Extra, 0);
                this.result = new CacheItem((ushort)flags, response.Data);
                this.Cas    = response.CAS;

#if EVEN_MORE_LOGGING
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Get succeeded for key '{0}'.", this.Key);
                }
#endif

                return(result.Pass());
            }

            this.Cas = 0;

#if EVEN_MORE_LOGGING
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
            }
#endif

            var message = ResultHelper.ProcessResponseData(response.Data);
            return(result.Fail(message));
        }
示例#3
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            var response   = new BinaryResponse();
            var serverData = new Dictionary <string, string>();
            var retval     = false;

            while (response.Read(socket) && response.KeyLength > 0)
            {
                retval = true;

                var data  = response.Data;
                var key   = BinaryConverter.DecodeKey(data.Array, data.Offset, response.KeyLength);
                var value = BinaryConverter.DecodeKey(data.Array, data.Offset + response.KeyLength, data.Count - response.KeyLength);

                serverData[key] = value;
            }

            this.result     = serverData;
            this.StatusCode = response.StatusCode;

            var result = new BinaryOperationResult()
            {
                StatusCode = StatusCode
            };

            result.PassOrFail(retval, "Failed to read response");
            return(result);
        }
示例#4
0
 protected override IOperationResult ProcessResponse(BinaryResponse response)
 {
     return(new BinaryOperationResult()
     {
         Success = true
     });
 }
示例#5
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            var response = new BinaryResponse();
            var retval   = response.Read(socket);

            this.Cas        = response.CAS;
            this.StatusCode = response.StatusCode;

            var result = new BinaryOperationResult()
            {
                Success    = retval,
                Cas        = this.Cas,
                StatusCode = this.StatusCode
            };

            IOperationResult responseResult;

            if (!(responseResult = this.ProcessResponse(response)).Success)
            {
                result.InnerResult = responseResult;
                responseResult.Combine(result);
            }

            return(result);
        }
示例#6
0
        protected internal override bool ReadResponseAsync(PooledSocket socket, Action <bool> next)
        {
            this.result = new Dictionary <string, CacheItem>();
            this.Cas    = new Dictionary <string, ulong>();

            this.currentSocket  = socket;
            this.asyncReader    = new BinaryResponse();
            this.asyncLoopState = null;
            this.afterAsyncRead = next;

            return(this.DoReadAsync());
        }
示例#7
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            var response = new BinaryResponse();
            var retval   = response.Read(socket);

            this.StatusCode = StatusCode;
            var result = new BinaryOperationResult()
            {
                Success    = retval,
                StatusCode = this.StatusCode
            };

            result.PassOrFail(retval, "Failed to read response");
            return(result);
        }
示例#8
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            this.result = new Dictionary <string, CacheItem>();
            this.Cas    = new Dictionary <string, ulong>();
            var result = new TextOperationResult();

            var response = new BinaryResponse();

            while (response.Read(socket))
            {
                this.StatusCode = response.StatusCode;

                // found the noop, quit
                if (response.CorrelationId == this.noopId)
                {
                    return(result.Pass());
                }

                string key;

                // find the key to the response
                if (!this.idToKey.TryGetValue(response.CorrelationId, out key))
                {
                    // we're not supposed to get here tho
                    log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", response.CorrelationId);
                    continue;
                }

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Reading item {0}", key);
                }

                // deserialize the response
                int flags = BinaryConverter.DecodeInt32(response.Extra, 0);

                this.result[key] = new CacheItem((ushort)flags, response.Data);
                this.Cas[key]    = response.CAS;
            }

            // finished reading but we did not find the NOOP
            return(result.Fail("Found response with CorrelationId {0}, but no key is matching it."));
        }
示例#9
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var result = new BinaryOperationResult();
            var status = response.StatusCode;

            this.StatusCode = status;

            if (status == 0)
            {
                var data = response.Data;
                if (data.Count != 8)
                {
                    return(result.Fail("Result must be 8 bytes long, received: " + data.Count, new InvalidOperationException()));
                }

                this.result = BinaryConverter.DecodeUInt64(data.Array, data.Offset);

                return(result.Pass());
            }

            var message = ResultHelper.ProcessResponseData(response.Data);

            return(result.Fail(message));
        }
示例#10
0
        private void StoreResult(BinaryResponse reader)
        {
            string key;

            // find the key to the response
            if (!this.idToKey.TryGetValue(reader.CorrelationId, out key))
            {
                // we're not supposed to get here tho
                log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", reader.CorrelationId);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Reading item {0}", key);
                }

                // deserialize the response
                var flags = (ushort)BinaryConverter.DecodeInt32(reader.Extra, 0);

                this.result[key] = new CacheItem(flags, reader.Data);
                this.Cas[key]    = reader.CAS;
            }
        }
示例#11
0
 protected abstract IOperationResult ProcessResponse(BinaryResponse response);