private static object[] ProcessEvent(HandleExternalEventActivity activity, ActivityExecutionContext context, object msg, Type interfaceType, string operation)
        {
            IMethodMessage message = msg as IMethodMessage;

            if (message == null)
            {
                Exception excp = msg as Exception;
                if (excp != null)
                {
                    throw excp;
                }
                throw new InvalidOperationException(SR.GetString(SR.Error_InvalidLocalServiceMessage));
            }

            CorrelationService.InvalidateCorrelationToken(activity, interfaceType, operation, message.Args);

            IdentityContextData identityData =
                (IdentityContextData)message.LogicalCallContext.GetData(IdentityContextData.IdentityContext);

            ValidateRoles(activity, identityData.Identity);

            if (ProcessEventParameters(activity.ParameterBindings, message, interfaceType, operation))
            {
                return(message.Args);
            }

            return(null);
        }
Ejemplo n.º 2
0
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            ActivityExecutionStatus status = ExecuteForActivity(executionContext, this.InterfaceType, this.MethodName);

            if (status == ActivityExecutionStatus.Closed)
            {
                UnsubscribeForActivity(executionContext);
                executionContext.CloseActivity();
                return(status);
            }

            // cannot resolve queue name or message not available
            // hence subscribe for message arrival
            if (!this.ActivitySubscribed)
            {
                this.ActivitySubscribed = CorrelationService.Subscribe(executionContext, this, this.InterfaceType, this.MethodName, this, this.WorkflowInstanceId);
            }

            return(ActivityExecutionStatus.Executing);
        }
Ejemplo n.º 3
0
 private void UnsubscribeForActivity(ActivityExecutionContext context)
 {
     if (this.ActivitySubscribed)
     {
         CorrelationService.Unsubscribe(context, this, this.InterfaceType, this.MethodName, this);
         this.ActivitySubscribed = false;
     }
 }
 void IEventActivity.Unsubscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler)
 {
     if (parentContext == null)
     {
         throw new ArgumentNullException("parentContext");
     }
     if (parentEventHandler == null)
     {
         throw new ArgumentNullException("parentEventHandler");
     }
     CorrelationService.Unsubscribe(parentContext, this, this.InterfaceType, this.EventName, parentEventHandler);
 }
Ejemplo n.º 5
0
 void IEventActivity.Subscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler)
 {
     if (parentContext == null)
     {
         throw new ArgumentNullException("parentContext");
     }
     if (parentEventHandler == null)
     {
         throw new ArgumentNullException("parentEventHandler");
     }
     CorrelationService.Subscribe(parentContext, this, this.InterfaceType, this.MethodName, parentEventHandler, base.WorkflowInstanceId);
 }
Ejemplo n.º 6
0
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (this.InterfaceType == null)
            {
                throw new ArgumentException(
                          SR.GetString(SR.Error_MissingInterfaceType), "executionContext");
            }

            Type   type       = this.InterfaceType;
            string methodName = this.MethodName;

            object serviceValue = executionContext.GetService(type);

            if (serviceValue == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_ServiceNotFound, this.InterfaceType));
            }

            this.RaiseEvent(MethodInvokingEvent, this, EventArgs.Empty);
            OnMethodInvoking(EventArgs.Empty);

            MethodInfo methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);

            ParameterModifier[] parameterModifiers = null;
            object[]            actualParameters   = InvokeHelper.GetParameters(methodInfo, this.ParameterBindings, out parameterModifiers);

            WorkflowParameterBinding resultBinding = null;

            if (this.ParameterBindings.Contains("(ReturnValue)"))
            {
                resultBinding = this.ParameterBindings["(ReturnValue)"];
            }

            CorrelationService.InvalidateCorrelationToken(this, type, methodName, actualParameters);

            object result = type.InvokeMember(this.MethodName, BindingFlags.InvokeMethod, new ExternalDataExchangeBinder(), serviceValue, actualParameters, parameterModifiers, null, null);

            if (resultBinding != null)
            {
                resultBinding.Value = InvokeHelper.CloneOutboundValue(result, new BinaryFormatter(), "(ReturnValue)");
            }

            InvokeHelper.SaveOutRefParameters(actualParameters, methodInfo, this.ParameterBindings);
            OnMethodInvoked(EventArgs.Empty);
            return(ActivityExecutionStatus.Closed);
        }
 protected sealed override void Initialize(IServiceProvider provider)
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if ((!base.IsDynamicActivity && !this.IsNestedUnderMultiInstanceContainer) || this.IsInitializingUnderMultiInstanceContainer)
     {
         Type        interfaceType = this.InterfaceType;
         string      eventName     = this.EventName;
         IComparable comparable    = null;
         if (CorrelationResolver.IsInitializingMember(interfaceType, eventName, null))
         {
             comparable = new EventQueueName(interfaceType, eventName);
         }
         base.SetValue(QueueNameProperty, comparable);
         CorrelationService.Initialize(provider, this, interfaceType, eventName, base.WorkflowInstanceId);
     }
 }
Ejemplo n.º 8
0
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            ActivityExecutionStatus status = this.ExecuteForActivity(executionContext, this.InterfaceType, this.MethodName);

            if (status == ActivityExecutionStatus.Closed)
            {
                this.UnsubscribeForActivity(executionContext);
                executionContext.CloseActivity();
                return(status);
            }
            if (!this.ActivitySubscribed)
            {
                this.ActivitySubscribed = CorrelationService.Subscribe(executionContext, this, this.InterfaceType, this.MethodName, this, base.WorkflowInstanceId);
            }
            return(ActivityExecutionStatus.Executing);
        }
Ejemplo n.º 9
0
        private void ProcessMessage(ActivityExecutionContext context, object msg, Type interfaceType, string operation)
        {
            IMethodMessage message = msg as IMethodMessage;

            if (message == null)
            {
                Exception exception = msg as Exception;
                if (exception != null)
                {
                    throw exception;
                }
                throw new ArgumentNullException("msg");
            }
            CorrelationService.InvalidateCorrelationToken(this, interfaceType, operation, message.Args);
            IdentityContextData data = (IdentityContextData)message.LogicalCallContext.GetData("__identitycontext__");

            InboundActivityHelper.ValidateRoles(this, data.Identity);
            this.ProcessParameters(context, message, interfaceType, operation);
            base.RaiseEvent(InputReceivedEvent, this, EventArgs.Empty);
        }
        internal static ActivityExecutionStatus ExecuteForActivity(HandleExternalEventActivity activity, ActivityExecutionContext context, Type interfaceType, string operation, out object[] args)
        {
            WorkflowQueuingService queueSvcs = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService));

            args = null;
            IComparable queueId = CorrelationService.ResolveQueueName(activity, interfaceType, operation);

            if (queueId != null)
            {
                WorkflowQueue queue;
                object        msg = DequeueMessage(queueId, queueSvcs, activity, out queue);
                CorrelationService.UninitializeFollowers(interfaceType, operation, queue);
                if (msg != null)
                {
                    args = ProcessEvent(activity, context, msg, interfaceType, operation);
                    return(ActivityExecutionStatus.Closed);
                }
            }
            return(ActivityExecutionStatus.Executing);
        }
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            object[] args = null;
            ActivityExecutionStatus status = InboundActivityHelper.ExecuteForActivity(this, executionContext, this.InterfaceType, this.EventName, out args);

            if (status == ActivityExecutionStatus.Closed)
            {
                this.RaiseEvent(args);
                this.UnsubscribeForActivity(executionContext);
                executionContext.CloseActivity();
                return(status);
            }
            if (!this.ActivitySubscribed)
            {
                this.ActivitySubscribed = CorrelationService.Subscribe(executionContext, this, this.InterfaceType, this.EventName, this, base.WorkflowInstanceId);
            }
            return(ActivityExecutionStatus.Executing);
        }
Ejemplo n.º 12
0
        protected sealed override void Initialize(IServiceProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            //When activity is dropped inside multi instance container(replicator)
            //We delay CorrelationService initialization to template initialization time.
            if ((!this.IsDynamicActivity && !IsNestedUnderMultiInstanceContainer) || IsInitializingUnderMultiInstanceContainer)
            {
                Type        type      = this.InterfaceType;
                string      eventName = this.EventName;
                IComparable queueName = null;
                if (CorrelationResolver.IsInitializingMember(type, eventName, null))
                {
                    queueName = new EventQueueName(type, eventName);
                }
                this.SetValue(QueueNameProperty, queueName);

                CorrelationService.Initialize(provider, this, type, eventName, this.WorkflowInstanceId);
            }
        }