//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace System.Activities.Statements { using System; using System.Activities.Hosting; using System.Collections.Generic; using System.Linq; using System.Runtime; using System.Text; /// /// StateMachineExtension is used to resume a bookmark outside StateMachine. /// class StateMachineExtension : IWorkflowInstanceExtension { private WorkflowInstanceProxy instance; /// /// Used to get additional extensions. /// /// Returns a IEnumerable of extensions public IEnumerable GetAdditionalExtensions() { return null; } /// /// called with the targe instance under WorkflowInstance.Initialize /// /// The value of WorkflowInstanceProxy public void SetInstance(WorkflowInstanceProxy instance) { this.instance = instance; } /// /// Used to resume bookmark outside workflow. /// /// The value of Bookmark to be resumed public void ResumeBookmark(Bookmark bookmark) { // This method is necessary due to CSDMain 223257. IAsyncResult asyncResult = this.instance.BeginResumeBookmark(bookmark, null, Fx.ThunkCallback(new AsyncCallback(StateMachineExtension.OnResumeBookmarkCompleted)), this.instance); if (asyncResult.CompletedSynchronously) { this.instance.EndResumeBookmark(asyncResult); } } static void OnResumeBookmarkCompleted(IAsyncResult result) { if (!result.CompletedSynchronously) { WorkflowInstanceProxy instance = result.AsyncState as WorkflowInstanceProxy; Fx.Assert(instance != null, "BeginResumeBookmark should pass a WorkflowInstanceProxy object as the async state object."); instance.EndResumeBookmark(result); } } } }