public override IMessage Invoke(IMessage request)
    {
        IMethodCallMessage call = (IMethodCallMessage)request;

        Console.WriteLine("Invoke " + call.MethodName);

        Console.Write("ARGS(");
        for (int i = 0; i < call.ArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(call.GetArgName(i) + " " +
                          call.GetArg(i));
        }
        Console.WriteLine(")");
        Console.Write("INARGS(");
        for (int i = 0; i < call.InArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(call.GetInArgName(i) + " " +
                          call.GetInArg(i));
        }
        Console.WriteLine(")");

        ((R1)target).test_field = 1;

        IMethodReturnMessage res = RemotingServices.ExecuteMessage(target, call);

        Console.Write("RESARGS(");
        for (int i = 0; i < res.ArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(res.GetArgName(i) + " " +
                          res.GetArg(i));
        }
        Console.WriteLine(")");

        Console.Write("RESOUTARGS(");
        for (int i = 0; i < res.OutArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(res.GetOutArgName(i) + " " +
                          res.GetOutArg(i));
        }
        Console.WriteLine(")");

        return(res);
    }
Exemplo n.º 2
0
 public virtual String GetArgName(int index)
 {
     return(mrm.GetArgName(index));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Provide trace output for the method return.  It is at this point that
        /// exceptions and return values will be logged (if available), and the
        /// elapsed time for the method to execute is calculated.
        /// </summary>
        /// <param name="msg">The incoming method call</param>
        /// <param name="returnMsg">The method return</param>
        private void TraceMethodReturn(IMessage msg, IMessage returnMsg)
        {
            IMethodReturnMessage methodReturn = returnMsg as IMethodReturnMessage;

            // Handle method returns only
            if ((methodReturn == null) || !(msg is IMethodMessage))
            {
                return;
            }

            // If no tracing is performed, exit.
            if (_traceLevel == TraceLevel.Off)
            {
                return;
            }

            // If the TraceLevel is set to "Info" or "Verbose", the method call
            // was logged and the indent increased.  Decrease it now.
            if (((int)_traceLevel) >= ((int)TraceLevel.Info))
            {
                Trace.Unindent();
            }

            // Calculate the time spent in the method call.
            TimeSpan elapsedTimeInCall = DateTime.Now - _timeOfMethodCall;

            StringBuilder textOutput = new StringBuilder(TRACE_OUTPUT_BUFFER_SIZE);

            // If an exception occurred, log it to the trace log and return.
            Exception e = methodReturn.Exception;

            if (e != null)
            {
                textOutput.Append(Type.GetType(methodReturn.TypeName).Name);
                textOutput.Append(".");
                textOutput.Append(methodReturn.MethodName);
                textOutput.Append("(");
                for (int index = 0; index < methodReturn.ArgCount; index++)
                {
                    if (index > 0)
                    {
                        textOutput.Append(", ");
                    }
                    textOutput.Append(methodReturn.GetArgName(index));
                    textOutput.Append(" = ");
                    textOutput.Append(methodReturn.GetArg(index).ToString());
                }
                textOutput.Append(")\n");
                textOutput.Append("----- EXCEPTION -----\n");
                textOutput.Append(e.ToString());
                textOutput.Append("\n----- EXCEPTION -----");

                Trace.WriteLine(textOutput.ToString(), string.Format(
                                    "Method Return - {0} ms", elapsedTimeInCall.TotalMilliseconds));
                return;
            }

            // If the trace level is set to "Info" or "Verbose", then log the
            // return values from the call as well as the time spent in the call.
            if (((int)_traceLevel) >= ((int)TraceLevel.Info))
            {
                textOutput.Append(Type.GetType(methodReturn.TypeName).Name);
                textOutput.Append(".");
                textOutput.Append(methodReturn.MethodName);
                textOutput.Append("(");
                if (methodReturn.OutArgCount > 0)
                {
                    textOutput.Append("ref/out parameters[");
                    for (int index = 0; index < methodReturn.OutArgCount; index++)
                    {
                        if (index > 0)
                        {
                            textOutput.Append(", ");
                        }
                        textOutput.Append(methodReturn.GetOutArgName(index));
                        textOutput.Append(" = ");
                        textOutput.Append(methodReturn.GetOutArg(index).ToString());
                    }
                    textOutput.Append("]");
                }

                if (methodReturn.ReturnValue.GetType() != typeof(void))
                {
                    if (methodReturn.OutArgCount > 0)
                    {
                        textOutput.Append(", ");
                    }
                    textOutput.Append("returned [");
                    textOutput.Append(methodReturn.ReturnValue.ToString());
                    textOutput.Append("]");
                }
                textOutput.Append(")");

                Trace.WriteLine(textOutput.ToString(), string.Format(
                                    "Method Return - {0} ms", elapsedTimeInCall.TotalMilliseconds));
            }
        }