Esempio n. 1
0
        protected sealed override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (removedActivity == null)
            {
                throw new ArgumentNullException("removedActivity");
            }
            ListenActivity activity = executionContext.Activity as ListenActivity;

            if (((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && (activity.ActivityState != null)) && !activity.IsListenTrigerred)
            {
                EventDrivenActivity activity2 = removedActivity as EventDrivenActivity;
                for (int i = 0; i < activity.ActivityState.Count; i++)
                {
                    ListenEventActivitySubscriber parentEventHandler = activity.ActivityState[i];
                    if (parentEventHandler.eventDrivenActivity.QualifiedName.Equals(activity2.QualifiedName))
                    {
                        activity2.EventActivity.Unsubscribe(executionContext, parentEventHandler);
                        activity.ActivityState.RemoveAt(i);
                        return;
                    }
                }
            }
            else if (this.IsListenTrigerred && (removedActivity.ExecutionStatus == ActivityExecutionStatus.Closed))
            {
                this.activeBranchRemoved = true;
            }
        }
Esempio n. 2
0
            void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
            {
                if (sender == null)
                {
                    throw new ArgumentNullException("sender");
                }
                if (e == null)
                {
                    throw new ArgumentNullException("e");
                }
                ActivityExecutionContext parentContext = sender as ActivityExecutionContext;

                if (parentContext == null)
                {
                    throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender");
                }
                ListenActivity activityStatusChangeListener = parentContext.Activity as ListenActivity;

                if (((!activityStatusChangeListener.IsListenTrigerred && (activityStatusChangeListener.ExecutionStatus != ActivityExecutionStatus.Canceling)) && (activityStatusChangeListener.ExecutionStatus != ActivityExecutionStatus.Closed)) && activityStatusChangeListener.EnabledActivities.Contains(this.eventDrivenActivity))
                {
                    activityStatusChangeListener.IsListenTrigerred = true;
                    for (int i = 0; i < activityStatusChangeListener.EnabledActivities.Count; i++)
                    {
                        EventDrivenActivity activity2 = activityStatusChangeListener.EnabledActivities[i] as EventDrivenActivity;
                        ListenActivity.ListenEventActivitySubscriber parentEventHandler = activityStatusChangeListener.ActivityState[i];
                        activity2.EventActivity.Unsubscribe(parentContext, parentEventHandler);
                    }
                    this.eventDrivenActivity.RegisterForStatusChange(Activity.ClosedEvent, activityStatusChangeListener);
                    parentContext.ExecuteActivity(this.eventDrivenActivity);
                }
            }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));

            ListenActivity listen = obj as ListenActivity;

            if (listen == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(ListenActivity).FullName), "obj");
            }

            // Validate number of children
            if (listen.EnabledActivities.Count < 2)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ListenLessThanTwoChildren), ErrorNumbers.Error_ListenLessThanTwoChildren));
            }

            bool bNotAllEventDriven = false;

            foreach (Activity activity in listen.EnabledActivities)
            {
                if (!(activity is EventDrivenActivity))
                {
                    bNotAllEventDriven = true;
                }
            }

            // validate that all child activities are event driven activities.
            if (bNotAllEventDriven)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ListenNotAllEventDriven), ErrorNumbers.Error_ListenNotAllEventDriven));
            }

            return(validationErrors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors   = new ValidationErrorCollection(base.Validate(manager, obj));
            ListenActivity            activity = obj as ListenActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ListenActivity).FullName }), "obj");
            }
            if (activity.EnabledActivities.Count < 2)
            {
                errors.Add(new ValidationError(SR.GetString("Error_ListenLessThanTwoChildren"), 0x513));
            }
            bool flag = false;

            foreach (Activity activity2 in activity.EnabledActivities)
            {
                if (!(activity2 is EventDrivenActivity))
                {
                    flag = true;
                }
            }
            if (flag)
            {
                errors.Add(new ValidationError(SR.GetString("Error_ListenNotAllEventDriven"), 0x514));
            }
            return(errors);
        }
        protected override sealed void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (removedActivity == null)
            {
                throw new ArgumentNullException("removedActivity");
            }

            ListenActivity listen = executionContext.Activity as ListenActivity;

            if (listen.ExecutionStatus == ActivityExecutionStatus.Executing && listen.ActivityState != null && !listen.IsListenTrigerred)
            {
                EventDrivenActivity eda = removedActivity as EventDrivenActivity;

                for (int i = 0; i < listen.ActivityState.Count; ++i)
                {
                    ListenEventActivitySubscriber listenEventSubscriber = listen.ActivityState[i];

                    if (listenEventSubscriber.eventDrivenActivity.QualifiedName.Equals(eda.QualifiedName))
                    {
                        eda.EventActivity.Unsubscribe(executionContext, listenEventSubscriber);
                        listen.ActivityState.RemoveAt(i);
                        return;
                    }
                }
            }
            else if (this.IsListenTrigerred && removedActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
            {
                activeBranchRemoved = true;
            }
        }
Esempio n. 6
0
        protected override IComponent[] CreateComponentsCore(IDesignerHost designerHost)
        {
            CompositeActivity activity = new ListenActivity {
                Activities = { new EventDrivenActivity(), new EventDrivenActivity() }
            };

            return(new IComponent[] { activity });
        }
Esempio n. 7
0
        protected override IComponent[] CreateComponentsCore(IDesignerHost designerHost)
        {
            CompositeActivity listenActivity = new ListenActivity();

            listenActivity.Activities.Add(new EventDrivenActivity());
            listenActivity.Activities.Add(new EventDrivenActivity());
            return((IComponent[])new IComponent[] { listenActivity });
        }
Esempio n. 8
0
        protected sealed override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (addedActivity == null)
            {
                throw new ArgumentNullException("addedActivity");
            }
            ListenActivity activity = executionContext.Activity as ListenActivity;

            if (((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && (activity.ActivityState != null)) && !activity.IsListenTrigerred)
            {
                EventDrivenActivity           eventDriven        = addedActivity as EventDrivenActivity;
                ListenEventActivitySubscriber parentEventHandler = new ListenEventActivitySubscriber(eventDriven);
                eventDriven.EventActivity.Subscribe(executionContext, parentEventHandler);
                activity.ActivityState.Insert(activity.EnabledActivities.IndexOf(addedActivity), parentEventHandler);
            }
        }
            void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
            {
                if (sender == null)
                {
                    throw new ArgumentNullException("sender");
                }
                if (e == null)
                {
                    throw new ArgumentNullException("e");
                }

                ActivityExecutionContext context = sender as ActivityExecutionContext;

                if (context == null)
                {
                    throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender");
                }

                ListenActivity parentActivity = context.Activity as ListenActivity;

                if (!parentActivity.IsListenTrigerred && parentActivity.ExecutionStatus != ActivityExecutionStatus.Canceling && parentActivity.ExecutionStatus != ActivityExecutionStatus.Closed)
                {
                    //Check whether it is still live in tree.
                    if (!parentActivity.EnabledActivities.Contains(eventDrivenActivity))//Activity is dynamically removed.
                    {
                        return;
                    }

                    parentActivity.IsListenTrigerred = true;

                    for (int i = 0; i < parentActivity.EnabledActivities.Count; ++i)
                    {
                        EventDrivenActivity           eventDriven     = parentActivity.EnabledActivities[i] as EventDrivenActivity;
                        ListenEventActivitySubscriber eventSubscriber = parentActivity.ActivityState[i];
                        eventDriven.EventActivity.Unsubscribe(context, eventSubscriber);
                    }

                    eventDrivenActivity.RegisterForStatusChange(Activity.ClosedEvent, parentActivity);
                    context.ExecuteActivity(eventDrivenActivity);
                }
            }
Esempio n. 10
0
        protected override sealed void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (addedActivity == null)
            {
                throw new ArgumentNullException("addedActivity");
            }

            Debug.Assert(addedActivity is EventDrivenActivity, "Listen only contains EventDriven activities");

            ListenActivity listen = executionContext.Activity as ListenActivity;

            if (listen.ExecutionStatus == ActivityExecutionStatus.Executing && listen.ActivityState != null && !listen.IsListenTrigerred)
            {
                EventDrivenActivity           eda = addedActivity as EventDrivenActivity;
                ListenEventActivitySubscriber eventActivitySubscriber = new ListenEventActivitySubscriber(eda);
                eda.EventActivity.Subscribe(executionContext, eventActivitySubscriber);
                listen.ActivityState.Insert(listen.EnabledActivities.IndexOf(addedActivity), eventActivitySubscriber);
            }
        }