SendResult() 공개 메소드

public SendResult ( object request_state, object result ) : void
request_state object
result object
리턴 void
예제 #1
0
파일: RpcManager.cs 프로젝트: pcbing/brunet
            public void HandleRpc(ISender caller, string methname, IList arguments, object request_state)
            {
                MethodInfo mi = null;

                /*
                 * Lookup this method name in our table.
                 * This uses a cache, so it should be fast
                 * after the first time
                 */
                lock ( _sync ) {
                    mi = (MethodInfo)_method_cache[methname];
                    if (mi == null)
                    {
                        mi = _type.GetMethod(methname);
                        _method_cache[methname] = mi;
                    }
                }

                if (_use_sender)
                {
                    arguments = new ArrayList(arguments);
                    arguments.Add(caller);
                }
                object[] arg_array = new object[arguments.Count];
                arguments.CopyTo(arg_array, 0);
                //Console.Error.WriteLine("About to call: {0}.{1} with args",handler, mname);
                //foreach(object arg in pa) { Console.Error.WriteLine("arg: {0}",arg); }
                //make the following happen asynchronously in a separate thread
                //build an invocation record for the call
                Object result = null;

                try {
  #if RPC_DEBUG
                    Console.Error.WriteLine("[RpcServer: {0}] Invoking method: {1}", _rrman.Info, mi);
  #endif
                    result = mi.Invoke(_handler, arg_array);
                } catch (ArgumentException argx) {
  #if RPC_DEBUG
                    Console.Error.WriteLine("[RpcServer: {0}] Argument exception. {1}", _rrman.Info, mi);
  #endif
                    result = new AdrException(-32602, argx);
                }
                catch (TargetParameterCountException argx) {
  #if RPC_DEBUG
                    Console.Error.WriteLine("[RpcServer: {0}] Parameter count exception. {1}", _rrman.Info, mi);
  #endif
                    result = new AdrException(-32602, argx);
                }
                catch (TargetInvocationException x) {
  #if RPC_DEBUG
                    Console.Error.WriteLine("[RpcServer: {0}] Exception thrown by method: {1}, {2}", _rrman.Info, mi, x.InnerException.Message);
  #endif
                    if (x.InnerException is AdrException)
                    {
                        result = x.InnerException;
                    }
                    else
                    {
                        result = new AdrException(-32608, x.InnerException);
                    }
                }
                catch (Exception x) {
  #if RPC_DEBUG
                    Console.Error.WriteLine("[RpcServer: {0}] General exception. {1}", _rrman.Info, mi);
  #endif
                    result = x;
                }
                finally {
                    _rpc.SendResult(request_state, result);
                }
            }
예제 #2
0
            public void HandleRpc(ISender caller, string methname, IList arguments, object request_state)
            {
                MethodInfo mi = null;

                /*
                 * Lookup this method name in our table.
                 * This uses a cache, so it should be fast
                 * after the first time
                 */
                lock ( _sync ) {
                    mi = (MethodInfo)_method_cache[methname];
                    if (mi == null)
                    {
                        mi = _type.GetMethod(methname);
                        _method_cache[methname] = mi;
                    }
                }

                if (_use_sender)
                {
                    arguments = new ArrayList(arguments);
                    arguments.Add(caller);
                }
                object[] arg_array = new object[arguments.Count];
                arguments.CopyTo(arg_array, 0);
                //Console.Error.WriteLine("About to call: {0}.{1} with args",handler, mname);
                //foreach(object arg in pa) { Console.Error.WriteLine("arg: {0}",arg); }
                //make the following happen asynchronously in a separate thread
                //build an invocation record for the call
                WaitCallback wb = delegate(object o) {
                    Object result = null;
                    try {
    #if RPC_DEBUG
                        Console.Error.WriteLine("[RpcServer: {0}] Invoking method: {1}", _rrman.Info, mi);
    #endif
                        result = mi.Invoke(_handler, arg_array);
                    } catch (ArgumentException argx) {
    #if RPC_DEBUG
                        Console.Error.WriteLine("[RpcServer: {0}] Argument exception. {1}", _rrman.Info, mi);
    #endif
                        result = new AdrException(-32602, argx);
                    }
                    catch (TargetParameterCountException argx) {
    #if RPC_DEBUG
                        Console.Error.WriteLine("[RpcServer: {0}] Parameter count exception. {1}", _rrman.Info, mi);
    #endif
                        result = new AdrException(-32602, argx);
                    }
                    catch (TargetInvocationException x) {
    #if RPC_DEBUG
                        Console.Error.WriteLine("[RpcServer: {0}] Exception thrown by method: {1}, {2}", _rrman.Info, mi, x.InnerException.Message);
    #endif
                        if (x.InnerException is AdrException)
                        {
                            result = x.InnerException;
                        }
                        else
                        {
                            result = new AdrException(-32608, x.InnerException);
                        }
                    }
                    catch (Exception x) {
    #if RPC_DEBUG
                        Console.Error.WriteLine("[RpcServer: {0}] General exception. {1}", _rrman.Info, mi);
    #endif
                        result = x;
                    }
                    finally {
                        _rpc.SendResult(request_state, result);
                    }
                };

                //Make sure we don't block while invoking the method:
#if BRUNET_SIMULATOR
                //Don't use extra threads in the simulator case:
                wb(null);
#else
                try {
                    /*
                     * According to MSDN, the only way this fails is if the CLR is "Hosted"
                     * which appears to mean that it is running inside SQL server.  I can't imagine
                     * us running into that case, but let's handle it just in case.
                     */
                    if (!ThreadPool.QueueUserWorkItem(wb))
                    {
                        wb(null);
                    }
                }
                catch (Exception) {
                    wb(null);
                }
#endif
            }