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

            return(subscription != null);
        }
        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);
        }
        private StateMachineSubscription SubscribeEventActivity(ActivityExecutionContext context, IEventActivity eventActivity)
        {
            EventActivitySubscription subscription = new EventActivitySubscription();
            StateActivity             state        = (StateActivity)context.Activity;

            subscription.Subscribe(context, state, eventActivity);
            WorkflowQueue workflowQueue = GetWorkflowQueue(context, subscription.QueueName);

            if (workflowQueue != null)
            {
                workflowQueue.Enabled = true;
            }
            this.Subscriptions[subscription.QueueName] = subscription;
            return(subscription);
        }
        private EventActivitySubscription GetSubscription(IEventActivity eventActivity)
        {
            IComparable queueName = GetQueueName(eventActivity);

            if ((queueName != null) && this.Subscriptions.ContainsKey(queueName))
            {
                EventActivitySubscription subscription = this.Subscriptions[queueName] as EventActivitySubscription;
                Activity activity = (Activity)eventActivity;
                if ((subscription != null) && !(subscription.EventActivityName != activity.QualifiedName))
                {
                    return(subscription);
                }
            }
            return(null);
        }
        private void UnsubscribeEventActivity(ActivityExecutionContext context, IEventActivity eventActivity)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (eventActivity == null)
            {
                throw new ArgumentNullException("eventActivity");
            }
            EventActivitySubscription subscription  = this.GetSubscription(eventActivity);
            WorkflowQueue             workflowQueue = GetWorkflowQueue(context, subscription.QueueName);

            if (workflowQueue != null)
            {
                workflowQueue.Enabled = false;
            }
            this.UnsubscribeEventActivity(context, eventActivity, subscription);
        }
示例#6
0
        private void UnsubscribeEventActivity(ActivityExecutionContext context,
                                              IEventActivity eventActivity,
                                              EventActivitySubscription subscription)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (eventActivity == null)
            {
                throw new ArgumentNullException("eventActivity");
            }
            if (subscription == null)
            {
                throw new ArgumentNullException("subscription");
            }

            subscription.Unsubscribe(context, eventActivity);
            RemoveFromQueue(subscription.SubscriptionId);

            Debug.Assert(subscription.QueueName != null);
            this.Subscriptions.Remove(subscription.QueueName);
        }
        private void UnsubscribeEventActivity(ActivityExecutionContext context,
            IEventActivity eventActivity,
            EventActivitySubscription subscription)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (eventActivity == null)
                throw new ArgumentNullException("eventActivity");
            if (subscription == null)
                throw new ArgumentNullException("subscription");

            subscription.Unsubscribe(context, eventActivity);
            RemoveFromQueue(subscription.SubscriptionId);

            Debug.Assert(subscription.QueueName != null);
            this.Subscriptions.Remove(subscription.QueueName);
        }
        private StateMachineSubscription SubscribeEventActivity(ActivityExecutionContext context,
            IEventActivity eventActivity)
        {
            EventActivitySubscription subscription = new EventActivitySubscription();
            StateActivity state = (StateActivity)context.Activity;
            subscription.Subscribe(context, state, eventActivity);
            WorkflowQueue workflowQueue = GetWorkflowQueue(context, subscription.QueueName);
            if (workflowQueue != null)
                workflowQueue.Enabled = true;

            Debug.Assert(subscription.QueueName != null);
            this.Subscriptions[subscription.QueueName] = subscription;

            return subscription;
        }
示例#9
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);
        }