public async Task <WorkflowsVM> CompletedWorkflows(string projectId, string user) { ExistingWorkflows existingWorkflows = new ExistingWorkflows(_ampRepository.GetWorkflowMastersByProject(projectId)); WorkflowsVM workflowsVm = new WorkflowsVM(); List <CompletedWorkflowVM> completedWorkflowVms = new List <CompletedWorkflowVM>(); List <Tuple <WorkflowMaster, WorkflowMaster> > completedTupleList = new List <Tuple <WorkflowMaster, WorkflowMaster> >(); List <WorkflowMaster> completedRequests = existingWorkflows.CompletedRequests().OrderByDescending(x => x.WorkFlowID).ToList(); List <WorkflowMaster> completedResponses = existingWorkflows.CompletedResponses().OrderByDescending(x => x.WorkFlowID).ToList(); for (int i = 0; i < completedRequests.Count(); i++) { WorkflowRequest request = new WorkflowRequest(_personService); WorkflowResponse response = new WorkflowResponse(_personService); request.workflow = completedRequests.ElementAt(i); response.workflow = completedResponses.ElementAt(i); CompletedWorkflow completed = new CompletedWorkflow(_ampRepository, _documentService); await completed.Construct(request, response); completedWorkflowVms.Add(completed); } workflowsVm.workflows = completedWorkflowVms; return(workflowsVm); }
public async Task <WorkflowVM> WorkflowByProjectIdAndTaskId(string projectId, Int32 taskId, string user) { if (string.IsNullOrEmpty(projectId)) { throw new ArgumentException("String is null or empty", "projectId"); } if (string.IsNullOrEmpty(user)) { throw new ArgumentException("String is null or empty", "user"); } ExistingWorkflows existingWorkflows = new ExistingWorkflows(_ampRepository.GetWorkflowMastersByProjectandTask(projectId, taskId)); WorkflowRequest workflowRequest = new WorkflowRequest(_personService); WorkflowResponse workflowResponse = new WorkflowResponse(_personService); WorkflowConfiguration configuration = new WorkflowConfiguration(); WorkflowObject workflowObj = new WorkflowObject(_ampRepository, taskId, _documentService); string projectStage = _ampRepository.GetProject(projectId).Stage; string userRole = ""; if (taskId == Constants.PlannedEndDate) // set up the message to workflow screen for planned end date { ProjectPlannedEndDate projectPlannedEndDate = _ampRepository.GetProjectPlannedEndDate(projectId); string message = WorkflowMessages.PlannedEndDatePendingApprovalMessage(projectPlannedEndDate.NewPlannedEndDate); workflowObj.WfMessage = message; } if (existingWorkflows.HasActiveWorkflow()) { workflowRequest.workflow = existingWorkflows.ActiveWorkflowRequest(); workflowResponse.CreateResponse(workflowRequest.workflow); userRole = SetUserRole(user, projectId, workflowRequest.workflow.Recipient); } else if (existingWorkflows.LastWorkflowWasRejected()) { workflowRequest.workflow = existingWorkflows.LastRejectedWorkflowRequest(); workflowResponse.workflow = existingWorkflows.LastRejectedWorkflowResponse(); userRole = SetUserRole(user, projectId, workflowRequest.workflow.Recipient); } else { workflowRequest.CreateRequest(projectId, taskId, user); workflowResponse.response = new WorkflowMaster(); userRole = SetUserRole(user, projectId, null); } await workflowObj.Construct(workflowRequest, workflowResponse, userRole); return(workflowObj); }
/// <summary> /// Cancel a running workflow /// </summary> /// <param name="runId"></param> public static void CancelRun(long runId) { var run = Entity.Get <WorkflowRun>(runId, true, WorkflowRun.TaskId_Field, WorkflowRun.WorkflowRunStatus_Field); if (run == null) { throw new MissingRunException(); } if (run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunCancelled || run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunCompleted || run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunFailed) { return; } // Cancel the run run.WorkflowRunStatus_Enum = WorkflowRunState_Enumeration.WorkflowRunCancelled; run.RunCompletedAt = DateTime.UtcNow; run.Save(); // mark it as complete Factory.WorkflowRunTaskManager.RegisterCancelled(run.TaskId); // Update the diagnostics info var response = new WorkflowResponse { TenantName = RequestContext.GetContext().Tenant.Name, Id = run.Id, TaskId = run.TaskId, WorkflowName = run?.WorkflowBeingRun?.Name, WorkflowRunName = run?.Name, Status = WorkflowRunState_Enumeration.WorkflowRunCancelled.ToString(), Date = DateTime.Now, TriggeredBy = run.TriggeringUser != null ? run.TriggeringUser.Name : "Unknown", Server = Environment.MachineName, Process = Process.GetCurrentProcess().MainModule.ModuleName, StepCount = run.RunStepCounter ?? -1 }; ReadiNow.Diagnostics.DiagnosticChannel.Publish(response); }
public async Task <WorkflowVM> WorkflowByWorkflowId(Int32 workflowId, string user) { string userRole; Int32 taskId; string projectId; ExistingWorkflows existingWorkflows = new ExistingWorkflows(_ampRepository.GetWorkflowMasters(workflowId)); if (existingWorkflows.HasWorkflows()) { WorkflowRequest request = new WorkflowRequest(_personService); WorkflowResponse response = new WorkflowResponse(_personService); WorkflowConfiguration configuration = new WorkflowConfiguration(); WorkflowObject workflowObj; request.workflow = existingWorkflows.WorkflowRequest(workflowId); response.workflow = existingWorkflows.WorkflowResponse(workflowId); taskId = request.workflow.TaskID; projectId = request.workflow.ProjectID; string projectStage = _ampRepository.GetProject(projectId).Stage; workflowObj = new WorkflowObject(_ampRepository, request.workflow.TaskID, _documentService); userRole = SetUserRole(user, request.workflow.ProjectID, request.workflow.Recipient); await workflowObj.Construct(request, response, userRole); if (taskId == Constants.PlannedEndDate && response.workflow.StageID != 3)// set up the message to workflow screen for planned end date only if approved { ProjectPlannedEndDate projectPlannedEndDate = _ampRepository.GetProjectPlannedEndDatForWorkflowHistory(workflowId); string message = WorkflowMessages.PlannedEndDateWorkflowHistoryMessage(projectPlannedEndDate.CurrentPlannedEndDate, projectPlannedEndDate.NewPlannedEndDate); workflowObj.WfMessage = message; } return(workflowObj); } return(null); }
public static ProcessWorkflowResponseRequest New(Contract contract, WorkflowResponse response, Guid trackingReference) => new ProcessWorkflowResponseRequest(new WorkflowResponseProcessingPayload(contract, response, trackingReference));