private void NotifyChangesToChildExecutors(IWorkflowCoreRuntime workflowCoreRuntime, Activity contextActivity, IList <WorkflowChangeAction> changeActions)
        {
            foreach (WorkflowChangeAction action in changeActions)
            {
                if (!(action is ActivityChangeAction))
                {
                    continue;
                }

                CompositeActivity ownerActivity = contextActivity.TraverseDottedPathFromRoot(((ActivityChangeAction)action).OwnerActivityDottedPath) as CompositeActivity;
                if (ownerActivity == null || !WorkflowChanges.IsActivityExecutable(ownerActivity))
                {
                    continue;
                }

                ISupportWorkflowChanges compositeActivityExecutor = ActivityExecutors.GetActivityExecutor(ownerActivity) as ISupportWorkflowChanges;
                if (compositeActivityExecutor == null)
                {
                    throw new ApplicationException(SR.GetString(SR.Error_WorkflowChangesNotSupported, ownerActivity.GetType().FullName));
                }

                using (workflowCoreRuntime.SetCurrentActivity(ownerActivity))
                {
                    using (ActivityExecutionContext executionContext = new ActivityExecutionContext(ownerActivity))
                    {
                        if (action is AddedActivityAction)
                        {
                            Activity addedActivity = ownerActivity.Activities[((AddedActivityAction)action).Index];
                            if (WorkflowChanges.IsActivityExecutable(addedActivity))
                            {
                                addedActivity.OnActivityExecutionContextLoad(executionContext.Activity.RootActivity.WorkflowCoreRuntime);
                                executionContext.InitializeActivity(addedActivity);
                                compositeActivityExecutor.OnActivityAdded(executionContext, addedActivity);
                            }
                        }
                        else if (action is RemovedActivityAction)
                        {
                            RemovedActivityAction removedActivityAction = (RemovedActivityAction)action;
                            if (WorkflowChanges.IsActivityExecutable(removedActivityAction.OriginalRemovedActivity))
                            {
                                compositeActivityExecutor.OnActivityRemoved(executionContext, removedActivityAction.OriginalRemovedActivity);
                                if (removedActivityAction.OriginalRemovedActivity.ExecutionResult != ActivityExecutionResult.Uninitialized)
                                {
                                    removedActivityAction.OriginalRemovedActivity.Uninitialize(executionContext.Activity.RootActivity.WorkflowCoreRuntime);
                                    removedActivityAction.OriginalRemovedActivity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized);
                                }
                                removedActivityAction.OriginalRemovedActivity.OnActivityExecutionContextUnload(executionContext.Activity.RootActivity.WorkflowCoreRuntime);
                                removedActivityAction.OriginalRemovedActivity.Dispose();
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 private void NotifyChangesToChildExecutors(IWorkflowCoreRuntime workflowCoreRuntime, Activity contextActivity, IList <WorkflowChangeAction> changeActions)
 {
     foreach (WorkflowChangeAction action in changeActions)
     {
         if (action is ActivityChangeAction)
         {
             CompositeActivity activity = contextActivity.TraverseDottedPathFromRoot(((ActivityChangeAction)action).OwnerActivityDottedPath) as CompositeActivity;
             if ((activity != null) && IsActivityExecutable(activity))
             {
                 ISupportWorkflowChanges activityExecutor = ActivityExecutors.GetActivityExecutor(activity) as ISupportWorkflowChanges;
                 if (activityExecutor == null)
                 {
                     throw new ApplicationException(SR.GetString("Error_WorkflowChangesNotSupported", new object[] { activity.GetType().FullName }));
                 }
                 using (workflowCoreRuntime.SetCurrentActivity(activity))
                 {
                     using (ActivityExecutionContext context = new ActivityExecutionContext(activity))
                     {
                         if (action is AddedActivityAction)
                         {
                             Activity activity2 = activity.Activities[((AddedActivityAction)action).Index];
                             if (IsActivityExecutable(activity2))
                             {
                                 activity2.OnActivityExecutionContextLoad(context.Activity.RootActivity.WorkflowCoreRuntime);
                                 context.InitializeActivity(activity2);
                                 activityExecutor.OnActivityAdded(context, activity2);
                             }
                         }
                         else if (action is RemovedActivityAction)
                         {
                             RemovedActivityAction action2 = (RemovedActivityAction)action;
                             if (IsActivityExecutable(action2.OriginalRemovedActivity))
                             {
                                 activityExecutor.OnActivityRemoved(context, action2.OriginalRemovedActivity);
                                 if (action2.OriginalRemovedActivity.ExecutionResult != ActivityExecutionResult.Uninitialized)
                                 {
                                     action2.OriginalRemovedActivity.Uninitialize(context.Activity.RootActivity.WorkflowCoreRuntime);
                                     action2.OriginalRemovedActivity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized);
                                 }
                                 action2.OriginalRemovedActivity.OnActivityExecutionContextUnload(context.Activity.RootActivity.WorkflowCoreRuntime);
                                 action2.OriginalRemovedActivity.Dispose();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
        private static List<SerialisableActivityRemovedAction> buildSerialisableRemovedActivityAction(RemovedActivityAction action, int order)
        {
            List<SerialisableActivityRemovedAction> removedActivities = new List<SerialisableActivityRemovedAction>();

            Queue<Activity> activityQueue = new Queue<Activity>();
            activityQueue.Enqueue(action.OriginalRemovedActivity);
            while (activityQueue.Count > 0)
            {
                // is this the first record?
                Activity currentActivity = activityQueue.Dequeue();
                if (currentActivity == action.OriginalRemovedActivity)
                {
                    removedActivities.Add(new SerialisableActivityRemovedAction(
                        currentActivity.GetType(), currentActivity.QualifiedName,
                        currentActivity.Parent == null ? null : currentActivity.Parent.QualifiedName,
                        order, WorkflowInstanceHelper.GetXomlDocument(currentActivity)));
                }
                else
                {
                    removedActivities.Add(new SerialisableActivityRemovedAction(
                        currentActivity.GetType(), currentActivity.QualifiedName,
                        currentActivity.Parent == null ? null : currentActivity.Parent.QualifiedName,
                        -1, WorkflowInstanceHelper.GetXomlDocument(currentActivity)));
                }

                CompositeActivity parentActivity = currentActivity as CompositeActivity;
                if (parentActivity != null)
                {
                    foreach (Activity childActivity in parentActivity.Activities)
                        activityQueue.Enqueue(childActivity);
                }
            }

            return removedActivities;
        }