Esempio n. 1
0
            public void Run()
            {
                this.pause = false;

                while (!this.pause)
                {
                    SchedulableItem item;

                    // atomicActivityQueue has higher priority
                    if (this.atomicActivityQueue.Count > 0)
                    {
                        item = this.atomicActivityQueue.Dequeue();
                    }
                    // The execution of the items in the scheduler queue is deferred until the atomic activity completes.
                    else if (owner.CurrentAtomicActivity == null &&
                             this.schedulerQueue.Count > 0)
                    {
                        item = schedulerQueue.Dequeue();
                    }
                    else
                    {
                        break;
                    }

                    Activity itemActivity = owner.GetContextActivityForId(item.ContextId).GetActivityByName(item.ActivityId);
                    Activity atomicActivity;
                    TransactionalProperties transactionalProperties = null;

                    if (owner.IsActivityInAtomicContext(itemActivity, out atomicActivity))
                    {
                        transactionalProperties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty);

                        // If we've aborted for any reason stop now!
                        if (owner.CheckAndProcessTransactionAborted(transactionalProperties))
                        {
                            return;
                        }
                    }

                    try
                    {
                        item.Run(owner);
                    }
                    catch (Exception e)
                    {
                        if (WorkflowExecutor.IsIrrecoverableException(e))
                        {
                            throw;
                        }

                        if (transactionalProperties != null)
                        {
                            transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed;
                            owner.lastExceptionThrown = e;
                        }

                        owner.RaiseException(e, itemActivity, null);
                    }
                }
            }
 public void Run()
 {
     this.pause = false;
     while (!this.pause)
     {
         SchedulableItem item;
         System.Workflow.ComponentModel.Activity activity2;
         if (this.atomicActivityQueue.Count > 0)
         {
             item = this.atomicActivityQueue.Dequeue();
         }
         else
         {
             if ((this.owner.CurrentAtomicActivity != null) || (this.schedulerQueue.Count <= 0))
             {
                 break;
             }
             item = this.schedulerQueue.Dequeue();
         }
         System.Workflow.ComponentModel.Activity activityByName = this.owner.GetContextActivityForId(item.ContextId).GetActivityByName(item.ActivityId);
         TransactionalProperties transactionalProperties        = null;
         if (this.owner.IsActivityInAtomicContext(activityByName, out activity2))
         {
             transactionalProperties = (TransactionalProperties)activity2.GetValue(WorkflowExecutor.TransactionalPropertiesProperty);
             if (this.owner.CheckAndProcessTransactionAborted(transactionalProperties))
             {
                 return;
             }
         }
         try
         {
             item.Run(this.owner);
             continue;
         }
         catch (Exception exception)
         {
             if (WorkflowExecutor.IsIrrecoverableException(exception))
             {
                 throw;
             }
             if (transactionalProperties != null)
             {
                 transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed;
                 this.owner.lastExceptionThrown           = exception;
             }
             this.owner.RaiseException(exception, activityByName, null);
             continue;
         }
     }
 }
Esempio n. 3
0
 public void Invoke(WorkflowSchedulerService service)
 {
     try
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Running workflow {0}", new object[] { this.state });
         this.Callback(this.state);
     }
     catch (Exception exception)
     {
         if (WorkflowExecutor.IsIrrecoverableException(exception))
         {
             throw;
         }
         service.RaiseExceptionNotHandledEvent(exception, (Guid)this.state);
     }
 }
 public void Invoke(WorkflowSchedulerService service)
 {
     try
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Running workflow {0}", state);
         Callback(state);
     }
     catch (Exception e)
     {
         if (WorkflowExecutor.IsIrrecoverableException(e))
         {
             throw;
         }
         else
         {
             service.RaiseExceptionNotHandledEvent(e, (Guid)state);
         }
     }
 }
Esempio n. 5
0
 internal void Complete(bool succeeded)
 {
     foreach (KeyValuePair <IPendingWork, SortedList <long, object> > pair in this.Items)
     {
         IPendingWork  key   = pair.Key;
         List <object> items = new List <object>(pair.Value.Values);
         try
         {
             key.Complete(succeeded, items);
         }
         catch (Exception exception)
         {
             if (WorkflowExecutor.IsIrrecoverableException(exception))
             {
                 throw;
             }
             WorkflowTrace.Runtime.TraceEvent(TraceEventType.Warning, 0, "Work Item {0} threw exception on complete notification", new object[] { pair.GetType() });
         }
     }
 }
 //Complete All Pending Work
 internal void Complete(bool succeeded)
 {
     foreach (KeyValuePair <IPendingWork, SortedList <long, object> > workItem in Items)
     {
         IPendingWork  work   = workItem.Key;
         List <object> values = new List <object>(workItem.Value.Values);
         try
         {
             work.Complete(succeeded, values);
         }
         catch (Exception e)
         {
             if (WorkflowExecutor.IsIrrecoverableException(e))
             {
                 throw;
             }
             else
             {
                 WorkflowTrace.Runtime.TraceEvent(TraceEventType.Warning, 0, "Work Item {0} threw exception on complete notification", workItem.GetType());
             }
         }
     }
 }
Esempio n. 7
0
 private void OnExit()
 {
     if ((this.uncaughtException == null) || !WorkflowExecutor.IsIrrecoverableException(this.uncaughtException))
     {
         this.executor.ClearAmbientTransactionAndServiceEnvironment();
         IEnumerable <IComparable> queues = this.executor.Queues;
         if (this.completed || (this.uncaughtException != null))
         {
             this.Activity.OnClose(this.nativeActivityContext, this.uncaughtException);
             this.Activity.SetOutputArgumentValues(this.executor.Outputs, this.nativeActivityContext);
             this.nativeActivityContext.RemoveAllBookmarks();
             this.executor.BookmarkQueueMap.Clear();
             if (this.canceled)
             {
                 this.nativeActivityContext.MarkCanceled();
             }
         }
         else
         {
             IList <IComparable> list = new List <IComparable>();
             foreach (IComparable comparable in this.initialBookmarks)
             {
                 list.Add(comparable);
             }
             IList <IComparable> list2 = null;
             foreach (IComparable comparable2 in queues)
             {
                 if (!list.Remove(comparable2))
                 {
                     if (list2 == null)
                     {
                         list2 = new List <IComparable>();
                     }
                     list2.Add(comparable2);
                 }
             }
             if (list2 != null)
             {
                 foreach (IComparable comparable3 in list2)
                 {
                     Bookmark key = this.nativeActivityContext.CreateBookmark(comparable3.ToString(), this.bookmarkCallback, BookmarkOptions.MultipleResume);
                     this.executor.BookmarkQueueMap.Add(key, comparable3);
                 }
             }
             foreach (IComparable comparable4 in list)
             {
                 this.nativeActivityContext.RemoveBookmark(comparable4.ToString());
                 List <Bookmark> list3 = new List <Bookmark>();
                 foreach (KeyValuePair <Bookmark, IComparable> pair in this.executor.BookmarkQueueMap)
                 {
                     if (pair.Value == comparable4)
                     {
                         list3.Add(pair.Key);
                     }
                 }
                 foreach (Bookmark bookmark2 in list3)
                 {
                     this.executor.BookmarkQueueMap.Remove(bookmark2);
                 }
             }
         }
     }
 }
Esempio n. 8
0
        //Called everytime we leave InteropEnvironment.
        void OnExit()
        {
            if (this.uncaughtException != null)
            {
                if (WorkflowExecutor.IsIrrecoverableException(this.uncaughtException))
                {
                    return;
                }
            }

            // This method clears the ambient transaction for the current thread.
            // Since the runtime can execute us on different threads,
            // we have to set up the transaction scope everytime we enter the interop environment and clear it when we leave the environment.
            this.executor.ClearAmbientTransactionAndServiceEnvironment();

            //Capture Current state of Queues in InteropEnvironment.
            IEnumerable <IComparable> currentBookmarks = this.executor.Queues;

            //Set outparameters when completed or faulted.
            if (this.completed || this.uncaughtException != null)
            {
                this.Activity.OnClose(this.nativeActivityContext, this.uncaughtException);

                this.Activity.SetOutputArgumentValues(
                    this.executor.Outputs, this.nativeActivityContext);

                this.nativeActivityContext.RemoveAllBookmarks();
                this.executor.BookmarkQueueMap.Clear();

                if (this.canceled)
                {
                    this.nativeActivityContext.MarkCanceled();
                }
            }
            else
            {
                //Find Differentials
                IList <IComparable> deletedBookmarks = new List <IComparable>();
                foreach (IComparable value in this.initialBookmarks)
                {
                    deletedBookmarks.Add(value);
                }

                IList <IComparable> newBookmarks = null;
                foreach (IComparable value in currentBookmarks)
                {
                    if (!deletedBookmarks.Remove(value))
                    {
                        if (newBookmarks == null)
                        {
                            newBookmarks = new List <IComparable>();
                        }
                        newBookmarks.Add(value);
                    }
                }

                if (newBookmarks != null)
                {
                    // Create new Queues as Bookmark.
                    foreach (IComparable bookmark in newBookmarks)
                    {
                        //
                        Bookmark v2Bookmark = this.nativeActivityContext.CreateBookmark(bookmark.ToString(),
                                                                                        this.bookmarkCallback, BookmarkOptions.MultipleResume);
                        this.executor.BookmarkQueueMap.Add(v2Bookmark, bookmark);
                    }
                }

                // Delete removed queues.
                foreach (IComparable bookmark in deletedBookmarks)
                {
                    this.nativeActivityContext.RemoveBookmark(bookmark.ToString());
                    List <Bookmark> bookmarksToRemove = new List <Bookmark>();
                    foreach (KeyValuePair <Bookmark, IComparable> entry in this.executor.BookmarkQueueMap)
                    {
                        if (entry.Value == bookmark)
                        {
                            bookmarksToRemove.Add(entry.Key);
                        }
                    }

                    foreach (Bookmark bookmarkToRemove in bookmarksToRemove)
                    {
                        this.executor.BookmarkQueueMap.Remove(bookmarkToRemove);
                    }
                }
            }
        }
Esempio n. 9
0
        public void Run()
        {
            do
            {
                this.RootWorkflowExecutor.ProcessQueuedEvents();
                // Get item to run
                SchedulableItem item        = GetItemToRun();
                bool            runningItem = false;

                // no ready work to run... go away
                if (item == null)
                {
                    break;
                }

                Activity  itemActivity = null;
                Exception exp          = null;

                TransactionalProperties transactionalProperties = null;
                int contextId = item.ContextId;

                // This function gets the root or enclosing while-loop activity
                Activity contextActivity = this.RootWorkflowExecutor.GetContextActivityForId(contextId);
                if (contextActivity == null)
                {
                    throw new InvalidOperationException(ExecutionStringManager.InvalidExecutionContext);
                }

                // This is the activity corresponding to the item's ActivityId
                itemActivity = contextActivity.GetActivityByName(item.ActivityId);
                using (new ServiceEnvironment(itemActivity))
                {
                    exp = null;
                    bool ignoreFinallyBlock = false;

                    try
                    {
                        // item preamble
                        // set up the item transactional context if necessary
                        //
                        Debug.Assert(itemActivity != null, "null itemActivity");
                        if (itemActivity == null)
                        {
                            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.InvalidActivityName, item.ActivityId));
                        }

                        Activity atomicActivity = null;
                        if (this.RootWorkflowExecutor.IsActivityInAtomicContext(itemActivity, out atomicActivity))
                        {
                            transactionalProperties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty);
                            // If we've aborted for any reason stop now!
                            // If we attempt to enter a new TransactionScope the com+ context will get corrupted
                            // See windows se bug 137267
                            if (!WorkflowExecutor.CheckAndProcessTransactionAborted(transactionalProperties))
                            {
                                if (transactionalProperties.TransactionScope == null)
                                {
                                    // Use TimeSpan.Zero so scope will not create timeout independent of the transaction
                                    // Use EnterpriseServicesInteropOption.Full to flow transaction to COM+
                                    transactionalProperties.TransactionScope =
                                        new TransactionScope(transactionalProperties.Transaction, TimeSpan.Zero, EnterpriseServicesInteropOption.Full);

                                    WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0,
                                                                     "Workflow Runtime: Scheduler: instanceId: " + this.RootWorkflowExecutor.InstanceIdString +
                                                                     "Entered into TransactionScope, Current atomic acitivity " + atomicActivity.Name);
                                }
                            }
                        }

                        // Run the item
                        //
                        runningItem = true;
                        WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 1, "Workflow Runtime: Scheduler: InstanceId: {0} : Running scheduled entry: {1}", this.RootWorkflowExecutor.InstanceIdString, item.ToString());

                        // running any entry implicitly changes some state of the workflow instance
                        this.RootWorkflowExecutor.stateChangedSincePersistence = true;

                        item.Run(this.RootWorkflowExecutor);
                    }
                    catch (Exception e)
                    {
                        if (WorkflowExecutor.IsIrrecoverableException(e))
                        {
                            ignoreFinallyBlock = true;
                            throw;
                        }
                        else
                        {
                            if (transactionalProperties != null)
                            {
                                transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed;
                            }
                            exp = e;
                        }
                    }
                    finally
                    {
                        if (!ignoreFinallyBlock)
                        {
                            if (runningItem)
                            {
                                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 1, "Workflow Runtime: Scheduler: InstanceId: {0} : Done with running scheduled entry: {1}", this.RootWorkflowExecutor.InstanceIdString, item.ToString());
                            }

                            // Process exception
                            //
                            if (exp != null)
                            {
                                //
                                this.RootWorkflowExecutor.ExceptionOccured(exp, itemActivity == null ? contextActivity : itemActivity, null);
                                exp = null;
                            }
                        }
                    }
                }
            } while (true);
        }
        public void Run()
        {
Label_0000:
            this.RootWorkflowExecutor.ProcessQueuedEvents();
            SchedulableItem itemToRun = this.GetItemToRun();
            bool            flag      = false;

            if (itemToRun != null)
            {
                Activity  currentActivity = null;
                Exception exp             = null;
                TransactionalProperties transactionalProperties = null;
                int      contextId            = itemToRun.ContextId;
                Activity contextActivityForId = this.RootWorkflowExecutor.GetContextActivityForId(contextId);
                if (contextActivityForId == null)
                {
                    throw new InvalidOperationException(ExecutionStringManager.InvalidExecutionContext);
                }
                currentActivity = contextActivityForId.GetActivityByName(itemToRun.ActivityId);
                using (new ServiceEnvironment(currentActivity))
                {
                    exp = null;
                    bool flag2 = false;
                    try
                    {
                        if (currentActivity == null)
                        {
                            throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.InvalidActivityName, new object[] { itemToRun.ActivityId }));
                        }
                        Activity atomicActivity = null;
                        if (this.RootWorkflowExecutor.IsActivityInAtomicContext(currentActivity, out atomicActivity))
                        {
                            transactionalProperties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty);
                            if (!WorkflowExecutor.CheckAndProcessTransactionAborted(transactionalProperties) && (transactionalProperties.TransactionScope == null))
                            {
                                transactionalProperties.TransactionScope = new TransactionScope(transactionalProperties.Transaction, TimeSpan.Zero, EnterpriseServicesInteropOption.Full);
                                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "Workflow Runtime: Scheduler: instanceId: " + this.RootWorkflowExecutor.InstanceIdString + "Entered into TransactionScope, Current atomic acitivity " + atomicActivity.Name);
                            }
                        }
                        flag = true;
                        WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 1, "Workflow Runtime: Scheduler: InstanceId: {0} : Running scheduled entry: {1}", new object[] { this.RootWorkflowExecutor.InstanceIdString, itemToRun.ToString() });
                        this.RootWorkflowExecutor.stateChangedSincePersistence = true;
                        itemToRun.Run(this.RootWorkflowExecutor);
                    }
                    catch (Exception exception2)
                    {
                        if (WorkflowExecutor.IsIrrecoverableException(exception2))
                        {
                            flag2 = true;
                            throw;
                        }
                        if (transactionalProperties != null)
                        {
                            transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed;
                        }
                        exp = exception2;
                    }
                    finally
                    {
                        if (!flag2)
                        {
                            if (flag)
                            {
                                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 1, "Workflow Runtime: Scheduler: InstanceId: {0} : Done with running scheduled entry: {1}", new object[] { this.RootWorkflowExecutor.InstanceIdString, itemToRun.ToString() });
                            }
                            if (exp != null)
                            {
                                this.RootWorkflowExecutor.ExceptionOccured(exp, (currentActivity == null) ? contextActivityForId : currentActivity, null);
                                exp = null;
                            }
                        }
                    }
                    goto Label_0000;
                }
            }
        }