public void SetWhenCondition(Activity activity, ActivityCondition handler)
 {
     if (activity.Parent is ConditionedActivityGroup)
     {
         activity.SetValue(ConditionedActivityGroup.WhenConditionProperty, handler);
     }
 }
 protected override bool ApplyTo(Activity rootActivity)
 {
     if (rootActivity == null)
     {
         return false;
     }
     RuleDefinitions definitions = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
     if (definitions == null)
     {
         definitions = new RuleDefinitions();
         rootActivity.SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);
     }
     bool flag = false;
     if (definitions.Conditions.RuntimeMode)
     {
         definitions.Conditions.RuntimeMode = false;
         flag = true;
     }
     try
     {
         definitions.Conditions.Add(this.ConditionDefinition);
     }
     finally
     {
         if (flag)
         {
             definitions.Conditions.RuntimeMode = true;
         }
     }
     return true;
 }
        private bool AcquireLocks(Activity activity)
        {
            // If this activity doesn't have any handles, we have nothing to do.
            ICollection <string> handles = GetAllSynchronizationHandles(activity);

            if (handles == null || handles.Count == 0)
            {
                return(true);
            }

            Activity parent = activity.Parent;

            while (parent != null)
            {
                if (parent.SupportsSynchronization || parent.Parent == null)
                {
                    Dictionary <string, GrantedLock> grantedLocks = (Dictionary <string, GrantedLock>)parent.GetValue(GrantedLocksProperty);
                    if (grantedLocks == null)
                    {
                        grantedLocks = new Dictionary <string, GrantedLock>();
                        parent.SetValue(GrantedLocksProperty, grantedLocks);
                    }
                    foreach (string handle in handles)
                    {
                        bool acquiredLocks = true;
                        if (!grantedLocks.ContainsKey(handle))
                        {
                            grantedLocks[handle] = new GrantedLock(activity);
                        }
                        else if (grantedLocks[handle].Holder != activity)
                        {
                            grantedLocks[handle].WaitList.Add(activity);
                            acquiredLocks = false;
                        }
                        if (!acquiredLocks)
                        {
                            return(false);
                        }
                    }
                }

                // If we reach a parent which has at least one handle, then we do not need to
                // go any further as the parent would already have acquired all our locks for
                // itself. Note that we still need to acquire our locks in the same parent if
                // the parent ProvidesSychronization, hence, this if check is *not* after
                // "parent = parent.Parent"!
                ICollection <string> synchronizationHandlesOnParent = (ICollection <string>)parent.GetValue(Activity.SynchronizationHandlesProperty);
                if (synchronizationHandlesOnParent != null && synchronizationHandlesOnParent.Count != 0)
                {
                    break;
                }

                parent = parent.Parent;
            }
            return(true);
        }
        public void CheckpointInstanceState(System.Workflow.ComponentModel.Activity atomicActivity)
        {
            TransactionOptions         transactionOptions = new TransactionOptions();
            WorkflowTransactionOptions options2           = TransactedContextFilter.GetTransactionOptions(atomicActivity);

            transactionOptions.IsolationLevel = options2.IsolationLevel;
            if (transactionOptions.IsolationLevel == IsolationLevel.Unspecified)
            {
                transactionOptions.IsolationLevel = IsolationLevel.Serializable;
            }
            transactionOptions.Timeout = options2.TimeoutDuration;
            TransactionalProperties properties = new TransactionalProperties();

            atomicActivity.SetValue(WorkflowExecutor.TransactionalPropertiesProperty, properties);
            this.ServiceProvider.CreateTransaction(transactionOptions);
            this.currentAtomicActivity = atomicActivity;
            this.scheduler.Pause();
        }
Esempio n. 5
0
        private static Activity CloneRootActivity(Activity originalRootActivity)
        {
            string           str             = originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty) as string;
            string           rulesMarkup     = null;
            Activity         rootActivity    = null;
            IServiceProvider serviceProvider = originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty) as IServiceProvider;

            if (!string.IsNullOrEmpty(str))
            {
                rulesMarkup  = originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty) as string;
                rootActivity = Activity.OnResolveActivityDefinition(null, str, rulesMarkup, true, false, serviceProvider);
            }
            else
            {
                rootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType(), null, null, true, false, serviceProvider);
            }
            if (rootActivity == null)
            {
                throw new NullReferenceException(SR.GetString("Error_InvalidRootForWorkflowChanges"));
            }
            ArrayList workflowChanges = (ArrayList)originalRootActivity.GetValue(WorkflowChangeActionsProperty);

            if (workflowChanges != null)
            {
                workflowChanges = CloneWorkflowChangeActions(workflowChanges, originalRootActivity);
                if (workflowChanges == null)
                {
                    return(rootActivity);
                }
                foreach (WorkflowChangeAction action in workflowChanges)
                {
                    action.ApplyTo(rootActivity);
                }
                rootActivity.SetValue(WorkflowChangeActionsProperty, workflowChanges);
            }
            return(rootActivity);
        }
Esempio n. 6
0
        private void SerializeToMarkup(Activity workflow, string fileName)
        {
            workflow.SetValue(WorkflowMarkupSerializer.XClassProperty, null);

            using (XmlWriter xmlWriter = XmlWriter.Create(fileName))
            {
                WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();
                markupSerializer.Serialize(xmlWriter, workflow);
            }

            RuleDefinitions ruleDefinitions = workflow.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
            if (ruleDefinitions != null)
            {
                if (ruleDefinitions.Conditions.Count > 0 || ruleDefinitions.RuleSets.Count > 0)
                {
                    String rulesFileName = GetRulesFileName(fileName);
                    using (XmlWriter xmlWriter = XmlWriter.Create(rulesFileName))
                    {
                        WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();
                        markupSerializer.Serialize(xmlWriter, ruleDefinitions);
                    }
                }
            }
        }
        public ActivityExecutionContext CreateExecutionContext(Activity activity)
        {
            ActivityExecutionContext context2;

            if (this.ownerContext == null)
            {
                throw new ObjectDisposedException("ActivityExecutionContextManager");
            }
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (!this.ownerContext.IsValidChild(activity, true))
            {
                throw new ArgumentException(SR.GetString("AEC_InvalidActivity"), "activity");
            }
            Activity item = activity.Clone();

            ((IDependencyObjectAccessor)item).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);
            Queue <Activity> queue = new Queue <Activity>();

            queue.Enqueue(item);
            while (queue.Count != 0)
            {
                Activity activity3 = queue.Dequeue();
                if (activity3.ExecutionStatus != ActivityExecutionStatus.Initialized)
                {
                    activity3.ResetAllKnownDependencyProperties();
                    CompositeActivity activity4 = activity3 as CompositeActivity;
                    if (activity4 != null)
                    {
                        for (int i = 0; i < activity4.EnabledActivities.Count; i++)
                        {
                            queue.Enqueue(activity4.EnabledActivities[i]);
                        }
                        ISupportAlternateFlow flow = activity4;
                        if (flow != null)
                        {
                            for (int j = 0; j < flow.AlternateFlowActivities.Count; j++)
                            {
                                queue.Enqueue(flow.AlternateFlowActivities[j]);
                            }
                        }
                    }
                }
            }
            IList <Activity> list = (IList <Activity>) this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);

            if (list == null)
            {
                list = new List <Activity>();
                this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, list);
            }
            list.Add(item);
            ActivityExecutionContextInfo info = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);

            item.SetValue(Activity.ActivityExecutionContextInfoProperty, info);
            item.SetValue(Activity.ActivityContextGuidProperty, info.ContextGuid);
            ActivityExecutionContext context = null;

            try
            {
                this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(item);
                context = new ActivityExecutionContext(item);
                this.executionContexts.Add(context);
                context.InitializeActivity(context.Activity);
                context2 = context;
            }
            catch (Exception)
            {
                if (context != null)
                {
                    this.CompleteExecutionContext(context);
                }
                else
                {
                    list.Remove(item);
                }
                throw;
            }
            return(context2);
        }
 private static bool TryCompensateLastCompletedChildActivity(ActivityExecutionContext context, Activity targetActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs> statusChangeHandler, bool isimmediateCompensation)
 {
     SortedDictionary<int, CompensationInfo> sortedListOfCompensatableTargets = new SortedDictionary<int, CompensationInfo>();
     if (targetActivity is CompositeActivity)
     {
         if (CollectCompensatableTargetActivities(targetActivity as CompositeActivity, sortedListOfCompensatableTargets, isimmediateCompensation))
         {
             return true;
         }
         if (CollectCompensatableActiveContexts(context, targetActivity, sortedListOfCompensatableTargets, isimmediateCompensation))
         {
             return true;
         }
         CollectCompensatableCompletedContexts(context, targetActivity, sortedListOfCompensatableTargets, isimmediateCompensation);
         if (sortedListOfCompensatableTargets.Count == 0)
         {
             CompleteRevokedExecutionContext(targetActivity, context);
             return false;
         }
         int? nullable = targetActivity.GetValue(CompensationHandlingFilter.LastCompensatedOrderIdProperty) as int?;
         int num = -1;
         CompensationInfo info = null;
         foreach (int num2 in sortedListOfCompensatableTargets.Keys)
         {
             if (nullable.HasValue)
             {
                 int? nullable2 = nullable;
                 int num3 = num2;
                 if ((nullable2.GetValueOrDefault() < num3) && nullable2.HasValue)
                 {
                     break;
                 }
             }
             info = sortedListOfCompensatableTargets[num2];
             num = num2;
         }
         if (info == null)
         {
             CompleteRevokedExecutionContext(targetActivity, context);
             return false;
         }
         targetActivity.SetValue(CompensationHandlingFilter.LastCompensatedOrderIdProperty, num);
         if ((info.TargetActivity != null) && (info.TargetActivity is ICompensatableActivity))
         {
             info.TargetActivity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
             context.CompensateActivity(info.TargetActivity);
             return true;
         }
         if ((info.TargetExecutionInfo != null) && (info.TargetExecutionContextManager != null))
         {
             ActivityExecutionContext context2 = info.TargetExecutionContextManager.DiscardPersistedExecutionContext(info.TargetExecutionInfo);
             if (context2.Activity is ICompensatableActivity)
             {
                 context2.Activity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                 context2.CompensateActivity(context2.Activity);
                 return true;
             }
             if (context2.Activity is CompositeActivity)
             {
                 Activity lastCompensatableChild = GetLastCompensatableChild(context2.Activity as CompositeActivity);
                 if (lastCompensatableChild != null)
                 {
                     lastCompensatableChild.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                     context2.CompensateActivity(lastCompensatableChild);
                     return true;
                 }
                 return TryCompensateLastCompletedChildActivity(context2, context2.Activity, statusChangeHandler, false);
             }
         }
         else if ((info.TargetExecutionContext != null) && (info.TargetExecutionContext.Activity is CompositeActivity))
         {
             Activity activity = GetLastCompensatableChild(info.TargetExecutionContext.Activity as CompositeActivity);
             if (activity != null)
             {
                 activity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                 info.TargetExecutionContext.CompensateActivity(activity);
                 return true;
             }
             return TryCompensateLastCompletedChildActivity(info.TargetExecutionContext, info.TargetExecutionContext.Activity, statusChangeHandler, false);
         }
     }
     return false;
 }
Esempio n. 9
0
        private static bool TryCompensateLastCompletedChildActivity(ActivityExecutionContext context, Activity targetActivity, IActivityEventListener <ActivityExecutionStatusChangedEventArgs> statusChangeHandler, bool isimmediateCompensation)
        {
            SortedDictionary <int, CompensationInfo> sortedListOfCompensatableTargets = new SortedDictionary <int, CompensationInfo>();

            if (targetActivity is CompositeActivity)
            {
                if (CollectCompensatableTargetActivities(targetActivity as CompositeActivity, sortedListOfCompensatableTargets, isimmediateCompensation))
                {
                    return(true);
                }
                if (CollectCompensatableActiveContexts(context, targetActivity, sortedListOfCompensatableTargets, isimmediateCompensation))
                {
                    return(true);
                }
                CollectCompensatableCompletedContexts(context, targetActivity, sortedListOfCompensatableTargets, isimmediateCompensation);
                if (sortedListOfCompensatableTargets.Count == 0)
                {
                    CompleteRevokedExecutionContext(targetActivity, context);
                    return(false);
                }
                int?nullable          = targetActivity.GetValue(CompensationHandlingFilter.LastCompensatedOrderIdProperty) as int?;
                int num               = -1;
                CompensationInfo info = null;
                foreach (int num2 in sortedListOfCompensatableTargets.Keys)
                {
                    if (nullable.HasValue)
                    {
                        int?nullable2 = nullable;
                        int num3      = num2;
                        if ((nullable2.GetValueOrDefault() < num3) && nullable2.HasValue)
                        {
                            break;
                        }
                    }
                    info = sortedListOfCompensatableTargets[num2];
                    num  = num2;
                }
                if (info == null)
                {
                    CompleteRevokedExecutionContext(targetActivity, context);
                    return(false);
                }
                targetActivity.SetValue(CompensationHandlingFilter.LastCompensatedOrderIdProperty, num);
                if ((info.TargetActivity != null) && (info.TargetActivity is ICompensatableActivity))
                {
                    info.TargetActivity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                    context.CompensateActivity(info.TargetActivity);
                    return(true);
                }
                if ((info.TargetExecutionInfo != null) && (info.TargetExecutionContextManager != null))
                {
                    ActivityExecutionContext context2 = info.TargetExecutionContextManager.DiscardPersistedExecutionContext(info.TargetExecutionInfo);
                    if (context2.Activity is ICompensatableActivity)
                    {
                        context2.Activity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                        context2.CompensateActivity(context2.Activity);
                        return(true);
                    }
                    if (context2.Activity is CompositeActivity)
                    {
                        Activity lastCompensatableChild = GetLastCompensatableChild(context2.Activity as CompositeActivity);
                        if (lastCompensatableChild != null)
                        {
                            lastCompensatableChild.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                            context2.CompensateActivity(lastCompensatableChild);
                            return(true);
                        }
                        return(TryCompensateLastCompletedChildActivity(context2, context2.Activity, statusChangeHandler, false));
                    }
                }
                else if ((info.TargetExecutionContext != null) && (info.TargetExecutionContext.Activity is CompositeActivity))
                {
                    Activity activity = GetLastCompensatableChild(info.TargetExecutionContext.Activity as CompositeActivity);
                    if (activity != null)
                    {
                        activity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                        info.TargetExecutionContext.CompensateActivity(activity);
                        return(true);
                    }
                    return(TryCompensateLastCompletedChildActivity(info.TargetExecutionContext, info.TargetExecutionContext.Activity, statusChangeHandler, false));
                }
            }
            return(false);
        }
        internal void ReleaseLocks(bool transactional)
        {
            if (this.currentActivity == null)
            {
                throw new ObjectDisposedException("ActivityExecutionContext");
            }


            // remove the callback.
            this.Activity.RemoveProperty(LockAcquiredCallbackProperty);

            // The assumption is that lock contentions will be few. Hence, we optimize serialization
            // size over performance, for ex. do not persist the list of locks that have already been
            // granted.
            ICollection <string> handles = GetAllSynchronizationHandles(this.Activity);

            if (handles == null || handles.Count == 0)
            {
                return;
            }

            List <Activity> waitingActivities = new List <Activity>();
            Activity        parent            = Activity.Parent;

            while (parent != null)
            {
                if (parent.SupportsSynchronization || parent.Parent == null)
                {
                    Dictionary <string, GrantedLock> grantedLocks = (Dictionary <string, GrantedLock>)parent.GetValue(GrantedLocksProperty);

                    // if its an transactional release of locks, then release it and then keep it
                    // cached, so that in case of rollback, we can reacuire locks
                    if (transactional)
                    {
                        Dictionary <string, GrantedLock> cachedGrantedLocks = new Dictionary <string, GrantedLock>();

                        if (grantedLocks != null)
                        {
                            foreach (KeyValuePair <string, GrantedLock> grantedLockEntry in grantedLocks)
                            {
                                cachedGrantedLocks.Add(grantedLockEntry.Key, (GrantedLock)grantedLockEntry.Value.Clone());
                            }
                        }

                        parent.SetValue(CachedGrantedLocksProperty, cachedGrantedLocks);
                    }

                    if (grantedLocks != null)
                    {
                        foreach (string handle in handles)
                        {
                            if (!grantedLocks.ContainsKey(handle))
                            {
                                continue;
                            }
                            else if (grantedLocks[handle].WaitList.Count == 0)
                            {
                                grantedLocks.Remove(handle);
                            }
                            else if (grantedLocks[handle].Holder != this.Activity)
                            {
                                grantedLocks[handle].WaitList.Remove(this.Activity);
                            }
                            else
                            {
                                // Grant the lock to the next waiting activity.
                                Activity waitingActivity = grantedLocks[handle].WaitList[0];
                                grantedLocks[handle].WaitList.RemoveAt(0);
                                grantedLocks[handle].Holder = waitingActivity;
                                if (!waitingActivities.Contains(waitingActivity))
                                {
                                    waitingActivities.Add(waitingActivity);
                                }
                            }
                        }
                        if (grantedLocks.Count == 0)
                        {
                            parent.RemoveProperty(GrantedLocksProperty);
                        }
                    }
                }

                // If we reach a parent which has at least one handle, then we do not need to
                // go any further as the parent would already have acquired all our locks for
                // itself. Note that we still need to acquire our locks in the same parent if
                // the parent ProvidesSychronization, hence, this if check is *not* after
                // "parent = parent.Parent"!
                ICollection <string> synchronizationHandlesOnParent = (ICollection <string>)parent.GetValue(Activity.SynchronizationHandlesProperty);
                if (synchronizationHandlesOnParent != null && synchronizationHandlesOnParent.Count != 0)
                {
                    break;
                }

                parent = parent.Parent;
            }

            // Try and acquire locks for all the waiting activities.
            foreach (Activity waitingActivity in waitingActivities)
            {
                if (AcquireLocks(waitingActivity))
                {
                    ActivityExecutorDelegateInfo <EventArgs> waitingActivityCallback = (ActivityExecutorDelegateInfo <EventArgs>)waitingActivity.GetValue(LockAcquiredCallbackProperty);
                    waitingActivityCallback.InvokeDelegate(this.Activity.ContextActivity, EventArgs.Empty, false, transactional);
                }
            }
        }
        private static bool TryCompensateLastCompletedChildActivity(ActivityExecutionContext context, Activity targetActivity, IActivityEventListener <ActivityExecutionStatusChangedEventArgs> statusChangeHandler, bool isimmediateCompensation)
        {
            SortedDictionary <int, CompensationInfo> sortedListOfCompensatableTargets = new SortedDictionary <int, CompensationInfo>();

            if (!(targetActivity is CompositeActivity))
            {
                return(false);
            }

            //Walk through all of the direct children which are compensatable and add them in the sorted order of their completion
            //bail out if any of the compensatable children is currently compensating/faulting or canceling
            if (CollectCompensatableTargetActivities(targetActivity as CompositeActivity, sortedListOfCompensatableTargets, isimmediateCompensation))
            {
                return(true);
            }

            // walk through active contexts that contain compensatable child, add them in the sorted order of the completion
            // this also, walks through the completed contexts which are compensatable and are nested directly within the active contexts and adds them in the order of their completion
            // bail out if any activity is currently compensating/faulting or cancelling
            if (CollectCompensatableActiveContexts(context, targetActivity, sortedListOfCompensatableTargets, isimmediateCompensation))
            {
                return(true);
            }

            // walk through all completed execution contexts which are compensatable and are directly nested under the target activity,
            //and add them to our sorted list
            CollectCompensatableCompletedContexts(context, targetActivity, sortedListOfCompensatableTargets, isimmediateCompensation);

            //if there were no compensatable targets found, bail out
            if (sortedListOfCompensatableTargets.Count == 0)
            {
                CompleteRevokedExecutionContext(targetActivity, context);
                return(false);
            }

            int?lastCompletedOrderId     = targetActivity.GetValue(CompensationHandlingFilter.LastCompensatedOrderIdProperty) as Nullable <int>;
            int nextLastCompletedOrderId = -1;
            //get the last compensatable target - this could be an activity, contextInfo or a Context
            CompensationInfo lastCompensatableTarget = null;

            foreach (int completedOrderId in sortedListOfCompensatableTargets.Keys)
            {
                if (lastCompletedOrderId.HasValue && lastCompletedOrderId < completedOrderId)
                {
                    break;
                }

                lastCompensatableTarget  = sortedListOfCompensatableTargets[completedOrderId];
                nextLastCompletedOrderId = completedOrderId;
            }

            //We are done with compensation on entire branch, now complete execution contexts
            //recursilvely which we might have opened up.
            if (lastCompensatableTarget == null)
            {
                CompleteRevokedExecutionContext(targetActivity, context);
                return(false);
            }

            targetActivity.SetValue(CompensationHandlingFilter.LastCompensatedOrderIdProperty, nextLastCompletedOrderId);

            //the last compensatable target could be an activity
            if (lastCompensatableTarget.TargetActivity != null && lastCompensatableTarget.TargetActivity is ICompensatableActivity)
            {
                lastCompensatableTarget.TargetActivity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                context.CompensateActivity(lastCompensatableTarget.TargetActivity);
                return(true);
            } //or get the last compensatable "completed" context
            else if (lastCompensatableTarget.TargetExecutionInfo != null && lastCompensatableTarget.TargetExecutionContextManager != null)
            {
                ActivityExecutionContext revokedExecutionContext = lastCompensatableTarget.TargetExecutionContextManager.DiscardPersistedExecutionContext(lastCompensatableTarget.TargetExecutionInfo);

                //get the "first" compensatable child and compensate it
                if (revokedExecutionContext.Activity is ICompensatableActivity)
                {
                    revokedExecutionContext.Activity.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                    revokedExecutionContext.CompensateActivity(revokedExecutionContext.Activity);
                    return(true);
                }
                else if (revokedExecutionContext.Activity is CompositeActivity)
                {
                    //get the last compensatable child of the revoked context
                    Activity compensatableChild = GetLastCompensatableChild(revokedExecutionContext.Activity as CompositeActivity);
                    if (compensatableChild != null)
                    {
                        compensatableChild.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                        revokedExecutionContext.CompensateActivity(compensatableChild);
                        return(true);
                    }
                    else// recursively, walk the context tree and keep revoking the compensatable contexts
                    {
                        return(TryCompensateLastCompletedChildActivity(revokedExecutionContext, revokedExecutionContext.Activity, statusChangeHandler, false));
                    }
                }
            }
            else if (lastCompensatableTarget.TargetExecutionContext != null) //or get the last compensatable "active" context
            {
                if (lastCompensatableTarget.TargetExecutionContext.Activity is CompositeActivity)
                {
                    //get the last compensatable child of the active context
                    Activity compensatableChild = GetLastCompensatableChild(lastCompensatableTarget.TargetExecutionContext.Activity as CompositeActivity);
                    if (compensatableChild != null)
                    {
                        compensatableChild.RegisterForStatusChange(Activity.StatusChangedEvent, statusChangeHandler);
                        lastCompensatableTarget.TargetExecutionContext.CompensateActivity(compensatableChild);
                        return(true);
                    }
                    else // recursively, walk the context tree and keep revoking the compensatable contexts
                    {
                        return(TryCompensateLastCompletedChildActivity(lastCompensatableTarget.TargetExecutionContext, lastCompensatableTarget.TargetExecutionContext.Activity, statusChangeHandler, false));
                    }
                }
            }
            return(false);
        }
        public ActivityExecutionContext CreateExecutionContext(Activity activity)
        {
            if (this.ownerContext == null)
            {
                throw new ObjectDisposedException("ActivityExecutionContextManager");
            }

            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }

            if (!this.ownerContext.IsValidChild(activity, true))
            {
                throw new ArgumentException(SR.GetString(SR.AEC_InvalidActivity), "activity");
            }

            Activity copiedActivity = activity.Clone();

            ((IDependencyObjectAccessor)copiedActivity).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);

            //Reset the cloned tree for execution.
            Queue <Activity> activityQueue = new Queue <Activity>();

            activityQueue.Enqueue(copiedActivity);

            while (activityQueue.Count != 0)
            {
                Activity clonedActivity = activityQueue.Dequeue();
                if (clonedActivity.ExecutionStatus != ActivityExecutionStatus.Initialized)
                {
                    clonedActivity.ResetAllKnownDependencyProperties();
                    CompositeActivity compositeActivity = clonedActivity as CompositeActivity;

                    if (compositeActivity != null)
                    {
                        for (int i = 0; i < compositeActivity.EnabledActivities.Count; ++i)
                        {
                            activityQueue.Enqueue(compositeActivity.EnabledActivities[i]);
                        }

                        ISupportAlternateFlow alternateFlow = compositeActivity as ISupportAlternateFlow;

                        if (alternateFlow != null)
                        {
                            for (int i = 0; i < alternateFlow.AlternateFlowActivities.Count; ++i)
                            {
                                activityQueue.Enqueue(alternateFlow.AlternateFlowActivities[i]);
                            }
                        }
                    }
                }
            }

            // get active context activities and add it to this one
            IList <Activity> activeContexts = (IList <Activity>) this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);

            if (activeContexts == null)
            {
                activeContexts = new List <Activity>();
                this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, activeContexts);
            }
            activeContexts.Add(copiedActivity);

            // prepare the copied activity as a context activity
            ActivityExecutionContextInfo contextInfo = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);

            copiedActivity.SetValue(Activity.ActivityExecutionContextInfoProperty, contextInfo);
            copiedActivity.SetValue(Activity.ActivityContextGuidProperty, contextInfo.ContextGuid);
            ActivityExecutionContext newExecutionContext = null;

            try
            {
                // inform workflow runtime
                this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(copiedActivity);

                // return the new context
                newExecutionContext = new ActivityExecutionContext(copiedActivity);
                this.executionContexts.Add(newExecutionContext);
                newExecutionContext.InitializeActivity(newExecutionContext.Activity);
                return(newExecutionContext);
            }
            catch (Exception)
            {
                if (newExecutionContext != null)
                {
                    this.CompleteExecutionContext(newExecutionContext);
                }
                else
                {
                    activeContexts.Remove(copiedActivity);
                }
                throw;
            }
        }
        public void CheckpointInstanceState(Activity atomicActivity)
        {
            // Note that the WF4 runtime does not create checkpoints.  If the transaction aborts, the workflow aborts.  
            // We are following the WF4 behavior and not creating a checkpoint.

            TransactionOptions tranOpts = new TransactionOptions();
            WorkflowTransactionOptions atomicTxn = TransactedContextFilter.GetTransactionOptions(atomicActivity);

            tranOpts.IsolationLevel = atomicTxn.IsolationLevel;
            if (tranOpts.IsolationLevel == IsolationLevel.Unspecified)
            {
                tranOpts.IsolationLevel = IsolationLevel.Serializable;
            }

            tranOpts.Timeout = atomicTxn.TimeoutDuration;

            TransactionalProperties transactionProperties = new TransactionalProperties();
            atomicActivity.SetValue(WorkflowExecutor.TransactionalPropertiesProperty, transactionProperties);
            this.ServiceProvider.CreateTransaction(tranOpts);
            this.currentAtomicActivity = atomicActivity;
            this.scheduler.Pause();
        }
 internal static RuleDefinitions Load_Rules_RT(Activity declaringActivity)
 {
     RuleDefinitions ruleDefinitionsFromManifest = declaringActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
     if (ruleDefinitionsFromManifest == null)
     {
         ruleDefinitionsFromManifest = GetRuleDefinitionsFromManifest(declaringActivity.GetType());
         if (ruleDefinitionsFromManifest != null)
         {
             declaringActivity.SetValue(RuleDefinitions.RuleDefinitionsProperty, ruleDefinitionsFromManifest);
         }
     }
     return ruleDefinitionsFromManifest;
 }
Esempio n. 15
0
 internal static RuleDefinitions Load_Rules_RT(Activity declaringActivity)
 {
     RuleDefinitions rules = declaringActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
     if (rules == null)
     {
         rules = ConditionHelper.GetRuleDefinitionsFromManifest(declaringActivity.GetType());
         if (rules != null)
             declaringActivity.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
     }
     return rules;
 }
 private void CreateTransaction(Activity atomicActivity)
 {
     TransactionalProperties properties = new TransactionalProperties();
     TransactionOptions options = new TransactionOptions();
     WorkflowTransactionOptions transactionOptions = TransactedContextFilter.GetTransactionOptions(atomicActivity);
     options.IsolationLevel = transactionOptions.IsolationLevel;
     if (options.IsolationLevel == IsolationLevel.Unspecified)
     {
         options.IsolationLevel = IsolationLevel.Serializable;
     }
     options.Timeout = transactionOptions.TimeoutDuration;
     CommittableTransaction transaction = new CommittableTransaction(options);
     properties.Transaction = transaction;
     WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, string.Concat(new object[] { "Workflow Runtime: WorkflowExecutor: instanceId: ", this.InstanceIdString, " .Created enlistable transaction ", transaction.GetHashCode(), " with timeout ", options.Timeout, ", isolation ", options.IsolationLevel }));
     properties.LocalQueuingService = new WorkflowQueuingService(this.qService);
     atomicActivity.SetValue(TransactionalPropertiesProperty, properties);
     this.currentAtomicActivity = atomicActivity;
     this.atomicActivityEvent = new ManualResetEvent(false);
     WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "Workflow Runtime: WorkflowExecutor: instanceId: " + this.InstanceIdString + " .Set CurrentAtomicActivity to " + atomicActivity.Name);
 }
 public void SetWorkflowServiceAttributes(Activity activity, WorkflowServiceAttributes value)
 {
     activity.SetValue(ReceiveActivity.WorkflowServiceAttributesProperty, value);
 }
 internal static void ProcessDefTag(WorkflowMarkupSerializationManager serializationManager, XmlReader reader, Activity activity, bool newSegment, string fileName)
 {
     ResourceManager manager = new ResourceManager("System.Workflow.ComponentModel.StringResources", typeof(ActivityBind).Assembly);
     if (reader.NodeType == XmlNodeType.Attribute)
     {
         string str;
         if (((str = reader.LocalName) != null) && (str == "Class"))
         {
             activity.SetValue(WorkflowMarkupSerializer.XClassProperty, reader.Value);
         }
         else
         {
             serializationManager.ReportError(new WorkflowMarkupSerializationException(string.Format(CultureInfo.CurrentCulture, manager.GetString("UnknownDefinitionTag"), new object[] { "x", reader.LocalName, "http://schemas.microsoft.com/winfx/2006/xaml" }), (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LineNumber : 1, (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LinePosition : 1));
         }
     }
     else
     {
         bool flag = false;
         bool isEmptyElement = reader.IsEmptyElement;
         int depth = reader.Depth;
         do
         {
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                 {
                     string localName = reader.LocalName;
                     if (localName != null)
                     {
                         if (localName == "Code")
                         {
                             if (isEmptyElement)
                             {
                                 flag = true;
                             }
                             break;
                         }
                         bool flag1 = localName == "Constructor";
                     }
                     serializationManager.ReportError(new WorkflowMarkupSerializationException(string.Format(CultureInfo.CurrentCulture, manager.GetString("UnknownDefinitionTag"), new object[] { "x", reader.LocalName, "http://schemas.microsoft.com/winfx/2006/xaml" }), (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LineNumber : 1, (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LinePosition : 1));
                     return;
                 }
                 case XmlNodeType.Text:
                 case XmlNodeType.CDATA:
                 {
                     int num2 = (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LineNumber : 1;
                     int num3 = (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LinePosition : 1;
                     CodeSnippetTypeMember member = new CodeSnippetTypeMember(reader.Value) {
                         LinePragma = new CodeLinePragma(fileName, Math.Max(num2 - 1, 1))
                     };
                     member.UserData[UserDataKeys.CodeSegment_New] = newSegment;
                     member.UserData[UserDataKeys.CodeSegment_ColumnNumber] = (num3 + reader.Name.Length) - 1;
                     CodeTypeMemberCollection members = activity.GetValue(WorkflowMarkupSerializer.XCodeProperty) as CodeTypeMemberCollection;
                     if (members == null)
                     {
                         members = new CodeTypeMemberCollection();
                         activity.SetValue(WorkflowMarkupSerializer.XCodeProperty, members);
                     }
                     members.Add(member);
                     break;
                 }
                 case XmlNodeType.EndElement:
                     if (reader.Depth == depth)
                     {
                         flag = true;
                     }
                     break;
             }
         }
         while (!flag && reader.Read());
     }
 }