Ejemplo n.º 1
0
            /// <summary>
            /// Invokes the message.
            /// </summary>
            /// <param name="msg">The message.</param>
            /// <returns>The result of invocation.</returns>
            public override IMessage Invoke(IMessage msg)
            {
                IConstructionCallMessage constructorCall = msg as IConstructionCallMessage;

                if (constructorCall != null)
                {
                    if (this.target == null)
                    {
                        MethodInfo factoryMethodInfo = Utility.GetInheritedMethod(constructorCall.ActivationType, DynamicConstructionAttribute.InstantiateMethodName, new[] { typeof(Type), typeof(object[]) });

                        if (factoryMethodInfo == null)
                        {
                            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot create an instance of type '{0}' because there is no '{1}' static method defined in its inheritance hierarchy. See '{2}' methods for an example of corresponding method signature.", constructorCall.ActivationType.AssemblyQualifiedName, DynamicConstructionAttribute.InstantiateMethodName, typeof(LiveTest).AssemblyQualifiedName));
                        }

                        if (!DynamicConstructionAttribute.EnterInstantiationPhase())
                        {
                            throw new InvalidOperationException("Error in instantiation workflow. Object is already in the middle of instantiation when another instance of the object is created.");
                        }

                        try
                        {
                            this.target = (LiveTest)factoryMethodInfo.Invoke(null, new object[] { constructorCall.ActivationType, constructorCall.Args });
                        }
                        finally
                        {
                            DynamicConstructionAttribute.LeaveInstantiationPhase();
                        }
                    }

                    return(EnterpriseServicesHelper.CreateConstructionReturnMessage(constructorCall, (MarshalByRefObject)this.GetTransparentProxy()));
                }

                IMethodCallMessage methodCall = msg as IMethodCallMessage;

                if (methodCall != null)
                {
                    methodCall = new MethodCall(methodCall);

                    MethodCallEventArgs eventArgs = typeof(LiveTest).IsAssignableFrom(methodCall.MethodBase.DeclaringType) ? new MethodCallEventArgs(Interlocked.Increment(ref methodCallId), methodCall.MethodBase, methodCall.Args) : null;

                    if (eventArgs != null)
                    {
                        this.target.OnBeforeMethodCall(this.target, eventArgs);
                    }

                    IMessage result = RemotingServices.GetRealProxy(this.target).Invoke(methodCall);

                    if (eventArgs != null)
                    {
                        this.target.OnAfterMethodCall(this.target, eventArgs);
                    }

                    return(result);
                }

                throw new NotSupportedException("Operations other than constructor and method calls are not supported.");
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Event handler executed before each method call.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The arguments.</param>
        protected virtual void OnBeforeMethodCall(object sender, MethodCallEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (this.InitializationManager != null)
            {
                this.InitializationManager.Initialize(args.MethodCallId, new TestInitializationContext(this, args.Method, args.Arguments));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles method call event
        /// </summary>
        unsafe static partial void Behavior_HandleMethodCall(ISciterBehavior behavior, IntPtr he, IntPtr prms, ref bool handled)
        {
            var datantf  = (METHOD_PARAMS *)prms;
            var methodId = (METHOD_PARAMS.BEHAVIOR_METHOD_IDENTIFIERS)datantf->methodID;

            switch (methodId)
            {
            case METHOD_PARAMS.BEHAVIOR_METHOD_IDENTIFIERS.XCALL:
            {
                var data = (XCALL_PARAMS *)datantf;
                var e    = new ScriptingMethodCallEventArgs(Element.Create(he))
                {
                    Arguments  = data->GetArgs(),
                    MethodName = data->GetName()
                };

                behavior.ProcessScriptingMethodCall(e);
                if (e.Handled)
                {
                    data->result.SetValue(e.ReturnValue);
                }

                handled = e.Handled;
            }
            break;

            default:
            {
                var e = new MethodCallEventArgs(Element.Create(he));
                behavior.ProcessMethodCall(e);

                handled = e.Handled;
            }
            break;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// The routine called before test method call.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The arguments.</param>
 protected override void OnBeforeMethodCall(object sender, MethodCallEventArgs args)
 {
     args.Arguments[0] = args.Arguments[0].ToString() + '*';
 }
Ejemplo n.º 5
0
 /// <summary>
 /// The routine called after test method call.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The arguments.</param>
 protected override void OnAfterMethodCall(object sender, MethodCallEventArgs args)
 {
     Assert.Equal("testValue", CallContext.LogicalGetData("test1"));
     Assert.Equal("testValue", CallContext.LogicalGetData("test2"));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// The routine called before test method call.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The arguments.</param>
 protected override void OnBeforeMethodCall(object sender, MethodCallEventArgs args)
 {
     CallContext.LogicalSetData("test1", "testValue");
 }