Ejemplo n.º 1
0
 private static void ExceptionHandler(RpcState rpcState, Exception ex)
 {
     try
     {
         if (rpcState.SyncContext == null)
         {
             return;
         }
         rpcState.SyncContext.Send(delegate(object pState)
         {
             var rs     = pState as RpcState;
             var result = new RpcResult();
             result.SetException(ex);
             if (rs != null && rs.ResultCallback != null)
             {
                 rs.ResultCallback(result);
                 BatchInvokeCallbackObject batchInvokeCallbackObject = rs.BatchInvokeCallbackObject;
                 if (batchInvokeCallbackObject != null)
                 {
                     batchInvokeCallbackObject.RemoveInvokeCount(null);
                 }
             }
         }, rpcState);
     }
     catch (ObjectDisposedException) { }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 删除调用计数
 /// </summary>
 public void RemoveInvokeCount(RpcResult pErrResult)
 {
     InvokeCount--;
     if (pErrResult != null)
     {
         _errorResult.Add(pErrResult);
     }
     if (InvokeCount <= 0 && CompletedCallback != null)
     {
         CompletedCallback(_errorResult);
         _errorResult.Clear();
         InvokeCount = 0;
     }
 }
Ejemplo n.º 3
0
        public void Invoke(string pInterfaceName, string pFunctionName, object[] pParames, RpcResultCallback pCallback, bool pReturnOnlyOne = false)
        {
            BatchInvokeCallbackObject bInvokeCallbackObject = null;

            try
            {
                //是否为批量调用
                if (_currentBatchInvokeCallbackObject != null)
                {
                    if (BatchInvokeQueue.ContainsKey(_currentBatchInvokeCallbackObject))
                    {
                        bInvokeCallbackObject = BatchInvokeQueue[_currentBatchInvokeCallbackObject];
                        if (bInvokeCallbackObject != null)
                        {
                            bInvokeCallbackObject.AddInvokeCount();
                        }
                    }
                }
                //判断在多次调用同一个方法时,是否仅返回一次结果
                string code = pInterfaceName + pFunctionName;
                lock (LockOnlyOne)
                {
                    if (pReturnOnlyOne)
                    {
                        if (InvokeCountDic.ContainsKey(code))
                        {
                            //累加调用方法次数
                            InvokeCountDic[code]++;
                        }
                        else
                        {
                            //初次调用该方法赋值1,该方法执行返回后再减1
                            InvokeCountDic[code] = 1;
                        }
                    }
                }
                SynchronizationContext syncContext = SynchronizationContext.Current;
                string url       = "";//@? Utile.GetHostUrl();
                var    remoting  = new Uri(string.Format("{0}/RemotingHandler.ashx", url.ToString(CultureInfo.InvariantCulture)));
                var    hwRequest = (HttpWebRequest)WebRequest.Create(remoting);
                hwRequest.Method      = "POST";
                hwRequest.ContentType = "application/x-www-form-urlencoded";
                string methodContext = RpcMethod.GetRpcMethodContext(pInterfaceName, pFunctionName, pParames);
                var    rpcState      = new RpcState
                {
                    WebRequest                = hwRequest,
                    ResultCallback            = pCallback,
                    SyncContext               = syncContext,
                    MethodContext             = methodContext,
                    BatchInvokeCallbackObject = bInvokeCallbackObject,
                    IsOnlyOne   = pReturnOnlyOne,
                    OnlyOneCode = code
                };
                hwRequest.BeginGetRequestStream(OnGetRequestStream, rpcState);
            }
            catch (Exception ex)
            {
                if (pCallback != null)
                {
                    var result = new RpcResult();
                    result.SetException(ex);
                    pCallback(result);
                    if (bInvokeCallbackObject != null)
                    {
                        bInvokeCallbackObject.RemoveInvokeCount(result);
                    }
                }
            }
        }