private TResponse StartWorkflow_todelete <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); this.WorkflowId = wfApp.Id; resetEvents(); wfApp.Run(timeOut); waitOne(); } else if (invokeMode == WorkflowInvokeMode.ResumeBookmark) { wfApp = createWorkflowApplication(instanceContext); resetEvents(); wfApp.Load(this.WorkflowId, 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); }
private TResponse execute <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(); } }; Action correlate = delegate() { if (instanceStore is IStoreCorrelation) { (instanceStore as IStoreCorrelation).Correlate(); this.WorkflowId = (instanceStore as IStoreCorrelation).Correlation.WorkflowId; } }; WorkflowInstanceContext instanceContext = new WorkflowInstanceContext() { Request = request, Response = default(TResponse) }; WorkflowApplication wfApp = null; //Guid wfId = Guid.Empty; while (invokeMode != WorkflowInvokeMode.None) { if (invokeMode == WorkflowInvokeMode.Run) { wfApp = createWorkflowApplication(instanceContext); this.WorkflowId = wfApp.Id; (wfApp.InstanceStore as IStoreCorrelation).Correlation.WorkflowId = wfApp.Id; resetEvents(); wfApp.Run(timeOut); waitOne(); } else if (invokeMode == WorkflowInvokeMode.ResumeBookmark) { wfApp = createWorkflowApplication(instanceContext); resetEvents(); correlate(); if (this.WorkflowId == Guid.Empty) { throw new Exception($"WorkflowId missing on workflow with"); } wfApp.Load(this.WorkflowId, timeOut); var ext = wfApp.Extensions; 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}"); } } if (exception != null) { throw exception; } } ; TResponse response = default(TResponse); try { response = (TResponse)instanceContext.Response; } catch (Exception exc) //TODO: System.InvalidCastException { throw exc; } return(response); }