public IEnumerable<WorkflowValidationMessage> Validate(WorkflowBatch workflowBatch) { foreach (var workflow in workflowBatch.Workflows) { foreach (var task in workflow.Tasks) { foreach (var parameter in task.Parameters) { if (!String.IsNullOrEmpty(parameter.Constant)) { if (workflowBatch.Constants.Where(item => item.Name == parameter.Constant).Count() == 0) { yield return new WorkflowValidationMessage { WorkflowBatchName = workflowBatch.Name, MessageType = WorkflowValidationMessageType.Error, WorkflowName = workflow.Name, WorkflowTaskName = task.Name, Message = String.Format("There is not a definition for constant with name: '{0}'", parameter.Constant) }; } } } } } }
public WorkflowRunner(WorkflowBatch batch) { WorkflowBatch = batch; Validators = new List<IWorkflowValidator>() { new UndefinedConstantValidator(), new UnreferencedConstantValidator() }; }
public List <Workflow> Patch(WorkflowBatch request) { if (true != request?.Any()) { throw new HttpError(HttpStatusCode.NotFound, "Request cannot be empty."); } var ret = new List <Workflow>(); var errors = new List <ResponseError>(); var errorMap = new Dictionary <string, string>(); var i = 0; request.ForEach(dto => { try { var obj = Patch(dto) as Workflow; ret.Add(obj); errorMap[$"{i}"] = $"true"; } catch (Exception ex) { errorMap[$"{i}"] = $"false"; errors.Add(new ResponseError() { Message = $"{ex.Message}{Environment.NewLine}{ex.InnerException?.Message}", ErrorCode = $"{i}" }); } i += 1; }); base.Response.AddHeader("X-AutoBatch-Completed", $"{ret.Count} succeeded"); if (errors.Any()) { throw new HttpError(HttpStatusCode.BadRequest, $"{errors.Count} failed in batch") { Response = new ErrorResponse() { ResponseStatus = new ResponseStatus { ErrorCode = nameof(HttpError), Meta = errorMap, Message = "Incomplete request", Errors = errors } } }; } return(ret); }
public IEnumerable<WorkflowValidationMessage> Validate(WorkflowBatch workflowBatch) { foreach (var constant in workflowBatch.Constants) { foreach (var variable in workflowBatch.Variables) { if (workflowBatch.Variables.Where(item => item.ConstantName == constant.Name).Count() == 0) { yield return new WorkflowValidationMessage { MessageType = WorkflowValidationMessageType.Warning, WorkflowBatchName = workflowBatch.Name, Message = String.Format("Constant in variable with name: '{0}' doesn't have any reference in tasks' parameters", constant.Name) }; } } } foreach (var constant in workflowBatch.Constants) { foreach (var workflow in workflowBatch.Workflows) { foreach (var task in workflow.Tasks) { if (task.Parameters.Where(item => item.Constant == constant.Name).Count() == 0) { yield return new WorkflowValidationMessage { WorkflowBatchName = workflowBatch.Name, WorkflowTaskName = task.Name, MessageType = WorkflowValidationMessageType.Warning, WorkflowName = workflow.Name, Message = String.Format("Constant with name: '{0}' doesn't have any reference in tasks' parameters", constant.Name) }; } } } } }
public static WorkflowBatch GetRegisterCustomerWorkflowBatch() { var workflowBatch = new WorkflowBatch { Name = "Register Customer" }; workflowBatch.Constants = new List<WorkflowConstant>() { new WorkflowConstant { Name = "CountryName", Value = "UK" } }; workflowBatch.Workflows = new List<Workflow>() { new Workflow { Name = "Authentication", Description = "Authenticate user against system", Tasks = new List<WorkflowTask>() { new WorkflowTask { Name = "Log In", Description = "User login", Parameters = new List<WorkflowParameter>() { new WorkflowParameter { Name = "UserName", Value = "JuanPerez" }, new WorkflowParameter { Name = "Password", Value = "abcd2016" } }, Delay = 3000 } } }, new Workflow { Name = "Register customer", Description = "Register new customer", Tasks = new List<WorkflowTask>() { new WorkflowTask { Name = "Add customer's data", Description = "Add information for customer's fields", Parameters = new List<WorkflowParameter>() { new WorkflowParameter { Name = "CompanyName", Value = "Acme" }, new WorkflowParameter { Name = "ContactName", Value = "John Doe" }, new WorkflowParameter { Name = "ContactTitle", Value = "Mr." }, new WorkflowParameter { Name = "Country", Constant = "CountryName" }, }, Delay = 5000 } } }, new Workflow { Name = "Logging off", Description = "Logging off user's session", Tasks = new List<WorkflowTask>() { new WorkflowTask { Name = "Sign Out", Description = "Sign out", Delay = 2000 } } } }; return workflowBatch; }
public List <Workflow> Put(WorkflowBatch request) { return(Patch(request)); }