当前位置: 首页>>代码示例>>C#>>正文


C# IOperation.GetBuffer方法代码示例

本文整理汇总了C#中IOperation.GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# IOperation.GetBuffer方法的具体用法?C# IOperation.GetBuffer怎么用?C# IOperation.GetBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOperation的用法示例。


在下文中一共展示了IOperation.GetBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteOperation

		protected override Enyim.Caching.Memcached.Results.IPooledSocketResult ExecuteOperation(IOperation op)
		{
			var result = this.Acquire();
			if (result.Success && result.HasValue)
			{
				try
				{
					var socket = result.Value;
					var b = op.GetBuffer();

					socket.Write(b);

					var readResult = op.ReadResponse(socket);
					if (readResult.Success)
					{
						result.Pass();
					}
					else
					{
						readResult.Combine(result);
					}
					return result;
				}
				//----------------------------------------Begin Modify by ZhaiXueDong---------------------------------------------------------------------------
				//catch (IOException e)
				//{
				//    log.Error(e);

				//    result.Fail("Exception reading response", e);
				//    return result;
				//}
				//----------------------------------------------------------------------------------------------------------------------------------------------
				// my
				catch (System.Net.Sockets.SocketException)
				{
					throw;
				}
				//----------------------------------------End Modify by ZhaiXueDong-----------------------------------------------------------------------------
				finally
				{
					((IDisposable)result.Value).Dispose();
				}
			}
			else
			{
				// result.Fail("Failed to obtain socket from pool");
				//return result;

				if (result.Exception != null)
				{
					throw result.Exception;
				}

				throw new System.ServiceModel.EndpointNotFoundException(String.Format("未能够从连接池中获取到连接对象,详细错误信息为:{0}", result.Message));
			}

		}
开发者ID:Kjubo,项目名称:xms.core,代码行数:57,代码来源:CustomBinaryNode.cs

示例2: ExecuteAsync

        public bool ExecuteAsync(IOperation op, Action<bool> next)
        {
            IPooledSocket socket = null;
            var result = false;
            try
            {
                socket = _pool.Acquire();
                var buffers = op.GetBuffer();
                socket.Write(buffers);

                result = op.ReadResponseAsync(socket, readSuccess =>
                {
                    socket.Dispose();
                    next(readSuccess);
                });
            }
            catch (IOException e)
            {
                Log.Error(e);
            }
            finally
            {
                if (socket != null)
                {
                    _pool.Release(socket);
                }
            }
            return result;
        }
开发者ID:JebteK,项目名称:couchbase-net-client,代码行数:29,代码来源:CouchbaseNode.cs

示例3: Execute

        public IOperationResult Execute(IOperation op)
        {
            IOperationResult result = new BinaryOperationResult();
            IPooledSocket socket = null;
            try
            {
                socket = _pool.Acquire();
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Start execute {0} with {1}", op.Key, socket.InstanceId);
                }
                var buffers = op.GetBuffer();
                socket.Write(buffers);

                result = op.ReadResponse(socket);
                if (result.Success)
                {
                    result.Pass();
                }
            }
            catch (NodeShutdownException e)
            {
                string msg = String.Format("Node Shutdown - {0}.", EndPoint);
                Log.DebugFormat("m:{0} i:{1}\n{2}", msg, op.Key, e);
                result.Fail(msg, e);
                result.StatusCode = StatusCode.NodeShutdown.ToInt();
            }
            catch (QueueTimeoutException e)
            {
                string msg = String.Format("Queue Timeout - {0}.", EndPoint);
                Log.ErrorFormat("m:{0} i:{1}\n{2}", msg, op.Key, e);
                result.Fail(msg, e);
                result.StatusCode = StatusCode.SocketPoolTimeout.ToInt();
            }
            catch (IOException e)
            {
                string msg = String.Format("Exception reading response - {0}", EndPoint);
                Log.ErrorFormat("m:{0} s:{1} i:{2}\n{3}", msg, op.Key,
                    socket == null ? Guid.Empty : socket.InstanceId, e);
                result.Fail(msg, e);
                if (result.StatusCode == null ||
                    result.StatusCode == StatusCode.Success.ToInt())
                {
                    result.StatusCode = StatusCode.InternalError.ToInt();
                }
            }
            catch (Exception e)
            {
                string msg = String.Format("Operation failed - {0}", EndPoint);
                Log.ErrorFormat("m:{0} s:{1} i:{2}\n{3}", msg, op.Key,
                    socket == null ? Guid.Empty : socket.InstanceId, e);
                result.Fail(msg, e);
                if (result.StatusCode == null ||
                    result.StatusCode == StatusCode.Success.ToInt())
                {
                    result.StatusCode = StatusCode.InternalError.ToInt();
                }
            }
            finally
            {
                if (socket != null)
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("End execute {0} with {1}", op.Key, socket.InstanceId);
                    }
                    _pool.Release(socket);
                }
            }
            if (Log.IsDebugEnabled)
            {
                const string msg = "Operation {0} :i {1} n: {2} t: {3} m: {4} sc: {5} r: {6}";
                Log.DebugFormat(msg, result.Success ?
                    op.RetryAttempts > 0 ? "succeeded*" : "succeeded" :
                    op.RetryAttempts > 0 ? "failed*" : "failed",
                    op.Key,
                    _endpoint, Thread.CurrentThread.Name,
                    result.Message,
                    Enum.GetName(typeof (StatusCode), result.StatusCode ?? 0),
                    op.RetryAttempts);
            }
            return result;
        }
开发者ID:JebteK,项目名称:couchbase-net-client,代码行数:83,代码来源:CouchbaseNode.cs


注:本文中的IOperation.GetBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。