Esempio n. 1
0
        private void createResponse(ActionResult result, BpmTask bpmTask)
        {
            try
            {
                try
                {
                    OkResult x = (OkResult)result;
                    if (bpmTask.type != "userTask")
                    {
                        createSuccessResponse(new object[] {}, bpmTask);
                    }
                }
                catch (Exception)
                {
                    OkObjectResult x = (OkObjectResult)result;
                    if (bpmTask.type != "userTask")
                    {
                        createSuccessResponse(new object[] { x.Value }, bpmTask);
                    }
                }
            }
            catch (Exception ex)
            {
                BadRequestObjectResult x = (BadRequestObjectResult)result;

                createFailedResponse(x.Value, bpmTask);
            }
        }
Esempio n. 2
0
        public void QueueExection(BpmTask workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException(nameof(workItem));
            }

            _workItems.Enqueue(workItem);
            _signal.Release();
        }
        public async Task Execute(BpmTask bpmTask)
        {
            _logger.LogInformation("executing " + bpmTask.TaskName);

            using (var scope = Services.CreateScope())
            {
                var _sysServices = scope.ServiceProvider.GetRequiredService <SystemServices>();

                await _sysServices.findServiceAsync(bpmTask, scope);
            }
        }
Esempio n. 4
0
        private void createFailedResponse(object message, BpmTask bpmTask)
        {
            ServiceResponse bpmResponse = new ServiceResponse
            {
                Organization = bpmTask.databaseName,
                status       = "Failed",
                IsBpm        = bpmTask.IsBpm,
                InvokerId    = bpmTask.InvokerId,
                Type         = bpmTask.type,
                parameters   = message,
            };

            _responseQueue.QueueExection(bpmResponse);
        }
Esempio n. 5
0
        private void createSuccessResponse(object[] param, BpmTask bpmTask)
        {
            ServiceResponse Response = new ServiceResponse
            {
                Organization = bpmTask.databaseName,
                InvokerId    = bpmTask.InvokerId,
                status       = "success",
                Type         = bpmTask.type,
                IsBpm        = bpmTask.IsBpm,
                parameters   = param
            };

            _responseQueue.QueueExection(Response);
        }
Esempio n. 6
0
        public ActionResult RunTask(BpmTask bpmTask)
        {
            var bpmWorker = new BpmWorker
            {
                instanceID   = bpmTask.instanceID,
                workflowName = bpmTask.workflowName,
                taskID       = bpmTask.taskID
            };

            _accountDbContext.BpmWorkers.Add(bpmWorker);
            _accountDbContext.SaveChanges();
            bpmTask.InvokerId = bpmWorker.Id;

            bpmTask.databaseName = ((ClaimsIdentity)HttpContext.User.Identity).FindFirst("organization").Value;
            bpmTask.IsBpm        = true;
            _exectionQueue.QueueExection(bpmTask);
            return(Ok());
        }
        protected async override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Task Execution Engine Hosted Service is starting.");


            while (!stoppingToken.IsCancellationRequested)
            {
                BpmTask bpmTask = await _taskExectionQueue.DequeueAsync(stoppingToken);

                if (bpmTask != null)
                {
                    tasks.Add(Execute(bpmTask));
                }
                //Thread.Sleep(1000);
            }

            await Task.WhenAll(tasks);

            _logger.LogInformation("Task Execution Engine Hosted Service is stopping.");
        }
Esempio n. 8
0
        public async Task <ActionResult <string> > AddOrderPayment([FromBody] Order order)
        {
            string       OrganizationName = (string)RouteData.Values["OrganizationName"];
            Organization orgExist         = await _organizationRepository.OraganizationExist(OrganizationName);

            if (orgExist != null)
            {
                _orderRepository.setConnectionString(OrganizationName);

                byte[] error  = new byte[500];
                int    status = await _orderRepository.AddOrderPayment(order, error);

                string z = Encoding.ASCII.GetString(error);
                if (status != 0)
                {
                    return(BadRequest(z.Remove(z.IndexOf('\0'))));
                }
                else
                {
                    BpmTask task = new BpmTask()
                    {
                        IsBpm        = false,
                        type         = "external",
                        TaskName     = "InvokeOrder",
                        databaseName = OrganizationName,
                        TaskParam    = new object[] { order }
                    };
                    _executionEngine.QueueExection(task);
                    return(Ok("successfuly added"));
                }
            }
            else
            {
                return(NotFound("This organization does not exist"));
            }
        }
Esempio n. 9
0
        public async Task findServiceAsync(BpmTask bpmTask, IServiceScope serviceScope)
        {
            var services = _actionDescriptorCollectionProvider
                           .ActionDescriptors
                           .Items
                           .OfType <ControllerActionDescriptor>()
                           .Where(a => a.ActionName == bpmTask.TaskName);

            if (services.Count() > 0)
            {
                foreach (var item in services)
                {
                    try
                    {
                        var                  id           = new ClaimsIdentity();
                        string               httpMethode  = item.ActionConstraints.OfType <HttpMethodActionConstraint>().SingleOrDefault().HttpMethods.FirstOrDefault();
                        MethodInfo           methodInfo   = item.ControllerTypeInfo.GetMethod(bpmTask.TaskName);
                        List <ParameterInfo> parameters   = methodInfo.GetParameters().ToList();
                        List <object>        methodeParam = new List <object>();
                        if (parameters.Count == bpmTask.TaskParam.Length)
                        {
                            for (int i = 0; i < parameters.Count; ++i)
                            {
                                var     taskParameterobj = bpmTask.TaskParam[i];
                                string  json             = JsonConvert.SerializeObject(taskParameterobj);
                                JObject jsonOb           = JObject.Parse(json);
                                var     jsonObProperties = jsonOb.Properties();
                                Type    methodParamtype  = parameters[i].ParameterType;
                                bool    isClass          = checkedClassType(methodParamtype);

                                try
                                {
                                    if (isClass)
                                    {
                                        methodeParam.Add(JsonConvert.DeserializeObject(json, methodParamtype));
                                    }
                                    else if (jsonObProperties.Count() == 1)
                                    {
                                        methodeParam.Add(Convert.ChangeType(jsonObProperties.FirstOrDefault().Value, parameters[i].ParameterType));
                                    }
                                }
                                catch (Exception)
                                {
                                    createFailedResponse("Cannont convert paramenter" + json + "to the task paramerter " + i, bpmTask);
                                    return;
                                }
                            }
                            var controller  = (ControllerBase)serviceScope.ServiceProvider.GetService(item.ControllerTypeInfo);
                            var httpContext = new DefaultHttpContext();
                            httpContext.Request.Headers["organization"] = bpmTask.databaseName;

                            var controllerContext = new ControllerContext()
                            {
                                HttpContext = httpContext,
                            };
                            controller.ControllerContext = controllerContext;
                            var contProperties = controller.GetType().GetProperties().ToList();
                            foreach (var property in contProperties)
                            {
                                try
                                {
                                    var proType = property.GetValue(controller).GetType();
                                    if (proType != null)
                                    {
                                        Console.WriteLine(property.Name);
                                        MethodInfo _methodInfo = proType.GetMethod("setConnectionString");
                                        if (_methodInfo != null)
                                        {
                                            var result = _methodInfo.Invoke(property.GetValue(controller), new object[] { bpmTask.databaseName });
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    continue;
                                }
                            }
                            if (bpmTask.type == "userTask")
                            {
                                var IsBpmEngine = methodeParam[0].GetType().GetProperty("IsBpmEngine");
                                IsBpmEngine.SetValue(methodeParam[0], bpmTask.IsBpm);
                                var InvokerId = methodeParam[0].GetType().GetProperty("InvokerId");
                                InvokerId.SetValue(methodeParam[0], bpmTask.InvokerId);
                            }
                            _logger.LogInformation("Invoking " + bpmTask.TaskName);
                            var resutlt = await(dynamic) methodInfo.Invoke(controller, methodeParam.ToArray());

                            var prop = resutlt.GetType().GetProperty("Result");
                            if (prop != null)
                            {
                                var action = prop.GetValue(resutlt);
                                createResponse((ActionResult)action, bpmTask);
                            }
                            else
                            {
                                createResponse((ActionResult)(resutlt), bpmTask);
                            }
                        }
                        else
                        {
                            createFailedResponse("Parameter Don't match service Parameter", bpmTask);
                        }
                    }
                    catch (Exception ex)
                    {
                        createFailedResponse("Problem has occurred while Trying to execute this Task", bpmTask);
                        throw;
                    }
                }
            }
            else
            {
                createFailedResponse("This Task Does not exist", bpmTask);
            }
        }