private void setWFEvents(WorkflowApplication wf) { wf.Idle = delegate(WorkflowApplicationIdleEventArgs e) { Console.WriteLine("Workflow idled"); s_idleEvent.Set(); //s_syncEvent.Set(); }; wf.Completed = delegate(WorkflowApplicationCompletedEventArgs e) { Console.WriteLine("Workflow completed with state {0}.", e.CompletionState.ToString()); if (e.TerminationException != null) { Console.WriteLine("TerminationException = {0}; {1}", e.TerminationException.GetType().ToString(), e.TerminationException.Message); } s_completedEvent.Set(); //s_syncEvent.Set(); }; wf.Unloaded = delegate(WorkflowApplicationEventArgs e) { Console.WriteLine("Workflow unloaded"); if (this.invokeMode == WorkflowInvokeMode.Run) { this.invokeMode = WorkflowInvokeMode.ResumeBookmark; } else { this.invokeMode = WorkflowInvokeMode.None; } s_unloadedEvent.Set(); //s_syncEvent.Set(); }; wf.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e) { if (instanceStore != null) { return(PersistableIdleAction.Unload); } return(PersistableIdleAction.None); }; wf.Aborted = e => { int a = 0; //syncEvent.Set(); s_syncEvent.Set(); }; //wfApp.Idle = e => { /*syncEvent.Set();*/ }; //wfApp.PersistableIdle = e => { return PersistableIdleAction.Unload; }; //wfApp.OnUnhandledException = e => { return UnhandledExceptionAction.Terminate; }; }
public TResponse ContinueWorkflow <TRequest, TResponse>(TRequest request, string OperationName) { invokeMode = WorkflowInvokeMode.ResumeBookmark; return(execute <TRequest, TResponse>(request, OperationName)); }
public TResponse StartWorkflow <TRequest, TResponse>(TRequest request, string OperationName) { TimeSpan timeOut = TimeSpan.FromMinutes(1); Action waitOne = delegate() { s_syncEvent = null; if (instanceStore != null) { s_syncEvent = s_unloadedEvent; s_unloadedEvent.WaitOne(); } else { s_syncEvent = s_idleEvent; s_idleEvent.WaitOne(); } }; WorkflowInstanceContext instanceContext = new WorkflowInstanceContext() { Request = request, Response = default(TResponse) }; invokeMode = WorkflowInvokeMode.Run; WorkflowApplication wfApp = null; Guid wfId = Guid.Empty; while (invokeMode != WorkflowInvokeMode.None) { if (invokeMode == WorkflowInvokeMode.Run) { wfApp = createWorkflowApplication(instanceContext); wfId = wfApp.Id; resetEvents(); wfApp.Run(timeOut); waitOne(); } else if (invokeMode == WorkflowInvokeMode.ResumeBookmark) { wfApp = createWorkflowApplication(instanceContext); resetEvents(); wfApp.Load(wfId, timeOut); var isWaiting = wfApp.GetBookmarks().FirstOrDefault(b => b.BookmarkName == OperationName); if (isWaiting != null) { wfApp.ResumeBookmark(OperationName, "bookmark data", timeOut); waitOne(); } else { throw new Exception($"Bookmark {OperationName} missing on workflow with id {wfApp.Id}"); } } } ; TResponse response = default(TResponse); try { response = (TResponse)instanceContext.Response; } catch { } return(response); }
public TResponse StartWorkflow <TRequest, TResponse>(TRequest request, string OperationName) { invokeMode = WorkflowInvokeMode.Run; return(execute <TRequest, TResponse>(request, OperationName)); }