/// <summary> /// Initializes a new instance of the <see cref="T:ActionEventArgs"/> class. /// </summary> /// <param name="workflowId">The workflow ID.</param> /// <param name="failureReason">The failure reason.</param> /// <param name="cancelled">if set to <c>true</c> [cancelled].</param> public WorkflowCompleteEventArgs(string workflowId, Exception failureReason, bool cancelled) { WorkflowId = workflowId; _workflowStatus = cancelled == true ? WorkflowStatusEnum.Cancelled : WorkflowStatusEnum.Error; if (_workflowStatus == WorkflowStatusEnum.Error) { FailureReason = failureReason; } }
/// <summary> /// Initializes a new instance of the <see cref="T:ActionEventArgs"/> class. /// </summary> /// <param name="workflowId">The workflow ID.</param> /// <param name="failureReason">The failure reason.</param> public WorkflowCompleteEventArgs(string workflowId, Exception failureReason) { WorkflowId = workflowId; _workflowStatus = WorkflowStatusEnum.Error; if (failureReason == null) { failureReason = new ApplicationException("The operation was cancelled because the internet connection was dropped."); } FailureReason = failureReason; }
/// <summary> /// Begins the execution of the request. The request is asyncronous. When the execution /// has completed, the WorkflowComplete event will be raised. /// </summary> public void Execute() { if (_status != WorkflowStatusEnum.Pending) { throw new InvalidOperationException("The Workflow was in an incorrect state!"); } _status = WorkflowStatusEnum.Executing; //Call the implementattion of the derived class to begin execution ExecuteWorkflow(); }
public static WorkflowStatusEnum GetHigherImportance(WorkflowStatusEnum status1, WorkflowStatusEnum status2) { WorkflowStatusEnum retStatus = WorkflowStatusEnum.Normal; if (status1.Equals(status2)) { retStatus = status1; } else { switch (status1) { case WorkflowStatusEnum.Hidden: { //Nothing beats Hidden. retStatus = status1; } break; case WorkflowStatusEnum.Inactive: { //The only ones that beat 'Inactive' is Hidden. if (status2 == WorkflowStatusEnum.Hidden) { retStatus = status2; } } break; case WorkflowStatusEnum.Normal: { //Everything else beats Normal retStatus = status2; } break; case WorkflowStatusEnum.Required: { //Inactive and Hidden beats Required. if (status2 == WorkflowStatusEnum.Inactive || status2 == WorkflowStatusEnum.Hidden) { retStatus = status2; } } break; } } return(retStatus); }
private static void WriteBackTheState(WorkflowStatusEnum state, Guid instanceId) { var stateContent = GetStateContent(instanceId); if (stateContent == null) { return; } switch (stateContent.WorkflowStatus) { case WorkflowStatusEnum.Created: if (state == WorkflowStatusEnum.Created) { return; } break; case WorkflowStatusEnum.Running: if (state == WorkflowStatusEnum.Created || state == WorkflowStatusEnum.Running) { return; } break; case WorkflowStatusEnum.Aborted: case WorkflowStatusEnum.Completed: return; default: break; } var times = 3; while (true) { try { stateContent.WorkflowStatus = state; stateContent.DisableObserver(typeof(WorkflowNotificationObserver)); using (new SystemAccount()) stateContent.Save(SenseNet.ContentRepository.SavingMode.KeepVersion); Debug.WriteLine(String.Format("##WF> InstanceManager: WriteBackTheState: {0}, id: {1}, path: {2}", state, instanceId, stateContent.Path)); break; } catch (NodeIsOutOfDateException ne) { if (--times == 0) { throw new NodeIsOutOfDateException("Node is out of date after 3 trying", ne); } var msg = "InstanceManager: Writing back the workflow state caused NodeIsOutOfDateException. Trying again"; Debug.WriteLine("##WF> " + msg); Logger.WriteVerbose(msg); stateContent = (WorkflowHandlerBase)Node.LoadNodeByVersionId(stateContent.VersionId); } catch (Exception e) { var msg = String.Format("Workflow state is {0} but cannot write back to the workflow state content. InstanceId: {1}. Path: {2}" , state, instanceId, stateContent.Path); Debug.WriteLine("##WF> " + msg); Logger.WriteWarning(msg, Logger.EmptyCategoryList, new Dictionary <string, object> { { "Exception", e } }); break; } } }
private WorkflowStatus runWorkflow(string workflowName, IDictionary <string, object> parameters, Guid?workflowInstanceId, string bookmarkName, bool response) { Activity workflowDefinition = GetWorkflow(workflowName); using (var store = new Neo4jInstanceStore(client, workflowStoreId)) { WorkflowStatusEnum status = WorkflowStatusEnum.InProgress; string bookmark = null; bool?result = null; var instanceUnloaded = new AutoResetEvent(false); WorkflowApplication app; if (parameters == null) { app = new WorkflowApplication(workflowDefinition); } else { // Only pass in parameters that the appear in the workflow var parametersDefinedInThisWorkflow = getAvailableSettingsForWorkflow(workflowDefinition); var applicableParameters = parameters .Where(a => parametersDefinedInThisWorkflow.Contains(a.Key)) .ToDictionary(a => a.Key, a => a.Value); app = new WorkflowApplication(workflowDefinition, applicableParameters); } app.InstanceStore = store; app.PersistableIdle = (e) => { return(PersistableIdleAction.Unload); }; app.Completed = (arg) => { Console.WriteLine("Workflow has Completed in the {0} state.", arg.CompletionState); status = WorkflowStatusEnum.Completed; // If the result of the workflow is a boolean, use that value, otherwise the workflow must be so // simple that it doesn't return anything, so we'll set the result to true. if (arg.Outputs.ContainsKey("Result") && arg.Outputs["Result"] is bool) { result = (bool)arg.Outputs["Result"]; } else { result = true; } }; app.Unloaded = (arg) => { Console.WriteLine("Workflow has Unloaded."); instanceUnloaded.Set(); }; app.Idle = (idle) => { bookmark = idle.Bookmarks.Select(a => a.BookmarkName).FirstOrDefault(); Console.WriteLine("Workflow has Idled."); }; if (workflowInstanceId.HasValue) { app.Load(workflowInstanceId.Value); app.ResumeBookmark(bookmarkName, response); } else { workflowInstanceId = app.Id; app.Run(); Console.WriteLine("Started instance #" + workflowInstanceId.Value); } // Wait for the workflow to complete before returning the data instanceUnloaded.WaitOne(); return(new WorkflowStatus { InstanceId = workflowInstanceId.Value, Status = status, Bookmark = bookmark, Result = result }); } }
/// <summary> /// Initializes a new instance of the <see cref="T:ActionEventArgs"/> class. /// </summary> /// <param name="workflowId">The workflow ID.</param> /// <param name="cancelled">if set to <c>true</c> [cancelled].</param> public WorkflowCompleteEventArgs(string workflowId, bool cancelled) { WorkflowId = workflowId; _workflowStatus = cancelled == true ? WorkflowStatusEnum.Cancelled : WorkflowStatusEnum.Error; FailureReason = new ApplicationException("Operation failed."); }
/// <summary> /// Initializes a new instance of the <see cref="T:ActionEventArgs"/> class. /// </summary> /// <param name="workflowId">The workflow ID.</param> public WorkflowCompleteEventArgs(string workflowId) { _workflowStatus = WorkflowStatusEnum.Success; WorkflowId = workflowId; }
private static void WriteBackTheState(WorkflowStatusEnum state, Guid instanceId) { var stateContent = GetStateContent(instanceId); if (stateContent == null) return; switch (stateContent.WorkflowStatus) { case WorkflowStatusEnum.Created: if (state == WorkflowStatusEnum.Created) return; break; case WorkflowStatusEnum.Running: if (state == WorkflowStatusEnum.Created || state == WorkflowStatusEnum.Running) return; break; case WorkflowStatusEnum.Aborted: case WorkflowStatusEnum.Completed: return; default: break; } var times = 3; while (true) { try { stateContent.WorkflowStatus = state; stateContent.DisableObserver(typeof(WorkflowNotificationObserver)); using (new SystemAccount()) stateContent.Save(SenseNet.ContentRepository.SavingMode.KeepVersion); Debug.WriteLine(String.Format("##WF> InstanceManager: WriteBackTheState: {0}, id: {1}, path: {2}", state, instanceId, stateContent.Path)); break; } catch (NodeIsOutOfDateException ne) { if (--times == 0) throw new NodeIsOutOfDateException("Node is out of date after 3 trying", ne); var msg = "InstanceManager: Writing back the workflow state caused NodeIsOutOfDateException. Trying again"; Debug.WriteLine("##WF> " + msg); Logger.WriteVerbose(msg); stateContent = (WorkflowHandlerBase)Node.LoadNodeByVersionId(stateContent.VersionId); } catch (Exception e) { var msg = String.Format("Workflow state is {0} but cannot write back to the workflow state content. InstanceId: {1}. Path: {2}" , state, instanceId, stateContent.Path); Debug.WriteLine("##WF> " + msg); Logger.WriteWarning(msg, Logger.EmptyCategoryList, new Dictionary<string, object> { { "Exception", e } }); break; } } }