Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / WorkflowStateRollbackService.cs / 1305376 / WorkflowStateRollbackService.cs
using System; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Reflection; using System.Text; using System.IO; using System.IO.Compression; using System.Transactions; using System.Workflow.ComponentModel; namespace System.Workflow.Runtime { internal sealed class WorkflowStateRollbackService { WorkflowExecutor workflowExecutor; // cache the revert back data MemoryStream clonedInstanceStateStream; Activity workflowDefinition = null; bool isInstanceStateRevertRequested = false; // revert back notification info string activityQualifiedName; int activityContextId; EventArgs callbackData; EventHandlercallbackHandler; bool suspendOnRevert; string suspendOnRevertInfo; Hashtable completedContextActivities = new Hashtable(); public WorkflowStateRollbackService(WorkflowExecutor workflowExecutor) { this.workflowExecutor = workflowExecutor; } internal bool IsInstanceStateRevertRequested { get { return this.isInstanceStateRevertRequested; } } internal void CheckpointInstanceState() { Debug.Assert(this.workflowExecutor.InstanceId != null, "instance id null at checkpoint time"); // serialize the instance state this.clonedInstanceStateStream = new MemoryStream(10240); this.workflowExecutor.RootActivity.Save(this.clonedInstanceStateStream); this.workflowDefinition = this.workflowExecutor.WorkflowDefinition; this.completedContextActivities = (Hashtable)this.workflowExecutor.CompletedContextActivities.Clone(); this.clonedInstanceStateStream.Position = 0; } internal void RequestRevertToCheckpointState(Activity currentActivity, EventHandler callbackHandler, EventArgs callbackData, bool suspendOnRevert, string suspendInfo) { if (this.clonedInstanceStateStream == null) throw new InvalidOperationException(ExecutionStringManager.InvalidRevertRequest); // cache the after revert information this.activityContextId = ContextActivityUtils.ContextId(ContextActivityUtils.ContextActivity(currentActivity)); this.activityQualifiedName = currentActivity.QualifiedName; this.callbackData = callbackData; this.callbackHandler = callbackHandler; this.suspendOnRevert = suspendOnRevert; this.suspendOnRevertInfo = suspendInfo; // ask scheduler to stop this.isInstanceStateRevertRequested = true; this.workflowExecutor.Scheduler.CanRun = false; } internal void DisposeCheckpointState() { this.clonedInstanceStateStream = null; } internal void RevertToCheckpointState() { Debug.Assert(this.clonedInstanceStateStream != null, "cloned instance-state stream null at restore time"); // deserialize only on first access Activity clonedRootActivity = null; this.clonedInstanceStateStream.Position = 0; using (RuntimeEnvironment runtimeEnv = new RuntimeEnvironment(this.workflowExecutor.WorkflowRuntime)) { clonedRootActivity = Activity.Load(this.clonedInstanceStateStream, (Activity)this.workflowDefinition); } Debug.Assert(clonedRootActivity != null); // // Set the trackingListenerBroker before initializing the executor so the tracking // runtime gets a reference to the correct object clonedRootActivity.SetValue(WorkflowExecutor.TrackingListenerBrokerProperty, workflowExecutor.RootActivity.GetValue(WorkflowExecutor.TrackingListenerBrokerProperty)); // create the new workflowExecutor WorkflowExecutor newWorkflowExecutor = new WorkflowExecutor(Guid.Empty); // use a dummy guid while swapping executors newWorkflowExecutor.Initialize(clonedRootActivity, this.workflowExecutor.WorkflowRuntime, this.workflowExecutor); // enqueue the activity notifier Activity activityContext = newWorkflowExecutor.GetContextActivityForId(this.activityContextId); Activity activity = activityContext.GetActivityByName(this.activityQualifiedName); using (new ServiceEnvironment(activity)) { using (newWorkflowExecutor.SetCurrentActivity(activity)) { using (ActivityExecutionContext executionContext = new ActivityExecutionContext(activity)) executionContext.Invoke (this.callbackHandler, this.callbackData); } } // // Push the batch item ordering id to the new instance newWorkflowExecutor.BatchCollection.WorkItemOrderId = this.workflowExecutor.BatchCollection.WorkItemOrderId; // replace pending batch items foreach (KeyValuePair
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CodeExporter.cs
- SafeMILHandle.cs
- Int16.cs
- RowType.cs
- ManagementScope.cs
- LabelAutomationPeer.cs
- XmlHierarchicalDataSourceView.cs
- DataSourceListEditor.cs
- TreeNodeCollectionEditor.cs
- XmlIlTypeHelper.cs
- ClientFormsIdentity.cs
- COAUTHIDENTITY.cs
- TraceContextRecord.cs
- DoubleLinkListEnumerator.cs
- PasswordPropertyTextAttribute.cs
- DataStreamFromComStream.cs
- ToolboxDataAttribute.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- CompilerErrorCollection.cs
- AttributeQuery.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- BindUriHelper.cs
- CryptoApi.cs
- ValueSerializer.cs
- StaticContext.cs
- httpapplicationstate.cs
- httpapplicationstate.cs
- ObjectIDGenerator.cs
- DataGridGeneralPage.cs
- Compress.cs
- Peer.cs
- ProfilePropertyMetadata.cs
- GZipUtils.cs
- InvalidWMPVersionException.cs
- SectionInformation.cs
- DockAndAnchorLayout.cs
- ParserStreamGeometryContext.cs
- LinqDataSourceContextEventArgs.cs
- XmlILStorageConverter.cs
- DbProviderSpecificTypePropertyAttribute.cs
- DefaultSerializationProviderAttribute.cs
- SrgsGrammar.cs
- XmlSchemaElement.cs
- DocumentViewerAutomationPeer.cs
- XmlSchemaChoice.cs
- ObjectDataSourceDisposingEventArgs.cs
- GestureRecognizer.cs
- Point4DValueSerializer.cs
- PositiveTimeSpanValidatorAttribute.cs
- Substitution.cs
- HexParser.cs
- InfoCardMetadataExchangeClient.cs
- EntityClientCacheEntry.cs
- ObjectCloneHelper.cs
- HwndHostAutomationPeer.cs
- ForceCopyBuildProvider.cs
- RegexGroup.cs
- HostingEnvironmentException.cs
- EmulateRecognizeCompletedEventArgs.cs
- JsonReaderWriterFactory.cs
- TailPinnedEventArgs.cs
- OrthographicCamera.cs
- FixedSOMFixedBlock.cs
- ModelPerspective.cs
- DbProviderServices.cs
- SqlDataSourceQueryEditorForm.cs
- TextServicesLoader.cs
- ISAPIApplicationHost.cs
- GenericWebPart.cs
- WebPartDisplayModeCollection.cs
- IdentitySection.cs
- ObjRef.cs
- EdmFunctions.cs
- IgnoreFileBuildProvider.cs
- WmpBitmapDecoder.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- SafeFindHandle.cs
- XamlWriter.cs
- WebSysDefaultValueAttribute.cs
- DNS.cs
- IPPacketInformation.cs
- ProviderIncompatibleException.cs
- TextEffect.cs
- Encoder.cs
- AuthenticationSection.cs
- ColumnMapVisitor.cs
- RealProxy.cs
- StringSorter.cs
- DataBindingCollection.cs
- ContextDataSource.cs
- cookieexception.cs
- ProcessInputEventArgs.cs
- IssuedTokenParametersElement.cs
- __ConsoleStream.cs
- PrintDocument.cs
- SafeNativeMethods.cs
- DesignerVerbCollection.cs
- VectorKeyFrameCollection.cs
- DynamicPropertyReader.cs