public void QueueExection(BpmWorkFlow workItem) { if (workItem == null) { throw new ArgumentNullException(nameof(workItem)); } _workItems.Enqueue(workItem); _signal.Release(); }
protected async override Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("Bpm Invoker Service is Starting"); while (!stoppingToken.IsCancellationRequested) { BpmWorkFlow bpmWorkFlow = await _invokerQueue.DequeueAsync(stoppingToken); if (bpmWorkFlow != null) { await invokeWorkFlow(bpmWorkFlow); } } _logger.LogInformation("Bpm Invoker Service is Stoping"); }
private async Task invokeWorkFlow(BpmWorkFlow bpmWorkFlow) { _logger.LogInformation("Bpm Invoker Service Invoking Workflow " + bpmWorkFlow.workflowName); using (var client = new HttpClient()) { try { string url = _config["BpmEngine:Address"] + "/engine/api/workflow?name="; _logger.LogInformation("Sending to " + url); await client.PostAsJsonAsync(url + bpmWorkFlow.workflowName, bpmWorkFlow.Param); } catch (Exception) { throw; } } }
public async Task <ActionResult> InvokeOrder(Order order) { List <Task> tasks = new List <Task>(); byte[] error = new byte[500]; List <ProductInOrder> productInOrders = await _orderProductRepository.ShowProductsInOrder(order.id, error); List <Product> products = new List <Product>(); if (checkQuery(error)) { BpmWorkFlow bpmWorkFlow = new BpmWorkFlow(); JObject jObject = new JObject(); bpmWorkFlow.workflowName = "node"; foreach (var productInOrder in productInOrders) { tasks.Add(Task.Run(async() => { byte[] err = new byte[500]; Console.WriteLine("pid = " + productInOrder.productID); Product product = await _productRepository.GetById(productInOrder.productID, err); if (checkQuery(err)) { products.Add(product); jObject.Add(product.name, (productInOrder.unitsOrdered.ToString())); } })); } await Task.WhenAll(tasks); bpmWorkFlow.Param = jObject; _bpmInvokerQueue.QueueExection(bpmWorkFlow); return(Ok("successfully Invoke")); } else { return(BadRequest("Error")); } }
public ActionResult RunWorkFlow(BpmWorkFlow bpmWorkFlow) { _bpmInvokerQueue.QueueExection(bpmWorkFlow); return(Ok()); }
public async Task <IActionResult> UploadWorkFlow(BpmWorkFlow bpmWorkFlow) { Console.WriteLine(bpmWorkFlow.workflowName); _logger.LogInformation("Bpm Invoker Service Invoking Workflow " + bpmWorkFlow.workflowName); using (var client = new HttpClient()) { try { string url = _config["BpmEngine:Address"] + "/engine/api/workflow?name="; _logger.LogInformation("Sending to " + url); await client.PostAsJsonAsync(url + bpmWorkFlow.workflowName, bpmWorkFlow.workFlowParam); } catch (Exception) { throw; } } //try //{ // bool isCopied = false; // if (file.Length > 0) // { // string fileName = file.FileName; // string extension = Path.GetExtension(fileName); // if (extension == ".xml") // { // string workFlowStr = null; // string WorkFlowName = null; // string workFlowId = null; // using (Stream stream = file.OpenReadStream()) // { // BinaryReader br = new BinaryReader(stream); // byte[] fileBytes = br.ReadBytes((int)stream.Length); // workFlowStr = Encoding.ASCII.GetString(fileBytes); // XmlDocument xmlDoc = new XmlDocument(); // stream.Position = 0; // xmlDoc.Load(stream); // var element = xmlDoc.GetElementsByTagName("nodes")[0]; // if (element == null) // { // throw new Exception("This xml file is not supported"); // } // WorkFlowName = element.Attributes["name"].Value; // //workFlowId = element.Attributes["id"].Value; // Console.WriteLine(WorkFlowName); // } // string filePath = Path.GetFullPath( // Path.Combine(Directory.GetCurrentDirectory(), // "wwwroot/WorkFlows")); // using (var fileStream = new FileStream( // Path.Combine(filePath, fileName), // FileMode.Create)) // { // await file.CopyToAsync(fileStream); // isCopied = true; // } // if (isCopied) // { // string idstr = workFlowId; // Console.WriteLine(idstr); // await _nodeLangRepository.Create(new NodeLangWorkflow // { // //Id = workFlowId, // Name = WorkFlowName, // //WorkFlow = workFlowStr, // RuningInstances = 0 // } // ); // await _hubcontext.Clients.All.SendAsync("updateDeployList", idstr, WorkFlowName, workFlowStr); // return Ok(); // } // } // else // { // throw new Exception("File must be .xml"); // } // } //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} return(BadRequest("error")); }