static void Main(string[] args) { Boolean isRunning = true; while (isRunning) { try { AutoResetEvent syncEvent = new AutoResetEvent(false); WorkflowApplication wfApp = new WorkflowApplication(new BookmarkCalculator()); wfApp.Completed = delegate( WorkflowApplicationCompletedEventArgs e) { if (e.CompletionState == ActivityInstanceState.Closed) { Console.WriteLine("Result = {0}", e.Outputs["Result"]); } syncEvent.Set(); }; wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e) { Console.WriteLine("Workflow is idle"); }; wfApp.OnUnhandledException = delegate( WorkflowApplicationUnhandledExceptionEventArgs e) { Console.WriteLine(e.UnhandledException.Message.ToString()); return(UnhandledExceptionAction.Terminate); }; wfApp.Run(); Console.WriteLine("Enter an expression or 'quit' to exit"); String expression = Console.ReadLine(); if ((String.IsNullOrEmpty(expression)) || (!String.IsNullOrEmpty(expression) && expression.Trim().ToLower() == "quit")) { wfApp.Cancel(); Console.WriteLine("Exiting program"); isRunning = false; } else if (IsBookmarkValid(wfApp, "GetString")) { wfApp.ResumeBookmark("GetString", expression); } syncEvent.WaitOne(); } catch (Exception exception) { Console.WriteLine("Error: {0}", exception.Message); } } }
public static void ReceivedNotification( String prompt, String bookmarkName) { Action <String, String> asyncWork = (msg, bm) => { Console.WriteLine(msg); String expression = Console.ReadLine(); if ((String.IsNullOrEmpty(expression)) || (!String.IsNullOrEmpty(expression) && expression.Trim().ToLower() == "quit")) { wfApp.Cancel(); Console.WriteLine("Exiting program"); isRunning = false; } else if (IsBookmarkValid(wfApp, bm)) { wfApp.ResumeBookmark(bm, expression); } }; //ar = IAsyncResult asyncWork.BeginInvoke(prompt, bookmarkName, ar => { ((Action <String, String>)ar.AsyncState).EndInvoke(ar); }, asyncWork); }
public void Stop() { if (_workflowApplication != null) { ClientInstancesManager.GetInstance().GetComputer(ClientId).Status = "Ready"; _workflowApplication.Cancel(); } }
/// <summary> /// Stop /// </summary> private void Stop() { if (_host == null) { return; } _host.Cancel(); }
public void TestStateMachineWorkflow() { var a = new TurnstileStateMachine(); var app = new WorkflowApplication(a); app.InstanceStore = WFDefinitionStore.Instance.Store; app.PersistableIdle = (eventArgs) => { return(PersistableIdleAction.None); //Must be None so 1 application instance will do all states }; var id = app.Id; // var stp = new StatusTrackingParticipant(); // app.Extensions.Add(stp); app.Run(); Thread.Sleep(200); //Run and ResumeBookmark are all non blocking asynchronous calls, better to wait prior operation to finish. var br = app.ResumeBookmark("coin", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); // Assert.Equal("Unlocked", stp.StateName); br = app.ResumeBookmark("coin", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); // Assert.Equal("Unlocked", stp.StateName); br = app.ResumeBookmark("push", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); // Assert.Equal("Locked", stp.StateName); br = app.ResumeBookmark("push", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); // Assert.Equal("Locked", stp.StateName); br = app.ResumeBookmark("funky", null); Assert.Equal(BookmarkResumptionResult.NotFound, br); Thread.Sleep(200); // Assert.Equal("Locked", stp.StateName); br = app.ResumeBookmark("coin", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200);//ResumeBookmark is asynchrounous in a new thread, so better to wait, otherwise they got killed when app.Cancel is executed. // Assert.Equal("Unlocked", stp.StateName); app.Cancel(); }
public void Dispose() { if (wfApp?.InstanceStore != null) { wfApp?.Unload(); } else { wfApp?.Cancel(); } }
private static void RunActivity(Activity activity, TestType testType) { Console.WriteLine("\n{0} {1}", activity.DisplayName, testType); AutoResetEvent waitEvent = new AutoResetEvent(false); WorkflowApplication wfApp = new WorkflowApplication(activity); wfApp.Completed = (e) => { Console.WriteLine("WorkflowApplication.Completed"); waitEvent.Set(); }; wfApp.Aborted = (e) => { Console.WriteLine("WorkflowApplication.Aborted"); waitEvent.Set(); }; wfApp.OnUnhandledException = (e) => { Console.WriteLine("WorkflowApplication.OnUnhandledException: {0}", e.UnhandledException.Message); return(UnhandledExceptionAction.Cancel); }; wfApp.Run(); switch (testType) { case TestType.Cancel: Thread.Sleep(100); wfApp.Cancel(); break; case TestType.Abort: Thread.Sleep(100); wfApp.Abort("Abort was called"); break; case TestType.Terminate: Thread.Sleep(100); wfApp.Terminate("Terminate was called"); break; default: break; } waitEvent.WaitOne(TimeSpan.FromSeconds(60)); }
private void AbortWorkers() { foreach (JobSlice jobSlice in job.JobSlices) { try { if (jobSlice.WorkflowInstanceId != Guid.Empty) { WorkflowApplication wfApp = new WorkflowApplication(new Worker()); wfApp.Load(jobSlice.WorkflowInstanceId); wfApp.Cancel(); } } catch { } } }
public string ExecuteWF(User user, bool reject = false) { string retMsg = "SuccessWF"; if (user == null || user.WorkflowInstId == Guid.Empty) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("model", user); instance = new WorkflowApplication(new AdminRights(), dic); this.InitWorkflowApplication(); instance.Run(); } else { AdminRights rights = new AdminRights(); instance = new WorkflowApplication(rights); this.InitWorkflowApplication(); instance.Load(user.WorkflowInstId); string approver = "SuperAdmin"; if (reject) { //更新状态 WFinstanceDAL wfDal = new WFinstanceDAL(); wfDal.Add(user.WorkflowInstId.ToString(), approver, "驳回"); WFCurrentNodeInfoDAL infoDal = new WFCurrentNodeInfoDAL(); infoDal.UpdateExitTime(user.WorkflowInstId.ToString(), DateTime.Now); instance.Cancel(); retMsg = "驳回成功"; } if (instance.GetBookmarks().Count > 0) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("model", user); dic.Add("curApproveUser", approver); instance.ResumeBookmark("BookmarkTest", dic); } } user.WorkflowInstId = instance.Id; //等待工作线程结束 idleEvent.WaitOne(); instance.Unload(); return(retMsg); }
public static WorkflowApplication CancelWorkflow(System.Activities.Activity workflowDefinition, Guid instanceId) { // Try to load the workflow and cancel it. var ars = new AutoResetEvent(false); WorkflowApplication wfApp = CreateWorkflowApplication(workflowDefinition); InstanceHandle ownerHandle = InitializeInstanceStore(workflowDefinition, wfApp); RegisterWorkflowApplicationEvents(ownerHandle, wfApp, ars); wfApp.Load(instanceId); wfApp.Cancel(); ars.WaitOne(); return(wfApp); }
private void Cancel_Click(object sender, RoutedEventArgs e) { wa.Cancel(); }
public void Cancel() { _workflow.Cancel(); }
static void Main(string[] args) { Boolean isRunning = true; while (isRunning) { try { AutoResetEvent syncEvent = new AutoResetEvent(false); WorkflowApplication wfApp = new WorkflowApplication(new BookmarkCalculatorExtension()); wfApp.Completed = delegate( WorkflowApplicationCompletedEventArgs e) { if (e.CompletionState == ActivityInstanceState.Closed) { Console.WriteLine("Result = {0}", e.Outputs["Result"]); } syncEvent.Set(); }; wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e) { Console.WriteLine("Workflow is idle"); }; wfApp.OnUnhandledException = delegate( WorkflowApplicationUnhandledExceptionEventArgs e) { Console.WriteLine(e.UnhandledException.Message.ToString()); return(UnhandledExceptionAction.Terminate); }; HostQueueNotifier extension = new HostQueueNotifier(); wfApp.Extensions.Add(extension); wfApp.Run(); if (extension.MessageAvailableEvent.WaitOne()) { HostNotifyMessage msg = null; lock (extension.MessageQueue) { if (extension.MessageQueue.Count > 0) { msg = extension.MessageQueue.Dequeue(); } } if (msg != null) { Console.WriteLine(msg.Message); String expression = Console.ReadLine(); if ((String.IsNullOrEmpty(expression)) || (!String.IsNullOrEmpty(expression) && expression.Trim().ToLower() == "quit")) { wfApp.Cancel(); Console.WriteLine("Exiting program"); isRunning = false; } else if (IsBookmarkValid(wfApp, msg.BookmarkName)) { wfApp.ResumeBookmark( msg.BookmarkName, expression); } } } syncEvent.WaitOne(); } catch (Exception exception) { Console.WriteLine("Error: {0}", exception.Message); } } }
public void Cancel() { wfApp.Cancel(); wfApp = null; Dispose(); }
public void TestTurnstile() { var lockedState = new State() { DisplayName = "Locked" }; var unlockedState = new State() { DisplayName = "Unlocked" }; var insertCoinWhenLocked = new Transition() { To = unlockedState, Trigger = new Wakeup() { BookmarkName = "coin" }, }; var insertCoinWhenUnlocked = new Transition() { To = unlockedState, Trigger = new Wakeup() { BookmarkName = "coin" }, }; var pushWhenLocked = new Transition() { To = lockedState, Trigger = new Wakeup() { BookmarkName = "push" }, }; var pushWhenUnlocked = new Transition() { To = lockedState, Trigger = new Wakeup() { BookmarkName = "push" }, }; lockedState.Transitions.Add(pushWhenLocked); lockedState.Transitions.Add(insertCoinWhenLocked); unlockedState.Transitions.Add(pushWhenUnlocked); unlockedState.Transitions.Add(insertCoinWhenUnlocked); var a = new StateMachine() { InitialState = lockedState, }; a.States.Add(lockedState); a.States.Add(unlockedState); var app = new WorkflowApplication(a); app.InstanceStore = WFDefinitionStore.Instance.Store; app.PersistableIdle = (eventArgs) => { return(PersistableIdleAction.None); //Must be None so 1 application instance will do all states }; var id = app.Id; app.Extensions.Add(new Fonlow.Utilities.TraceWriter()); var stp = new StatusTrackingParticipant(); app.Extensions.Add(stp); app.Run(); Thread.Sleep(200); //Run and ResumeBookmark are all non blocking asynchronous calls, better to wait prior operation to finish. var br = app.ResumeBookmark("coin", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); Assert.Equal("Unlocked", stp.StateName); br = app.ResumeBookmark("coin", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); Assert.Equal("Unlocked", stp.StateName); br = app.ResumeBookmark("push", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); Assert.Equal("Locked", stp.StateName); br = app.ResumeBookmark("push", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200); Assert.Equal("Locked", stp.StateName); br = app.ResumeBookmark("funky", null); Assert.Equal(BookmarkResumptionResult.NotFound, br); Thread.Sleep(200); Assert.Equal("Locked", stp.StateName); br = app.ResumeBookmark("coin", null); Assert.Equal(BookmarkResumptionResult.Success, br); Thread.Sleep(200);//ResumeBookmark is asynchrounous in a new thread, so better to wait, otherwise they got killed when app.Cancel is executed. Assert.Equal("Unlocked", stp.StateName); app.Cancel(); }
/// <summary> /// Allows the demonstration of various scenarios using /// WorkflowApplication /// </summary> private static void BasicApplicationTest(TestScenario scenario) { AutoResetEvent waitEvent = new AutoResetEvent(false); WorkflowApplication wfApp = new WorkflowApplication( new HostingDemoWorkflow(), new Dictionary <String, Object> { { "ArgNumberToEcho", 1001 }, }); wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e) { switch (e.CompletionState) { case ActivityInstanceState.Closed: Console.WriteLine("Host: {0} Closed - Thread:{1} - {2}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId, e.Outputs["Result"]); break; case ActivityInstanceState.Canceled: Console.WriteLine("Host: {0} Canceled - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); break; case ActivityInstanceState.Executing: Console.WriteLine("Host: {0} Executing - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); break; case ActivityInstanceState.Faulted: Console.WriteLine( "Host: {0} Faulted - Thread:{1} - {2}:{3}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId, e.TerminationException.GetType(), e.TerminationException.Message); break; default: break; } waitEvent.Set(); }; wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e) { Console.WriteLine( "Host: {0} OnUnhandledException - Thread:{1} - {2}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId, e.UnhandledException.Message); waitEvent.Set(); return(UnhandledExceptionAction.Cancel); }; wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e) { Console.WriteLine("Host: {0} Aborted - Thread:{1} - {2}:{3}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId, e.Reason.GetType(), e.Reason.Message); waitEvent.Set(); }; wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e) { Console.WriteLine("Host: {0} Idle - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); }; wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e) { Console.WriteLine("Host: {0} PersistableIdle - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); return(PersistableIdleAction.Unload); }; wfApp.Unloaded = delegate(WorkflowApplicationEventArgs e) { Console.WriteLine("Host: {0} Unloaded - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); }; try { Console.WriteLine("Host: About to run {0} - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); //determine the demonstration scenario switch (scenario) { case TestScenario.Normal: wfApp.Run(); waitEvent.WaitOne(); break; //case TestScenario.TimeSpan: // wfApp.Run(TimeSpan.FromSeconds(1)); // waitEvent.WaitOne(); // break; case TestScenario.Cancel: wfApp.Run(); //Wait just a bit then cancel the workflow Thread.Sleep(1000); wfApp.Cancel(); waitEvent.WaitOne(); break; case TestScenario.Abort: wfApp.Run(); //Wait just a bit then abort the workflow Thread.Sleep(1000); wfApp.Abort("My aborted reason"); waitEvent.WaitOne(); break; case TestScenario.Terminate: wfApp.Run(); //Wait just a bit then terminate the workflow Thread.Sleep(1000); wfApp.Terminate("My termination reason"); waitEvent.WaitOne(); break; case TestScenario.BeginRun: wfApp.BeginRun(delegate(IAsyncResult ar) { Console.WriteLine( "Host: {0} BeginRunCallback - Thread:{1}", wfApp.Id, System.Threading.Thread.CurrentThread.ManagedThreadId); ((WorkflowApplication)ar.AsyncState).EndRun(ar); }, wfApp); waitEvent.WaitOne(); break; default: break; } } catch (Exception exception) { Console.WriteLine("Host: {0} exception:{1}:{2}", wfApp.Id, exception.GetType(), exception.Message); } }
public void CancelMarketMonitoring() { workflow.Cancel(); }