public async Task <WorkflowInstanceOut> CreateProcessInstance(WorkflowInstanceIn workflowInstance) { workflowInstance.TenantId = _apiConfiguration.WorkflowEngineConfig.TenantId; var serialized = JsonConvert.SerializeObject(workflowInstance, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); var stringContent = new StringContent(serialized); stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await _client.PostAsync($"runtime/process-instances", stringContent); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var responseString = response.Content.ReadAsStringAsync().Result; var instanceResponse = JsonConvert.DeserializeObject <WorkflowInstanceOut>(responseString); return(instanceResponse); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { throw new ExceptionWithFeedback(new FeedbackItem() { Description = $"The processInstance could not be created. Received a bad request from Workflow engine.", Type = FeedbackType.Error }); } if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { throw new ExceptionWithFeedback(new FeedbackItem() { Description = $"The processInstance could not be created. Received an internal server error from workflow engine.", Type = FeedbackType.Error }); } if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new EntityNotFoundException($"The endpoint to create the processInstance could not be found"); } return(null); }
public ProcessInstance CreateNewProcessInstance(string processDefinitionKey, Guid dossierId) { var workflowInstance = new WorkflowInstanceIn(); workflowInstance.ProcessDefinitionKey = processDefinitionKey; workflowInstance.Variables.Add(new WorkflowInstanceVariable() { Name = "DossierId", Value = dossierId }); var returnInstance = _workflowService.CreateProcessInstance(workflowInstance).Result; var processInstance = new ProcessInstance() { Id = returnInstance.Id, BusinessKey = returnInstance.BusinessKey, ProcessDefinitionKey = returnInstance.ProcessDefinitionKey, TenantKey = returnInstance.TenantKey }; returnInstance.Variables.ForEach(x => processInstance.Variables.Add(new ProcessVariable() { Name = x.Name, Value = x.Value })); return(processInstance); }