示例#1
0
        private void Preprocess(IMessage msg)
        {
            // 仅仅处理方法调用
            if (!(msg is IMethodMessage))
            {
                return;
            }

            IMethodMessage call = msg as IMethodMessage;

            Type type = Type.GetType(call.TypeName);

            mTypeAndName = type.Name + "." + call.MethodName;
            if (!FilterMethodName(msg))
            {
                return;
            }
            string logText = "PreProcessing: " + mTypeAndName + "( ";

            // 遍历参数
            for (int i = 0; i < call.ArgCount; ++i)
            {
                if (i > 0)
                {
                    logText += ", ";
                }
                logText += call.GetArgName(i) + " = " + call.GetArg(i);
            }
            logText += " )";
            Logger.Log.Info(logText);
        }
    // Overriding the Invoke method of RealProxy.
    public override IMessage Invoke(IMessage message)
    {
        IMethodMessage myMethodMessage = (IMethodMessage)message;

        Console.WriteLine("**** Begin Invoke ****");
        Console.WriteLine("\tType is : " + myType);
        Console.WriteLine("\tMethod name : " + myMethodMessage.MethodName);

        for (int i = 0; i < myMethodMessage.ArgCount; i++)
        {
            Console.WriteLine("\tArgName is : " + myMethodMessage.GetArgName(i));
            Console.WriteLine("\tArgValue is: " + myMethodMessage.GetArg(i));
        }

        if (myMethodMessage.HasVarArgs)
        {
            Console.WriteLine("\t The method have variable arguments!!");
        }
        else
        {
            Console.WriteLine("\t The method does not have variable arguments!!");
        }

        // Dispatch the method call to the real object.
        Object returnValue = myType.InvokeMember(myMethodMessage.MethodName, BindingFlags.InvokeMethod, null,
                                                 myObjectInstance, myMethodMessage.Args);

        Console.WriteLine("**** End Invoke ****");

        // Build the return message to pass back to the transparent proxy.
        ReturnMessage myReturnMessage = new ReturnMessage(returnValue, null, 0, null,
                                                          (IMethodCallMessage)message);

        return(myReturnMessage);
    }
示例#3
0
        private void Preprocess(IMessage msg)
        {
            // We only want to process method calls
            if (!(msg is IMethodMessage))
            {
                return;
            }

            IMethodMessage call = msg as IMethodMessage;
            Type           type = Type.GetType(call.TypeName);

            m_typeAndName = type.Name + "." + call.MethodName;
            Console.Write("PreProcessing: " + m_typeAndName + "(");

            // Loop through the [in] parameters
            for (int i = 0; i < call.ArgCount; ++i)
            {
                if (i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write(call.GetArgName(i) + " = " + call.GetArg(i));
            }
            Console.WriteLine(")");
        }
示例#4
0
        /// <summary>
        /// Provide trace output for the incoming method call.
        /// </summary>
        /// <param name="msg">The message representing the incoming method call.</param>
        private void TraceMethodCall(IMessage msg)
        {
            IMethodMessage methodCall = msg as IMethodMessage;

            // Process method calls only
            if (methodCall == null)
            {
                return;
            }

            // If the TraceLevel is set to "Info" or "Verbose", log the
            // method call.
            if (((int)_traceLevel) >= ((int)TraceLevel.Info))
            {
                // Store the time of the call, this will be used later to show elapsed time.
                _timeOfMethodCall = DateTime.Now;

                // Add information about the call to the trace output.
                StringBuilder textOutput = new StringBuilder(TRACE_OUTPUT_BUFFER_SIZE);
                textOutput.Append(Type.GetType(methodCall.TypeName).Name);
                textOutput.Append(".");
                textOutput.Append(methodCall.MethodName);
                textOutput.Append("(");
                for (int index = 0; index < methodCall.ArgCount; index++)
                {
                    if (index > 0)
                    {
                        textOutput.Append(", ");
                    }
                    textOutput.Append(methodCall.GetArgName(index));
                    textOutput.Append(" = ");
                    textOutput.Append(methodCall.GetArg(index).ToString());
                }
                textOutput.Append(")");

                // TODO: Write Trace Output.
                Trace.WriteLine(textOutput.ToString(), "Method Call");
                Trace.Indent();
            }

            // Add this object to the call context.
            methodCall.LogicalCallContext.SetData(ContextName, this);
        }