public void ClearAmbientTransactionAndServiceEnvironment() { try { if (this.resourceManager.IsBatchDirty) { this.ServiceProvider.AddResourceManager(this.resourceManager); } if (this.currentAtomicActivity != null) { TransactionalProperties properties = (TransactionalProperties)this.currentAtomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); properties.Transaction = null; if (properties.TransactionScope != null) { properties.TransactionScope.Complete(); properties.TransactionScope.Dispose(); properties.TransactionScope = null; } } } finally { ((IDisposable)this.serviceEnvironment).Dispose(); this.serviceEnvironment = null; } }
public void PersistInstanceState(System.Workflow.ComponentModel.Activity activity) { this.lastExceptionThrown = null; this.abortTransaction = false; this.ScheduleDelayedItems(activity); if (this.currentAtomicActivity == null) { if ((activity == this.rootActivity) && !activity.PersistOnClose) { return; } this.ServiceProvider.Persist(); } else { TransactionalProperties transactionalProperties = null; transactionalProperties = (TransactionalProperties)activity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); if (this.CheckAndProcessTransactionAborted(transactionalProperties)) { return; } transactionalProperties.TransactionScope.Complete(); transactionalProperties.TransactionScope.Dispose(); transactionalProperties.TransactionScope = null; this.ServiceProvider.CommitTransaction(); transactionalProperties.Transaction = null; this.currentAtomicActivity = null; } this.internalCurrentActivity = activity; this.scheduler.Pause(); }
void ScheduleDelayedItems(Activity atomicActivity) { List <SchedulableItem> items = null; TransactionalProperties transactionalProperties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); if (transactionalProperties == null) { return; } lock (transactionalProperties) { items = transactionalProperties.ItemsToBeScheduledAtCompletion; if (items == null) { return; } foreach (SchedulableItem item in items) { this.scheduler.ScheduleItem(item, false); } items.Clear(); transactionalProperties.ItemsToBeScheduledAtCompletion = null; } }
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); } } }
void AddItemToBeScheduledLater(Activity atomicActivity, SchedulableItem item) { if (atomicActivity == null) { return; } // Activity may not be atomic and is an activity which is not // yet scheduled for execution (typically receive case) if (!atomicActivity.SupportsTransaction) { return; } TransactionalProperties transactionalProperties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); if (transactionalProperties != null) { lock (transactionalProperties) { List <SchedulableItem> notifications = null; notifications = transactionalProperties.ItemsToBeScheduledAtCompletion; if (notifications == null) { notifications = new List <SchedulableItem>(); transactionalProperties.ItemsToBeScheduledAtCompletion = notifications; } notifications.Add(item); } } }
public void SetAmbientTransactionAndServiceEnvironment(Transaction transaction) { this.serviceEnvironment = new ServiceEnvironment(this.RootActivity); if ((transaction != null) && (this.currentAtomicActivity != null)) { TransactionalProperties properties = (TransactionalProperties)this.currentAtomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); properties.Transaction = transaction; properties.TransactionScope = new System.Transactions.TransactionScope(properties.Transaction, TimeSpan.Zero, EnterpriseServicesInteropOption.Full); } }
public void SetAmbientTransactionAndServiceEnvironment(Transaction transaction) { this.serviceEnvironment = new ServiceEnvironment(this.RootActivity); if (transaction != null && this.currentAtomicActivity != null) { TransactionalProperties transactionalProperties = (TransactionalProperties)this.currentAtomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); Debug.Assert(transactionalProperties != null, "The current atomic activity is missing transactional properties"); transactionalProperties.Transaction = transaction; transactionalProperties.TransactionScope = new System.Transactions.TransactionScope(transactionalProperties.Transaction, TimeSpan.Zero, EnterpriseServicesInteropOption.Full); } }
public bool CheckAndProcessTransactionAborted(TransactionalProperties transactionalProperties) { if ((transactionalProperties.Transaction != null) && (transactionalProperties.Transaction.TransactionInformation.Status != TransactionStatus.Aborted)) { return(false); } if (transactionalProperties.TransactionState != TransactionProcessState.AbortProcessed) { this.scheduler.Pause(); transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed; } return(true); }
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; } } }
public bool CheckAndProcessTransactionAborted(TransactionalProperties transactionalProperties) { if (transactionalProperties.Transaction != null && transactionalProperties.Transaction.TransactionInformation.Status != TransactionStatus.Aborted) { return(false); } if (transactionalProperties.TransactionState != TransactionProcessState.AbortProcessed) { // The transaction has aborted. The WF3 runtime throws a TransactionAborted exception here, which then propagates as fault. // But WF4 aborts the workflow, so pause the scheduler and return. this.scheduler.Pause(); transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed; } 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(); }
private void AddItemToBeScheduledLater(System.Workflow.ComponentModel.Activity atomicActivity, SchedulableItem item) { if ((atomicActivity != null) && atomicActivity.SupportsTransaction) { TransactionalProperties properties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); if (properties != null) { lock (properties) { List <SchedulableItem> itemsToBeScheduledAtCompletion = null; itemsToBeScheduledAtCompletion = properties.ItemsToBeScheduledAtCompletion; if (itemsToBeScheduledAtCompletion == null) { itemsToBeScheduledAtCompletion = new List <SchedulableItem>(); properties.ItemsToBeScheduledAtCompletion = itemsToBeScheduledAtCompletion; } itemsToBeScheduledAtCompletion.Add(item); } } } }
public void PersistInstanceState(Activity activity) { this.lastExceptionThrown = null; this.abortTransaction = false; this.ScheduleDelayedItems(activity); if (this.currentAtomicActivity == null) { if (activity == this.rootActivity && !activity.PersistOnClose) { // This method is called when the root activity completes. We shouldn't perist unless the root has [PersistOnClose] return; } this.ServiceProvider.Persist(); } else { TransactionalProperties transactionalProperties = null; transactionalProperties = (TransactionalProperties)activity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); if (this.CheckAndProcessTransactionAborted(transactionalProperties)) { return; } // Complete and dispose transaction scope transactionalProperties.TransactionScope.Complete(); transactionalProperties.TransactionScope.Dispose(); transactionalProperties.TransactionScope = null; this.ServiceProvider.CommitTransaction(); transactionalProperties.Transaction = null; this.currentAtomicActivity = null; } this.internalCurrentActivity = activity; this.scheduler.Pause(); }
private void ScheduleDelayedItems(System.Workflow.ComponentModel.Activity atomicActivity) { List <SchedulableItem> itemsToBeScheduledAtCompletion = null; TransactionalProperties properties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty); if (properties != null) { lock (properties) { itemsToBeScheduledAtCompletion = properties.ItemsToBeScheduledAtCompletion; if (itemsToBeScheduledAtCompletion != null) { foreach (SchedulableItem item in itemsToBeScheduledAtCompletion) { this.scheduler.ScheduleItem(item, false); } itemsToBeScheduledAtCompletion.Clear(); properties.ItemsToBeScheduledAtCompletion = null; } } } }
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(); }