示例#1
0
        private bool IsEventDrivenSubscribed(EventDrivenActivity eventDriven)
        {
            IEventActivity            eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
            EventActivitySubscription subscription  = GetSubscription(eventActivity);

            return(subscription != null);
        }
        internal override void Execute(ActivityExecutionContext context)
        {
            base.Execute(context);
            StateActivity         rootState = StateMachineHelpers.GetRootState(base.State);
            Queue <StateActivity> queue     = new Queue <StateActivity>();

            queue.Enqueue(rootState);
            while (queue.Count > 0)
            {
                foreach (Activity activity3 in queue.Dequeue().EnabledActivities)
                {
                    EventDrivenActivity eventDriven = activity3 as EventDrivenActivity;
                    if (eventDriven != null)
                    {
                        IComparable queueName = StateMachineHelpers.GetEventActivity(eventDriven).QueueName;
                        if (queueName != null)
                        {
                            WorkflowQueue workflowQueue = StateMachineSubscriptionManager.GetWorkflowQueue(context, queueName);
                            if (workflowQueue != null)
                            {
                                workflowQueue.Enabled = base.SubscriptionManager.Subscriptions.ContainsKey(queueName);
                            }
                        }
                    }
                    else
                    {
                        StateActivity item = activity3 as StateActivity;
                        if (item != null)
                        {
                            queue.Enqueue(item);
                        }
                    }
                }
            }
        }
示例#3
0
        internal void UnsubscribeEventDriven(ActivityExecutionContext context, EventDrivenActivity eventDriven)
        {
            Debug.Assert(IsEventDrivenSubscribed(eventDriven));
            IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);

            UnsubscribeEventActivity(context, eventActivity);
        }
        internal void SubscribeEventDriven(ActivityExecutionContext context, EventDrivenActivity eventDriven)
        {
            IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
            Activity       activity1     = (Activity)eventActivity;

            GetQueueName(eventActivity);
            this.SubscribeEventActivity(context, eventActivity);
        }
示例#5
0
        internal void SubscribeEventDriven(ActivityExecutionContext context, EventDrivenActivity eventDriven)
        {
            IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
            Activity       activity      = (Activity)eventActivity;
            IComparable    queueName     = GetQueueName(eventActivity);

            Debug.Assert(!this.Subscriptions.ContainsKey(queueName));
            SubscribeEventActivity(context, eventActivity);
        }
        internal static void ChangeEventDrivenQueueState(ActivityExecutionContext context, EventDrivenActivity eventDriven, bool enabled)
        {
            IComparable queueName = GetQueueName(StateMachineHelpers.GetEventActivity(eventDriven));

            if (queueName != null)
            {
                WorkflowQueue workflowQueue = GetWorkflowQueue(context, queueName);
                if (workflowQueue != null)
                {
                    workflowQueue.Enabled = enabled;
                }
            }
        }
        internal void ReevaluateSubscriptions(ActivityExecutionContext context)
        {
            Dictionary <IComparable, StateMachineSubscription> subscriptionsShallowCopy = this.GetSubscriptionsShallowCopy();
            List <IComparable> list = new List <IComparable>();

            for (StateActivity activity = StateMachineHelpers.GetCurrentState(context); activity != null; activity = activity.Parent as StateActivity)
            {
                foreach (Activity activity2 in activity.EnabledActivities)
                {
                    EventDrivenActivity eventDriven = activity2 as EventDrivenActivity;
                    if (eventDriven != null)
                    {
                        IComparable queueName = StateMachineHelpers.GetEventActivity(eventDriven).QueueName;
                        if (queueName != null)
                        {
                            StateMachineSubscription subscription;
                            subscriptionsShallowCopy.TryGetValue(queueName, out subscription);
                            EventActivitySubscription subscription2 = subscription as EventActivitySubscription;
                            if (subscription2 != null)
                            {
                                if (subscription2.EventDrivenName.Equals(eventDriven.QualifiedName))
                                {
                                    list.Add(queueName);
                                    continue;
                                }
                                if (subscription2.StateName.Equals(activity.QualifiedName))
                                {
                                    throw new InvalidOperationException(SR.GetStateAlreadySubscribesToThisEvent(activity.QualifiedName, queueName));
                                }
                                if (this.IsParentState(activity, subscription2.StateName))
                                {
                                    UnsubscribeAction action = new UnsubscribeAction(subscription2.StateName, subscription2.EventDrivenName);
                                    this.ExecutionState.EnqueueAction(action);
                                    subscriptionsShallowCopy.Remove(queueName);
                                }
                            }
                            if (!list.Contains(queueName))
                            {
                                SubscribeAction action2 = new SubscribeAction(activity.QualifiedName, eventDriven.QualifiedName);
                                this.ExecutionState.EnqueueAction(action2);
                                list.Add(queueName);
                            }
                        }
                    }
                }
            }
            DisableQueuesAction action3 = new DisableQueuesAction(StateMachineHelpers.GetCurrentState(context).QualifiedName);

            this.ExecutionState.EnqueueAction(action3);
        }
示例#8
0
        internal static void ChangeEventDrivenQueueState(ActivityExecutionContext context, EventDrivenActivity eventDriven, bool enabled)
        {
            IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
            IComparable    queueName     = GetQueueName(eventActivity);

            if (queueName == null)
            {
                return; // skip unitialized follower
            }
            WorkflowQueue workflowQueue = GetWorkflowQueue(context, queueName);

            if (workflowQueue != null)
            {
                workflowQueue.Enabled = enabled;
            }
        }
示例#9
0
        internal override void Execute(ActivityExecutionContext context)
        {
            base.Execute(context);

            StateActivity         state     = this.State;
            StateActivity         rootState = StateMachineHelpers.GetRootState(state);
            Queue <StateActivity> states    = new Queue <StateActivity>();

            states.Enqueue(rootState);
            while (states.Count > 0)
            {
                state = states.Dequeue();
                foreach (Activity activity in state.EnabledActivities)
                {
                    EventDrivenActivity eventDriven = activity as EventDrivenActivity;
                    if (eventDriven != null)
                    {
                        IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
                        IComparable    queueName     = eventActivity.QueueName;
                        if (queueName != null)
                        {
                            WorkflowQueue queue = StateMachineSubscriptionManager.GetWorkflowQueue(context, queueName);
                            if (queue != null)
                            {
                                queue.Enabled = this.SubscriptionManager.Subscriptions.ContainsKey(queueName);
                            }
                        }
                    }
                    else
                    {
                        StateActivity childState = activity as StateActivity;
                        if (childState != null)
                        {
                            states.Enqueue(childState);
                        }
                    }
                }
            }
        }
        internal void UnsubscribeEventDriven(ActivityExecutionContext context, EventDrivenActivity eventDriven)
        {
            IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);

            this.UnsubscribeEventActivity(context, eventActivity);
        }
示例#11
0
        internal void ReevaluateSubscriptions(ActivityExecutionContext context)
        {
            Dictionary <IComparable, StateMachineSubscription> subscriptions = this.GetSubscriptionsShallowCopy();
            List <IComparable> subscribed = new List <IComparable>();

            StateActivity state = StateMachineHelpers.GetCurrentState(context);

            while (state != null)
            {
                foreach (Activity activity in state.EnabledActivities)
                {
                    EventDrivenActivity eventDriven = activity as EventDrivenActivity;
                    if (eventDriven == null)
                    {
                        continue;
                    }

                    IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
                    IComparable    queueName     = eventActivity.QueueName;
                    if (queueName == null)
                    {
                        continue;
                    }

                    StateMachineSubscription subscription;
                    subscriptions.TryGetValue(queueName, out subscription);
                    EventActivitySubscription eventActivitySubscription = subscription as EventActivitySubscription;
                    if (eventActivitySubscription != null)
                    {
                        if (eventActivitySubscription.EventDrivenName.Equals(eventDriven.QualifiedName))
                        {
                            // this EventDriven is already subscribed
                            subscribed.Add(queueName);
                            continue;
                        }
                        else
                        {
                            // Check if this state already subscribe to this event
                            // if so, throws, since it is not valid to subscribe to the
                            // same event twice
                            if (eventActivitySubscription.StateName.Equals(state.QualifiedName))
                            {
                                throw new InvalidOperationException(SR.GetStateAlreadySubscribesToThisEvent(state.QualifiedName, queueName));
                            }

                            // some other EventDriven is subscribed, so we need to unsubscribe if
                            // the event driven belongs to one of our parents
                            if (IsParentState(state, eventActivitySubscription.StateName))
                            {
                                UnsubscribeAction unsubscribe = new UnsubscribeAction(eventActivitySubscription.StateName, eventActivitySubscription.EventDrivenName);
                                this.ExecutionState.EnqueueAction(unsubscribe);
                                subscriptions.Remove(queueName);
                            }
                        }
                    }

                    // Tests if a child state already subscribes to this event
                    // is so, skip, since the child takes precedence
                    if (subscribed.Contains(queueName))
                    {
                        continue;
                    }

                    SubscribeAction subscribe = new SubscribeAction(state.QualifiedName, eventDriven.QualifiedName);
                    this.ExecutionState.EnqueueAction(subscribe);
                    subscribed.Add(queueName);
                }

                state = state.Parent as StateActivity;
            }

            StateActivity       currentState  = StateMachineHelpers.GetCurrentState(context);
            DisableQueuesAction disableQueues = new DisableQueuesAction(currentState.QualifiedName);

            this.ExecutionState.EnqueueAction(disableQueues);
        }