/// <summary> /// WaitForWorkflowTerminate /// </summary> /// <param name="request">Request</param> /// <returns>WorkflowInfo</returns> private WorkflowInfo WaitForWorkflowTerminate(ReStartWorkflowRequest request) { const int retryNum = 10; const int delayRetryMsec = 1000; WorkflowInfo oldWf = null; for (int wait = 0; wait < retryNum; wait++) { int tot; IEnumerable <string> workflowCodes; oldWf = _workflow.GetWorkflows(Guid.Parse(request.OldWorkflowId), string.Empty, string.Empty, false, null, null, string.Empty, string.Empty, 0, 10, out tot, out workflowCodes).First(); if (oldWf.Status == WorkflowStatusType.InProgress.ToString()) { System.Threading.Thread.Sleep(delayRetryMsec); } else { break; } } return(oldWf); }
/// <summary> /// ReStart Workflow /// </summary> /// <param name="request">Request</param> /// <returns>ReStartWorkflowResponse</returns> public ReStartWorkflowResponse ReStartWorkflow(ReStartWorkflowRequest request) { return(Channel.ReStartWorkflow(request)); }
/// <summary> /// ReStart Workflow /// </summary> /// <param name="request">Request</param> /// <returns>ReStartWorkflowResponse</returns> public ReStartWorkflowResponse ReStartWorkflow(ReStartWorkflowRequest request) { // Cancell workflow var resp = CancelWorkflow(new ControlWorkflowRequest { WorkflowOid = request.OldWorkflowId }); if (resp.Message != Library.Properties.Resources.SUCCESS_RESULT) { return(new ReStartWorkflowResponse { Message = resp.Message, WorkflowId = request.OldWorkflowId }); } // Wait for workflow to terminate WorkflowInfo oldWf = WaitForWorkflowTerminate(request); if (oldWf == null || oldWf.Status == WorkflowStatusType.InProgress.ToString()) { return(new ReStartWorkflowResponse { Message = "Workflow still running", WorkflowId = request.OldWorkflowId }); } // Get workflow parameters var props = _workflow.GetWorkflowParameters(Guid.Parse(request.OldWorkflowId)); var startWorkflowRequest = new StartWorkflowRequest { Domain = oldWf.Domain, WorkflowCode = oldWf.WorkflowCode, WfRuntimeValues = props.Select(p => new WfProperty { Name = p.Name, Type = p.Type, Value = p.Value }).ToArray() }; // Restart workflow var startWorkflowResponse = StartWorkflow(startWorkflowRequest); #if RESTART_SAME_AS_OLD // The code below can be used when we want to restart a workflow and forward its // execution till the existing one. // Usefull when we make changes which are not back compatible. We need to terminate all // the existing workflows and start new ones without having users to start from the begin // the process. // TODO: // can go till the old point of execution if (request.RestartMode == "SAME_AS_OLD") { // TODO: need to find the way to wait until wf activity finishes. System.Threading.Thread.Sleep(3000); var traces = _workflow.GetTraceForWorkflow(new[] { Guid.Parse(request.OldWorkflowId) }) .Where(t => t.Action == ActionTrace.TaskCompleted.ToString()); foreach (var trace in traces) { var task = _task.GetNextTasksForWorkflow(Guid.Parse(startWorkflowResponse.WorkflowId)) .Where(t => t.TaskCode == trace.Code) .FirstOrDefault(); if (task != null) { ApproveTask(new ApproveTaskRequest { TaskId = task.TaskOid.ToString(), CorrelationId = task.TaskCorrelationId, Result = trace.Result, TaskCode = trace.Code, WorkflowId = task.WorkflowOid.ToString() }); } } } #endif return(new ReStartWorkflowResponse { WorkflowId = startWorkflowResponse.WorkflowId, Message = Library.Properties.Resources.SUCCESS_RESULT }); }