internal static bool ContainsEventActivity(CompositeActivity compositeActivity)
 {
     Queue<Activity> queue = new Queue<Activity>();
     queue.Enqueue(compositeActivity);
     while (queue.Count > 0)
     {
         Activity activity = queue.Dequeue();
         if (activity is IEventActivity)
         {
             return true;
         }
         compositeActivity = activity as CompositeActivity;
         if (compositeActivity != null)
         {
             foreach (Activity activity2 in compositeActivity.Activities)
             {
                 if (activity2.Enabled)
                 {
                     queue.Enqueue(activity2);
                 }
             }
         }
     }
     return false;
 }
 private static bool CollectCompensatableTargetActivities(CompositeActivity compositeActivity, SortedDictionary<int, CompensationInfo> sortedListOfCompensatableTargets, bool immediateCompensation)
 {
     Queue<Activity> queue = new Queue<Activity>(Helpers.GetAllEnabledActivities(compositeActivity));
     while (queue.Count > 0)
     {
         Activity childActivity = queue.Dequeue();
         if (((childActivity.ExecutionStatus == ActivityExecutionStatus.Compensating) || (childActivity.ExecutionStatus == ActivityExecutionStatus.Faulting)) || (childActivity.ExecutionStatus == ActivityExecutionStatus.Canceling))
         {
             return true;
         }
         if (!immediateCompensation || !IsActivityInBackWorkBranch(compositeActivity, childActivity))
         {
             if (((childActivity is ICompensatableActivity) && (childActivity.ExecutionStatus == ActivityExecutionStatus.Closed)) && (childActivity.ExecutionResult == ActivityExecutionResult.Succeeded))
             {
                 sortedListOfCompensatableTargets.Add((int) childActivity.GetValue(Activity.CompletedOrderIdProperty), new CompensationInfo(childActivity));
             }
             else if (childActivity is CompositeActivity)
             {
                 foreach (Activity activity2 in Helpers.GetAllEnabledActivities((CompositeActivity) childActivity))
                 {
                     queue.Enqueue(activity2);
                 }
                 continue;
             }
         }
     }
     return false;
 }
Exemplo n.º 3
0
        public static ActivityExecutionStatus Cancel(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            for (int i = (activity.EnabledActivities.Count - 1); i >= 0; i--)
            {
                Activity childActivity = activity.EnabledActivities[i];

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(childActivity);
                    return activity.ExecutionStatus;
                }

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Canceling ||
                    childActivity.ExecutionStatus == ActivityExecutionStatus.Faulting)
                {
                    return activity.ExecutionStatus;
                }

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    activity.RemoveProperty(ActiveChildQualifiedNameProperty);
                    return ActivityExecutionStatus.Closed;
                }
            }
            return ActivityExecutionStatus.Closed;
        }
            public DesignerLayoutConnectionPoint(ActivityDesigner associatedDesigner, int connectionIndex, CompositeActivity eventHandler, DesignerEdges designerEdges)
                : base(associatedDesigner, designerEdges, connectionIndex)
            {
                Debug.Assert(designerEdges == DesignerEdges.Left || designerEdges == DesignerEdges.Right);
                _eventHandler = eventHandler;
                _designerEdges = designerEdges;

            }
 private static bool ValidateParent(CompositeActivity parentActivity)
 {
     if (parentActivity == null)
     {
         return false;
     }
     return (SetStateValidator.IsValidContainer(parentActivity) || ValidateParent(parentActivity.Parent));
 }
 public static void OnActivityChangeRemove(CompositeActivity activity, ActivityExecutionContext executionContext, Activity removedActivity)
 {
     string str = activity.GetValue(ActiveChildQualifiedNameProperty) as string;
     if (removedActivity.QualifiedName.Equals(str))
     {
         activity.SetValue(ActiveChildRemovedProperty, true);
     }
 }
 private static RuleDefinitions GetRuleDefinitions(Activity activity, out CompositeActivity declaringActivity)
 {
     declaringActivity = Helpers.GetDeclaringActivity(activity);
     if (declaringActivity == null)
     {
         declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity;
     }
     return ConditionHelper.Load_Rules_RT(declaringActivity);
 }
Exemplo n.º 8
0
        public static void OnActivityChangeRemove(CompositeActivity activity, ActivityExecutionContext executionContext, Activity removedActivity)
        {
            String activeChildQualifiedName = activity.GetValue(ActiveChildQualifiedNameProperty) as String;

            if (removedActivity.QualifiedName.Equals(activeChildQualifiedName))
            {
                activity.SetValue(ActiveChildRemovedProperty, true);
            }
        }
Exemplo n.º 9
0
        protected ActivityChangeAction(CompositeActivity compositeActivity)
        {
            if (compositeActivity == null)
            {
                throw new ArgumentNullException("compositeActivity");
            }

            this.ownerActivityDottedPath = compositeActivity.DottedPath;
        }
 protected ActivityChangeAction(CompositeActivity compositeActivity)
 {
     this.ownerActivityDottedPath = string.Empty;
     if (compositeActivity == null)
     {
         throw new ArgumentNullException("compositeActivity");
     }
     this.ownerActivityDottedPath = compositeActivity.DottedPath;
 }
Exemplo n.º 11
0
        public ActivityCollection(Activity owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("Owner cannot be null");
            }

            this.owner = (CompositeActivity)owner;
        }
 internal TransitionInfo(SetStateActivity setState, CompositeActivity eventHandler)
 {
     if (setState == null)
         throw new ArgumentNullException("setState");
     if (eventHandler == null)
         throw new ArgumentNullException("eventHandler");
     _setState = setState;
     _eventHandler = eventHandler;
 }
Exemplo n.º 13
0
 internal static Activity GetLastCompensatableChild(CompositeActivity compositeActivity)
 {
     Activity[] compensatableChildren = GetCompensatableChildren(compositeActivity);
     if (((compensatableChildren != null) && (compensatableChildren.Length > 0)) && (compensatableChildren[compensatableChildren.Length - 1] != null))
     {
         return(compensatableChildren[compensatableChildren.Length - 1]);
     }
     return(null);
 }
 public static void OnEvent(CompositeActivity activity, object sender, ActivityExecutionStatusChangedEventArgs e)
 {
     ActivityExecutionContext executionContext = sender as ActivityExecutionContext;
     e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>) activity);
     if (((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)) || ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && !TryScheduleNextChild(activity, executionContext)))
     {
         activity.RemoveProperty(ActiveChildQualifiedNameProperty);
         executionContext.CloseActivity();
     }
 }
        internal static Activity GetLastCompensatableChild(CompositeActivity compositeActivity)
        {
            Activity[] activities = CompensationUtils.GetCompensatableChildren(compositeActivity);
            if (activities != null && activities.Length > 0 && activities[activities.Length - 1] != null)
            {
                return(activities[activities.Length - 1]);
            }

            return(null);
        }
        public static void OnEvent(CompositeActivity activity, object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            ActivityExecutionContext executionContext = sender as ActivityExecutionContext;

            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener <ActivityExecutionStatusChangedEventArgs>)activity);
            if (((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)) || ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && !TryScheduleNextChild(activity, executionContext)))
            {
                activity.RemoveProperty(ActiveChildQualifiedNameProperty);
                executionContext.CloseActivity();
            }
        }
 public static ActivityExecutionStatus Execute(CompositeActivity activity, ActivityExecutionContext executionContext)
 {
     if (activity.EnabledActivities.Count == 0)
     {
         return(ActivityExecutionStatus.Closed);
     }
     activity.EnabledActivities[0].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener <ActivityExecutionStatusChangedEventArgs>)activity);
     executionContext.ExecuteActivity(activity.EnabledActivities[0]);
     activity.SetValue(ActiveChildQualifiedNameProperty, activity.EnabledActivities[0].QualifiedName);
     return(ActivityExecutionStatus.Executing);
 }
Exemplo n.º 18
0
        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();
                            }
                        }
                    }
                }
            }
        }
 public static void OnWorkflowChangesCompleted(CompositeActivity activity, ActivityExecutionContext executionContext)
 {
     string str = activity.GetValue(ActiveChildQualifiedNameProperty) as string;
     bool flag = (bool) activity.GetValue(ActiveChildRemovedProperty);
     if (((str != null) && flag) && (((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)) || ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && !TryScheduleNextChild(activity, executionContext))))
     {
         activity.RemoveProperty(ActiveChildQualifiedNameProperty);
         executionContext.CloseActivity();
     }
     activity.RemoveProperty(ActiveChildRemovedProperty);
 }
 public static ActivityExecutionStatus Execute(CompositeActivity activity, ActivityExecutionContext executionContext)
 {
     if (activity.EnabledActivities.Count == 0)
     {
         return ActivityExecutionStatus.Closed;
     }
     activity.EnabledActivities[0].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>) activity);
     executionContext.ExecuteActivity(activity.EnabledActivities[0]);
     activity.SetValue(ActiveChildQualifiedNameProperty, activity.EnabledActivities[0].QualifiedName);
     return ActivityExecutionStatus.Executing;
 }
        public static void OnWorkflowChangesCompleted(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            string str  = activity.GetValue(ActiveChildQualifiedNameProperty) as string;
            bool   flag = (bool)activity.GetValue(ActiveChildRemovedProperty);

            if (((str != null) && flag) && (((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)) || ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && !TryScheduleNextChild(activity, executionContext))))
            {
                activity.RemoveProperty(ActiveChildQualifiedNameProperty);
                executionContext.CloseActivity();
            }
            activity.RemoveProperty(ActiveChildRemovedProperty);
        }
 private static bool CannotModifyChildren(CompositeActivity compositeActivity, bool parent)
 {
     if (compositeActivity == null)
     {
         throw new ArgumentNullException("compositeActivity");
     }
     if (parent && (compositeActivity.Parent == null))
     {
         return false;
     }
     return (((bool) compositeActivity.GetValue(Activity.CustomActivityProperty)) || ((compositeActivity.Parent != null) && CannotModifyChildren(compositeActivity.Parent, parent)));
 }
Exemplo n.º 23
0
 private CompositeActivity GetRootWorkflow(CompositeActivity activity)
 {
     if (activity.Parent != null)
     {
         CompositeActivity workflow = GetRootWorkflow(activity.Parent);
         return workflow;
     }
     else
     {
         return activity;
     }
 }
Exemplo n.º 24
0
 private static bool CannotModifyChildren(CompositeActivity compositeActivity, bool parent)
 {
     if (compositeActivity == null)
     {
         throw new ArgumentNullException("compositeActivity");
     }
     if (parent && (compositeActivity.Parent == null))
     {
         return(false);
     }
     return(((bool)compositeActivity.GetValue(Activity.CustomActivityProperty)) || ((compositeActivity.Parent != null) && CannotModifyChildren(compositeActivity.Parent, parent)));
 }
 public AddedActivityAction(CompositeActivity compositeActivity, Activity activityAdded) : base(compositeActivity)
 {
     if (compositeActivity == null)
     {
         throw new ArgumentNullException("compositeActivity");
     }
     if (activityAdded == null)
     {
         throw new ArgumentNullException("activityAdded");
     }
     this.index         = (compositeActivity.Activities != null) ? compositeActivity.Activities.IndexOf(activityAdded) : -1;
     this.addedActivity = activityAdded;
 }
 public AddedActivityAction(CompositeActivity compositeActivity, Activity activityAdded) : base(compositeActivity)
 {
     if (compositeActivity == null)
     {
         throw new ArgumentNullException("compositeActivity");
     }
     if (activityAdded == null)
     {
         throw new ArgumentNullException("activityAdded");
     }
     this.index = (compositeActivity.Activities != null) ? compositeActivity.Activities.IndexOf(activityAdded) : -1;
     this.addedActivity = activityAdded;
 }
Exemplo n.º 27
0
        void IIdentifierCreationService.EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities)
        {
            if (parentActivity == null)
                throw new ArgumentNullException("parentActivity");
            if (childActivities == null)
                throw new ArgumentNullException("childActivities");

            ArrayList allActivities = new ArrayList();

            Queue activities = new Queue(childActivities);
            while (activities.Count > 0)
            {
                Activity activity = (Activity)activities.Dequeue();
                if (activity is CompositeActivity)
                {
                    foreach (Activity child in ((CompositeActivity)activity).Activities)
                        activities.Enqueue(child);
                }

                //If we are moving activities, we need not regenerate their identifiers
                if (((IComponent)activity).Site != null)
                    continue;

                allActivities.Add(activity);
            }

            // get the root activity
            CompositeActivity rootActivity = GetRootActivity(parentActivity) as CompositeActivity;
            ArrayList identifiers = new ArrayList(); // all the identifiers in the workflow
            identifiers.AddRange(GetIdentifiersInCompositeActivity(rootActivity));

            foreach (Activity activity in allActivities)
            {
                string finalIdentifier = activity.Name;

                // now loop until we find a identifier that hasn't been used.
                string baseIdentifier = GetBaseIdentifier(activity);
                int index = 0;

                identifiers.Sort();
                while (finalIdentifier == null || finalIdentifier.Length == 0 || identifiers.BinarySearch(finalIdentifier.ToLower(CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) >= 0)
                {
                    finalIdentifier = string.Format("{0}{1}", baseIdentifier, ++index);
                }

                // add new identifier to collection 
                identifiers.Add(finalIdentifier);
                activity.Name = finalIdentifier;
            }
        }
 public RemovedActivityAction(int removedActivityIndex, Activity originalActivity, CompositeActivity clonedParentActivity) : base(clonedParentActivity)
 {
     this.removedActivityIndex = -1;
     if (originalActivity == null)
     {
         throw new ArgumentNullException("originalActivity");
     }
     if (clonedParentActivity == null)
     {
         throw new ArgumentNullException("clonedParentActivity");
     }
     this.originalRemovedActivity = originalActivity;
     this.removedActivityIndex = removedActivityIndex;
 }
        void ISupportWorkflowChanges.OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            CompositeActivity activity = executionContext.Activity as CompositeActivity;

            if (activity == null)
            {
                throw new ArgumentException("Error_InvalidActivityExecutionContext", "executionContext");
            }
            activity.OnWorkflowChangesCompleted(executionContext);
        }
Exemplo n.º 30
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();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 31
0
        internal static CompositeActivity GetFaultHandlers(Activity activityWithExceptionHandlers)
        {
            CompositeActivity activity2 = activityWithExceptionHandlers as CompositeActivity;

            if (activity2 != null)
            {
                foreach (Activity activity3 in ((ISupportAlternateFlow)activity2).AlternateFlowActivities)
                {
                    if (activity3 is FaultHandlersActivity)
                    {
                        return(activity3 as CompositeActivity);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 32
0
 private static bool IsDynamicMode(CompositeActivity compositeActivity)
 {
     if (compositeActivity == null)
     {
         throw new ArgumentNullException("compositeActivity");
     }
     while (compositeActivity.Parent != null)
     {
         if (compositeActivity.DynamicUpdateMode)
         {
             return(true);
         }
         compositeActivity = compositeActivity.Parent;
     }
     return(compositeActivity.DynamicUpdateMode);
 }
        internal static Activity GetCompensationHandler(Activity activityWithCompensation)
        {
            CompositeActivity activity2 = activityWithCompensation as CompositeActivity;

            if (activity2 != null)
            {
                foreach (Activity activity3 in ((ISupportAlternateFlow)activity2).AlternateFlowActivities)
                {
                    if (activity3 is CompensationHandlerActivity)
                    {
                        return(activity3);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 34
0
        internal static string GenerateQualifiedNameForLockedActivity(Activity activity, string id)
        {
            StringBuilder     builder           = new StringBuilder();
            string            str               = string.IsNullOrEmpty(id) ? activity.Name : id;
            CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(activity);

            if (declaringActivity != null)
            {
                builder.Append(declaringActivity.QualifiedName).Append(".").Append(str);
            }
            else
            {
                builder.Append(str);
            }
            return(builder.ToString());
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            CompensateActivity compensate = obj as CompensateActivity;

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

            // Compensate must be in a CompensationHandler or FaultHandler
            CompositeActivity parent = compensate.Parent;

            while (parent != null)
            {
                if (parent is CompensationHandlerActivity || parent is FaultHandlerActivity || parent is CancellationHandlerActivity)
                {
                    break;
                }

                parent = parent.Parent;
            }

            if (parent == null)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_CompensateBadNesting), ErrorNumbers.Error_CompensateBadNesting));
            }

            ValidationError  error   = null;
            StringCollection targets = CompensateActivity.GetCompensatableTargets(compensate);

            if (String.IsNullOrEmpty(compensate.TargetActivityName))
            {
                error = ValidationError.GetNotSetValidationError("TargetActivityName");
            }
            else if (!targets.Contains(compensate.TargetActivityName))
            {
                error = new ValidationError(SR.GetString(SR.Error_CompensateBadTargetTX, "TargetActivityName", compensate.TargetActivityName, compensate.QualifiedName), ErrorNumbers.Error_CompensateBadTargetTX, false, "TargetActivityName");
            }
            if (error != null)
            {
                validationErrors.Add(error);
            }

            return(validationErrors);
        }
Exemplo n.º 36
0
        public static void OnWorkflowChangesCompleted(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            String activeChildQualifiedName          = activity.GetValue(ActiveChildQualifiedNameProperty) as String;
            bool   activeChildRemovedInDynamicUpdate = (bool)activity.GetValue(ActiveChildRemovedProperty);

            if (activeChildQualifiedName != null && activeChildRemovedInDynamicUpdate)
            {   //We have our active child removed.
                if (activity.ExecutionStatus == ActivityExecutionStatus.Canceling ||
                    activity.ExecutionStatus == ActivityExecutionStatus.Faulting ||
                    activity.ExecutionStatus == ActivityExecutionStatus.Executing && !TryScheduleNextChild(activity, executionContext))
                {
                    activity.RemoveProperty(ActiveChildQualifiedNameProperty);
                    executionContext.CloseActivity();
                }
            }
            activity.RemoveProperty(ActiveChildRemovedProperty);
        }
Exemplo n.º 37
0
        internal static CompositeActivity GetFaultHandlers(Activity activityWithExceptionHandlers)
        {
            CompositeActivity exceptionHandlers = null;
            CompositeActivity compositeActivity = activityWithExceptionHandlers as CompositeActivity;

            if (compositeActivity != null)
            {
                foreach (Activity activity in ((ISupportAlternateFlow)compositeActivity).AlternateFlowActivities)
                {
                    if (activity is FaultHandlersActivity)
                    {
                        exceptionHandlers = activity as CompositeActivity;
                        break;
                    }
                }
            }
            return(exceptionHandlers);
        }
        void ISupportWorkflowChanges.OnActivityRemoved(ActivityExecutionContext executionContext, Activity removedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (removedActivity == null)
            {
                throw new ArgumentNullException("removedActivity");
            }
            CompositeActivity activity = executionContext.Activity as CompositeActivity;

            if (activity == null)
            {
                throw new ArgumentException("Error_InvalidActivityExecutionContext", "executionContext");
            }
            activity.OnActivityChangeRemove(executionContext, removedActivity);
        }
        internal static Activity GetCompensationHandler(Activity activityWithCompensation)
        {
            Activity          compensationHandler = null;
            CompositeActivity compositeActivity   = activityWithCompensation as CompositeActivity;

            if (compositeActivity != null)
            {
                foreach (Activity activity in ((ISupportAlternateFlow)compositeActivity).AlternateFlowActivities)
                {
                    if (activity is CompensationHandlerActivity)
                    {
                        compensationHandler = activity;
                        break;
                    }
                }
            }
            return(compensationHandler);
        }
Exemplo n.º 40
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors   = base.Validate(manager, obj);
            SuspendActivity           activity = obj as SuspendActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(SuspendActivity).FullName }), "obj");
            }
            for (CompositeActivity activity2 = activity.Parent; activity2 != null; activity2 = activity2.Parent)
            {
                if (activity2.SupportsTransaction)
                {
                    errors.Add(new ValidationError(SR.GetString("Error_SuspendInAtomicScope"), 0x525));
                    return(errors);
                }
            }
            return(errors);
        }
 private void ValidateSetStateInsideStateInitializationCore(CompositeActivity compositeActivity, StateActivity state, ValidationErrorCollection validationErrors)
 {
     foreach (Activity activity in compositeActivity.EnabledActivities)
     {
         CompositeActivity activity2 = activity as CompositeActivity;
         if (activity2 != null)
         {
             this.ValidateSetStateInsideStateInitializationCore(activity2, state, validationErrors);
         }
         else
         {
             SetStateActivity activity3 = activity as SetStateActivity;
             if (((activity3 != null) && !string.IsNullOrEmpty(activity3.TargetStateName)) && activity3.TargetStateName.Equals(state.QualifiedName))
             {
                 validationErrors.Add(new ValidationError(SR.GetError_InvalidTargetStateInStateInitialization(), 0x605));
                 break;
             }
         }
     }
 }
Exemplo n.º 42
0
        //@@undone:mayankm Once all ActivityExecutor is removed this method should not be virtual.
        void ISupportWorkflowChanges.OnActivityAdded(ActivityExecutionContext executionContext, Activity addedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (addedActivity == null)
            {
                throw new ArgumentNullException("addedActivity");
            }

            CompositeActivity compositeActivity = executionContext.Activity as CompositeActivity;

            if (compositeActivity == null)
            {
                throw new ArgumentException(SR.Error_InvalidActivityExecutionContext, "executionContext");
            }

            compositeActivity.OnActivityChangeAdd(executionContext, addedActivity);
        }
Exemplo n.º 43
0
        public Activity GetActivityByName(string activityQualifiedName, bool withinThisActivityOnly)
        {
            List <Activity> list = new List <Activity> ();
            Activity        current;

            if (withinThisActivityOnly)
            {
                current = this;
            }
            else
            {
                current = GetRootActivity();
            }

            while (current != null)
            {
                if (current.Name.Equals(activityQualifiedName))
                {
                    return(current);
                }

                if (IsBasedOnType(current, typeof(CompositeActivity)))
                {
                    CompositeActivity composite = (CompositeActivity)current;
                    foreach (Activity activity in composite.Activities)
                    {
                        list.Add(activity);
                    }
                }

                if (list.Count == 0)
                {
                    break;
                }

                current = list [0];
                list.Remove(current);
            }

            return(null);
        }
 private static bool TryScheduleNextChild(CompositeActivity activity, ActivityExecutionContext executionContext)
 {
     IList<Activity> enabledActivities = activity.EnabledActivities;
     int num = 0;
     for (int i = enabledActivities.Count - 1; i >= 0; i--)
     {
         if (enabledActivities[i].ExecutionStatus == ActivityExecutionStatus.Closed)
         {
             if (i == (enabledActivities.Count - 1))
             {
                 return false;
             }
             num = i + 1;
             break;
         }
     }
     enabledActivities[num].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>) activity);
     executionContext.ExecuteActivity(enabledActivities[num]);
     activity.SetValue(ActiveChildQualifiedNameProperty, enabledActivities[num].QualifiedName);
     return true;
 }
Exemplo n.º 45
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors     = base.Validate(manager, obj);
            CompensateActivity        compensate = obj as CompensateActivity;

            if (compensate == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CompensateActivity).FullName }), "obj");
            }
            CompositeActivity parent = compensate.Parent;

            while (parent != null)
            {
                if (((parent is CompensationHandlerActivity) || (parent is FaultHandlerActivity)) || (parent is CancellationHandlerActivity))
                {
                    break;
                }
                parent = parent.Parent;
            }
            if (parent == null)
            {
                errors.Add(new ValidationError(SR.GetString("Error_CompensateBadNesting"), 0x509));
            }
            ValidationError  item = null;
            StringCollection compensatableTargets = CompensateActivity.GetCompensatableTargets(compensate);

            if (string.IsNullOrEmpty(compensate.TargetActivityName))
            {
                item = ValidationError.GetNotSetValidationError("TargetActivityName");
            }
            else if (!compensatableTargets.Contains(compensate.TargetActivityName))
            {
                item = new ValidationError(SR.GetString("Error_CompensateBadTargetTX", new object[] { "TargetActivityName", compensate.TargetActivityName, compensate.QualifiedName }), 0x563, false, "TargetActivityName");
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
Exemplo n.º 46
0
        // Should only be called for BuiltIn activities
        internal static string GenerateQualifiedNameForLockedActivity(Activity activity, string id)
        {
            System.Text.StringBuilder sbQId = new System.Text.StringBuilder();

            // Walk up the parent chain to find the custom activity that contains this built-in activity
            // and prepend the ID of the custom activity to the front of the qualified ID of this activity.
            Debug.Assert(activity.Parent != null, "If this is a built-in activity, its parent should never be null.");
            string            newID          = (string.IsNullOrEmpty(id)) ? activity.Name : id;
            CompositeActivity customActivity = Helpers.GetDeclaringActivity(activity);

            if (customActivity != null)
            {
                //
                sbQId.Append(customActivity.QualifiedName).Append(".").Append(newID);
            }
            else
            {
                sbQId.Append(newID);
            }

            return(sbQId.ToString());
        }
Exemplo n.º 47
0
        protected internal override ValidationErrorCollection ValidateChanges(Activity contextActivity)
        {
            if (contextActivity == null)
            {
                throw new ArgumentNullException("contextActivity");
            }
            ValidationErrorCollection errors   = new ValidationErrorCollection();
            CompositeActivity         activity = contextActivity.TraverseDottedPathFromRoot(this.OwnerActivityDottedPath) as CompositeActivity;

            if ((activity != null) && WorkflowChanges.IsActivityExecutable(activity))
            {
                foreach (Validator validator in ComponentDispenser.CreateComponents(activity.GetType(), typeof(ActivityValidatorAttribute)))
                {
                    ValidationError item = validator.ValidateActivityChange(activity, this);
                    if (item != null)
                    {
                        errors.Add(item);
                    }
                }
            }
            return(errors);
        }
        private static bool TryScheduleNextChild(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            IList <Activity> enabledActivities = activity.EnabledActivities;
            int num = 0;

            for (int i = enabledActivities.Count - 1; i >= 0; i--)
            {
                if (enabledActivities[i].ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    if (i == (enabledActivities.Count - 1))
                    {
                        return(false);
                    }
                    num = i + 1;
                    break;
                }
            }
            enabledActivities[num].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener <ActivityExecutionStatusChangedEventArgs>)activity);
            executionContext.ExecuteActivity(enabledActivities[num]);
            activity.SetValue(ActiveChildQualifiedNameProperty, enabledActivities[num].QualifiedName);
            return(true);
        }
 public static ActivityExecutionStatus Cancel(CompositeActivity activity, ActivityExecutionContext executionContext)
 {
     for (int i = activity.EnabledActivities.Count - 1; i >= 0; i--)
     {
         Activity activity2 = activity.EnabledActivities[i];
         if (activity2.ExecutionStatus == ActivityExecutionStatus.Executing)
         {
             executionContext.CancelActivity(activity2);
             return(activity.ExecutionStatus);
         }
         if ((activity2.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity2.ExecutionStatus == ActivityExecutionStatus.Faulting))
         {
             return(activity.ExecutionStatus);
         }
         if (activity2.ExecutionStatus == ActivityExecutionStatus.Closed)
         {
             activity.RemoveProperty(ActiveChildQualifiedNameProperty);
             return(ActivityExecutionStatus.Closed);
         }
     }
     return(ActivityExecutionStatus.Closed);
 }
Exemplo n.º 50
0
        internal static Activity[] GetNestedActivities(CompositeActivity compositeActivity)
        {
            if (compositeActivity == null)
                throw new ArgumentNullException("compositeActivity");

            IList<Activity> childActivities = null;
            ArrayList nestedActivities = new ArrayList();
            Queue compositeActivities = new Queue();
            compositeActivities.Enqueue(compositeActivity);
            while (compositeActivities.Count > 0)
            {
                CompositeActivity compositeActivity2 = (CompositeActivity)compositeActivities.Dequeue();
                childActivities = compositeActivity2.Activities;

                foreach (Activity activity in childActivities)
                {
                    nestedActivities.Add(activity);
                    if (activity is CompositeActivity)
                        compositeActivities.Enqueue(activity);
                }
            }
            return (Activity[])nestedActivities.ToArray(typeof(Activity));
        }
Exemplo n.º 51
0
        private static bool TryScheduleNextChild(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            IList<Activity> children = activity.EnabledActivities;

            // Find index of next activity to run.
            int indexOfNextActivity = 0;
            for (int i = (children.Count - 1); i >= 0; i--)
            {
                if (children[i].ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    // Check whether this is last child?
                    if (i == (children.Count - 1))
                        return false;

                    indexOfNextActivity = i + 1;
                    break;
                }
            }

            children[indexOfNextActivity].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>)activity);
            executionContext.ExecuteActivity(children[indexOfNextActivity]);
            activity.SetValue(ActiveChildQualifiedNameProperty, children[indexOfNextActivity].QualifiedName);
            return true;
        }
 void IIdentifierCreationService.EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities)
 {
     if (parentActivity == null)
     {
         throw new ArgumentNullException("parentActivity");
     }
     if (childActivities == null)
     {
         throw new ArgumentNullException("childActivities");
     }
     ArrayList list = new ArrayList();
     Queue queue = new Queue(childActivities);
     while (queue.Count > 0)
     {
         Activity activity = (Activity) queue.Dequeue();
         if (activity is CompositeActivity)
         {
             foreach (Activity activity2 in ((CompositeActivity) activity).Activities)
             {
                 queue.Enqueue(activity2);
             }
         }
         if ((activity.Site == null) && !IsPreBuiltActivity(activity))
         {
             list.Add(activity);
         }
     }
     CompositeActivity rootActivity = Helpers.GetRootActivity(parentActivity) as CompositeActivity;
     StringDictionary dictionary = new StringDictionary();
     Type rootActivityType = this.GetRootActivityType(this.serviceProvider);
     if (rootActivity != null)
     {
         foreach (string str in Helpers.GetIdentifiersInCompositeActivity(rootActivity))
         {
             dictionary[str] = str;
         }
     }
     if (rootActivityType != null)
     {
         foreach (MemberInfo info in rootActivityType.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
         {
             Type c = null;
             if (info is FieldInfo)
             {
                 c = ((FieldInfo) info).FieldType;
             }
             if ((c == null) || !typeof(Activity).IsAssignableFrom(c))
             {
                 dictionary[info.Name] = info.Name;
             }
         }
     }
     foreach (Activity activity4 in list)
     {
         int num = 0;
         string baseIdentifier = Helpers.GetBaseIdentifier(activity4);
         string key = null;
         if (string.IsNullOrEmpty(activity4.Name) || string.Equals(activity4.Name, activity4.GetType().Name, StringComparison.Ordinal))
         {
             key = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { baseIdentifier, ++num });
         }
         else
         {
             key = activity4.Name;
         }
         while (dictionary.ContainsKey(key))
         {
             key = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { baseIdentifier, ++num });
             if (this.Provider != null)
             {
                 key = this.Provider.CreateValidIdentifier(key);
             }
         }
         dictionary[key] = key;
         activity4.Name = key;
     }
 }
Exemplo n.º 53
0
        private DesignerLayoutConnectionPoint GetEventHandlerConnectionPoint(CompositeActivity eventHandler)
        {
            Debug.Assert(eventHandler != null);
            StateDesigner sourceStateDesigner = (StateDesigner)GetDesigner(eventHandler.Parent);
            DesignerLayout eventHandlerLayout;
            if (!sourceStateDesigner.DesignerLayouts.TryGetValue(eventHandler, out eventHandlerLayout))
                return null;

            int connectionIndex = 0;
            foreach (DesignerLayout layout in sourceStateDesigner.DesignerLayouts.Values)
            {
                if (layout == eventHandlerLayout)
                {
                    // we add one so we connect to the Right side by default
                    break;
                }

                connectionIndex++;
            }

            return new DesignerLayoutConnectionPoint(sourceStateDesigner, connectionIndex, eventHandler, DesignerEdges.Right);
        }
Exemplo n.º 54
0
 static internal bool IsValidContainer(CompositeActivity activity)
 {
     return (activity is EventDrivenActivity || activity is StateInitializationActivity);
 }
Exemplo n.º 55
0
            private static void ValidateParentState(SetStateContainment containment, CompositeActivity activity)
            {
                Debug.Assert(activity != null);
                if (activity.Parent == null)
                    return;

                StateActivity state = activity.Parent as StateActivity;
                if (state != null)
                {
                    containment.validParentStateFound = true;
                    return;
                }

                ValidateParentState(containment, activity.Parent);
            }
 internal static Activity[] GetCompensatableChildren(CompositeActivity compositeActivity)
 {
     SortedDictionary<int, Activity> dictionary = new SortedDictionary<int, Activity>();
     Queue<Activity> queue = new Queue<Activity>(Helpers.GetAllEnabledActivities(compositeActivity));
     while (queue.Count > 0)
     {
         Activity activity = queue.Dequeue();
         if (((activity is ICompensatableActivity) && (activity.ExecutionStatus == ActivityExecutionStatus.Closed)) && (activity.ExecutionResult == ActivityExecutionResult.Succeeded))
         {
             dictionary.Add((int) activity.GetValue(Activity.CompletedOrderIdProperty), activity);
         }
         else if (activity is CompositeActivity)
         {
             foreach (Activity activity2 in Helpers.GetAllEnabledActivities((CompositeActivity) activity))
             {
                 queue.Enqueue(activity2);
             }
             continue;
         }
     }
     Activity[] array = new Activity[dictionary.Count];
     dictionary.Values.CopyTo(array, 0);
     return array;
 }
 internal static Activity GetLastCompensatableChild(CompositeActivity compositeActivity)
 {
     Activity[] compensatableChildren = GetCompensatableChildren(compositeActivity);
     if (((compensatableChildren != null) && (compensatableChildren.Length > 0)) && (compensatableChildren[compensatableChildren.Length - 1] != null))
     {
         return compensatableChildren[compensatableChildren.Length - 1];
     }
     return null;
 }
 private static List<WorkflowChangeAction> DiffTrees(CompositeActivity originalCompositeActivity, CompositeActivity clonedCompositeActivity)
 {
     List<WorkflowChangeAction> list = new List<WorkflowChangeAction>();
     IEnumerator<Activity> enumerator = clonedCompositeActivity.Activities.GetEnumerator();
     IEnumerator<Activity> enumerator2 = originalCompositeActivity.Activities.GetEnumerator();
     int removedActivityIndex = 0;
     while (enumerator2.MoveNext())
     {
         bool flag = false;
         Activity current = enumerator2.Current;
         while (enumerator.MoveNext())
         {
             Activity activityAdded = enumerator.Current;
             if (activityAdded.Readonly)
             {
                 if (current.DottedPath == activityAdded.CachedDottedPath)
                 {
                     removedActivityIndex++;
                     flag = true;
                     if (current is CompositeActivity)
                     {
                         list.AddRange(DiffTrees(current as CompositeActivity, activityAdded as CompositeActivity));
                     }
                 }
                 else
                 {
                     list.Add(new RemovedActivityAction(removedActivityIndex, current, clonedCompositeActivity));
                     while (enumerator2.MoveNext())
                     {
                         current = enumerator2.Current;
                         if (current.DottedPath == activityAdded.CachedDottedPath)
                         {
                             removedActivityIndex++;
                             flag = true;
                             if (current is CompositeActivity)
                             {
                                 list.AddRange(DiffTrees(current as CompositeActivity, activityAdded as CompositeActivity));
                             }
                             break;
                         }
                         list.Add(new RemovedActivityAction(removedActivityIndex, current, clonedCompositeActivity));
                     }
                 }
                 break;
             }
             list.Add(new AddedActivityAction(clonedCompositeActivity, activityAdded));
             removedActivityIndex++;
         }
         if (!flag)
         {
             list.Add(new RemovedActivityAction(removedActivityIndex, current, clonedCompositeActivity));
         }
     }
     while (enumerator.MoveNext())
     {
         list.Add(new AddedActivityAction(clonedCompositeActivity, enumerator.Current));
     }
     return list;
 }
Exemplo n.º 59
0
        /// <summary>
        /// Creates the business process activity info.
        /// </summary>
        /// <param name="businessProcess">The business process.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="parentActivity">The parent activity.</param>
        /// <param name="activityInfoItems">The activity info items.</param>
        private static void CreateBusinessProcessActivityInfo(BusinessProcessInfo businessProcess, WorkflowChangesScope scope, EntityObject[] assignments, CompositeActivity parentActivity, ActivityInfoCollection activityInfoItems)
        {
            foreach (Activity activity in parentActivity.Activities)
            {
                if (activity is CreateAssignmentAndWaitResultActivity)
                {
                    CreateAssignmentAndWaitResultActivity asgActivity = (CreateAssignmentAndWaitResultActivity)activity;
                    PropertyValueCollection properties = asgActivity.AssignmentProperties;

                    ActivityInfo activityInfo = new ActivityInfo();
                    activityInfoItems.Add(activityInfo);

                    activityInfo.Name = activity.Name;
                    activityInfo.Type = ActivityType.Assignment;

                    AssignmentEntity assignment = FindAssignmentByActivityName(assignments, activity.Name);

                    if (assignment != null)
                    {
                        activityInfo.State = (AssignmentState)assignment.State;
                        activityInfo.Subject = assignment.Subject;

                        activityInfo.TimeStatus = (AssignmentTimeStatus?)assignment.TimeStatus;

                        activityInfo.PlanStartDate = assignment.ActualStartDate;
                        activityInfo.PlanFinishDate = assignment.PlanFinishDate;

                        activityInfo.ActualStartDate = assignment.ActualStartDate;
                        activityInfo.ActualFinishDate = assignment.ActualFinishDate;
                        activityInfo.Comment = assignment.Comment;

                        activityInfo.UserId = assignment.UserId;

                        activityInfo.ClosedBy = assignment.ClosedBy;

                        activityInfo.ExecutionResult = (AssignmentExecutionResult?)assignment.ExecutionResult;
                    }
                    else
                    {
                        activityInfo.State = businessProcess.State == BusinessProcessState.Closed?
                            AssignmentState.Closed:
                            AssignmentState.Pending;

                        if (asgActivity.AssignmentProperties.Contains(AssignmentEntity.FieldSubject))
                            activityInfo.Subject = (string)asgActivity.AssignmentProperties[AssignmentEntity.FieldSubject];

                        if (asgActivity.AssignmentProperties.Contains(AssignmentEntity.FieldUserId))
                            activityInfo.UserId = (int?)asgActivity.AssignmentProperties[AssignmentEntity.FieldUserId];

                        // Resolve Plan Time
                        //if (activityInfo.State == AssignmentState.Pending &&
                        //    businessProcess.State == BusinessProcessState.Active &&
                        //    businessProcess.PlanFinishDate.HasValue)
                        //{
                        //    //CalculatePlanFinishDate(businessProcess, parentActivity, activity, activityInfo);
                        //}

                        //if (activityInfo.PlanStartDate.HasValue &&
                        //    activityInfo.PlanStartDate.Value < DateTime.Now)
                        //    activityInfo.TimeStatus = AssignmentTimeStatus.OverStart;

                        //if (activityInfo.PlanFinishDate.HasValue &&
                        //    activityInfo.PlanFinishDate.Value < DateTime.Now)
                        //    activityInfo.TimeStatus = AssignmentTimeStatus.OverDue;
                    }

                    // 2008-07-07 Added Assignment Properties
                    activityInfo.AssignmentProperties.AddRange(asgActivity.AssignmentProperties);
                    //
                }
                else if (activity is BlockActivity)
                {
                    // Create Block Info
                    ActivityInfo blockInfo = new ActivityInfo();
                    activityInfoItems.Add(blockInfo);

                    blockInfo.Name = activity.Name;
                    blockInfo.Type = ActivityType.Block;

                    blockInfo.State = businessProcess.State == BusinessProcessState.Closed ?
                            AssignmentState.Closed :
                            AssignmentState.Pending;

                    CreateBusinessProcessActivityInfo(businessProcess, scope, assignments, (BlockActivity)activity, blockInfo.Activities);

                    if (blockInfo.State == AssignmentState.Pending)
                    {
                        if (blockInfo.Activities.Count > 0)
                        {
                            foreach (ActivityInfo childActivitiInfo in blockInfo.Activities)
                            {
                                if (childActivitiInfo.State == AssignmentState.Active)
                                {
                                    blockInfo.State = AssignmentState.Active;
                                    break;
                                }
                                else if (childActivitiInfo.State == AssignmentState.Closed)
                                {
                                    blockInfo.State = AssignmentState.Closed;
                                }
                            }
                        }
                        else
                        {
                            int blockIndex = activityInfoItems.IndexOf(blockInfo);

                            if(blockIndex==0)
                                blockInfo.State = AssignmentState.Closed;
                            else
                                blockInfo.State = activityInfoItems[blockIndex-1].State==AssignmentState.Active? AssignmentState.Pending:
                                    activityInfoItems[blockIndex - 1].State;
                        }
                    }

                    if (blockInfo.Activities.Count > 0 &&
                        (blockInfo.State == AssignmentState.Active ||
                        blockInfo.State == AssignmentState.Closed))
                    {
                        blockInfo.PlanStartDate = blockInfo.Activities[0].PlanStartDate;
                        blockInfo.PlanFinishDate = blockInfo.Activities[0].PlanFinishDate;
                    }
                }
            }
        }
        // This function returns all the executable activities including secondary flow activities.
        public IList<Activity> GetAllEnabledActivities(CompositeActivity compositeActivity)
        {
            if (compositeActivity == null)
                throw new ArgumentNullException("compositeActivity");

            List<Activity> allActivities = new List<Activity>(compositeActivity.EnabledActivities);

            foreach (Activity secondaryFlowActivity in ((ISupportAlternateFlow)compositeActivity).AlternateFlowActivities)
            {
                if (!allActivities.Contains(secondaryFlowActivity))
                    allActivities.Add(secondaryFlowActivity);
            }

            return allActivities;
        }