Beispiel #1
0
        public async Task <WorkflowStartResponse> SendToWorkflow(WorkflowStart startModel)
        {
            Validate(startModel);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();

            return(await engineClient.SendToWorkflow(startModel));
        }
        public async Task <Result <VoidResult> > SaveAndSendToWorkflow(TModel model)
        {
            try
            {
                BeforeSave(model);
                Save(model);
                AfterSave(model);

                if (string.IsNullOrEmpty(FormName))
                {
                    throw new Exception("نام فارسی این گردش کار داده نشده است");
                }

                if (string.IsNullOrEmpty(thisControllerProcessDefinitionKey))
                {
                    throw new Exception("thisControllerProcessDefinitionKey این گردش کار داده نشده است");
                }

                if (string.IsNullOrEmpty(GetUsername()))
                {
                    throw new Exception("username این گردش کار داده نشده است");
                }


                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("formName", FormName);


                var ws = new WorkflowStart
                {
                    Id                   = model.Id.ToString(),
                    Username             = GetUsername(),
                    Group                = GetGroup(),
                    ProcessDefinitionKey = thisControllerProcessDefinitionKey,
                    variables            = dic
                };

                _workflowService = InjectorSingleTon.Inject <IWorkflowService>();
                BeforeSendToWorkflow(ws, model);

                var res = await _workflowService.SendToWorkflow(ws);

                AfterSendToWorkflow(ws, model);

                return(new Result <VoidResult>
                {
                    Type = res.Status == EngineResponseStatus.Success ? ResultType.Success : ResultType.Fail,
                    Message = res.Message,
                });
            }
            catch (Exception e)
            {
                ErrorSendToWorkflow(e, model);
                return(new Result <VoidResult> {
                    Message = e.Message, Type = ResultType.Fail
                });
            }
        }
Beispiel #3
0
        public async Task <WorkflowContinueResponse> Continue(WorkflowContinueRequest continueRequest)
        {
            ValidateContinueRequest(continueRequest);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();


            return(await engineClient.Continue(continueRequest));
        }
Beispiel #4
0
        QueryHistoricTasks(QueryHistoricProcessInstanceRequest queryHistoricProcessInstanceRequest)
        {
            ValidateHistoricTasks(queryHistoricProcessInstanceRequest);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();


            return(await engineClient.QueryHistoricTasks(queryHistoricProcessInstanceRequest));
        }
Beispiel #5
0
        public async Task <EngineQueryHistoricProcessInstanceGrid> QueryHistoricProcessInstances(QueryHistoricProcessInstanceRequest request)
        {
            ValidateQueryHistoricProcessInstancesRequest(request);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();


            return(await engineClient.QueryHistoricProcessInstances(request));
        }
Beispiel #6
0
        public async Task <EngineProcessDefinitionGrid> GetProcessDefinitions(ProcessDefinitionsRequest request)
        {
            ValidateGetProcessDefinitions(request);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();


            return(await engineClient.GetProcessDefinitions(request));
        }
Beispiel #7
0
        public async Task <EngineProcessDiagram> GetDiagram(DiagramRequest request)
        {
            ValidateGetDiagram(request);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();


            return(await engineClient.GetDiagram(request));
        }
Beispiel #8
0
        public async Task <EngineInboxTaskList> GetInboxTasks(EngineInboxTaskRequest inboxTaskRequest)
        {
            ValidateInboxTaskRequest(inboxTaskRequest);

            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();


            return(await engineClient.GetInboxTasks(inboxTaskRequest));
        }
        private void IsUserExistsOrNotCreateIt()
        {
            var userService        = InjectorSingleTon.Inject <IActivitiEngineUserManagementService>();
            var loggedUserProvider = InjectorSingleTon.Inject <ILoggedUserProviderService>();

            var loggedUser = loggedUserProvider.GetCurrentLoggedInUserInfos();

            userService.CreateUserIfNotExist(
                new EngineUser
            {
                Id        = loggedUser.Id,
                Password  = loggedUser.Password,
                FirstName = loggedUser.FirstName,
                LastName  = loggedUser.LastName
            });
        }
        Continue([FromUri] string taskId, [FromBody] Dictionary <string, string> vars)
        {
            try
            {
                var username = HttpContext.Current.Session["loggedInUsername"];
                if (username == null || string.IsNullOrEmpty(username.ToString()))
                {
                    throw new Exception("کاربر کنونی وارد نشده است");
                }

                var request = new WorkflowContinueRequest
                {
                    Username      = username.ToString(),
                    variables     = vars,
                    TaskId        = taskId,
                    RequestStatus = WorkflowContinueRequestStatus.Complete,
                };
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();


                BeforeContinue(request, vars);

                var tasks = await workflowService.Continue(request);

                AfterContinue(request, vars);


                return(new Result <InboxTaskViewModel <TModel> > {
                    Type = ResultType.Success
                });
            }
            catch (HttpRequestException e)
            {
                return(new Result <InboxTaskViewModel <TModel> >
                {
                    Message = e.Message + e.InnerException?.Message + " سرور گردش کار فعال نیست خطا در اتصال ",
                    Type = ResultType.Fail
                });
            }
            catch (Exception e)
            {
                OnContinueError(e, vars);
                return(new Result <InboxTaskViewModel <TModel> > {
                    Message = e.Message, Type = ResultType.Fail
                });
            }
        }
Beispiel #11
0
        public async Task <byte[]> GetPhoto(string key)
        {
            try
            {
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                var model = await workflowService.GetPhoto(new DiagramRequest
                {
                    Username             = GenericController <Vacation> .GetUsername(),
                    processDefinitionKey = key
                });


                return(model.Content);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #12
0
        public async Task <Result <FormProperty> > GetModel(string key)
        {
            try
            {
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                var model = await workflowService.GetModel(key, GenericController <Vacation> .GetUsername());


                List <FormProperty> list = new List <FormProperty>();

                for (int i = 0; i < model?.Processes?.Length; i++)
                {
                    for (int j = 0; j < model?.Processes[i]?.FlowElements?.Length; j++)
                    {
                        for (int k = 0; k < model?.Processes[i]?.FlowElements[j]?.FormProperties?.Length; k++)
                        {
                            var prop = model?.Processes[i]?.FlowElements[j]?.FormProperties[k];
                            if (!string.IsNullOrEmpty(prop.Name) && (prop.Name.StartsWith("U_") || prop.Name.StartsWith("G_")))
                            {
                                list.Add(prop);
                            }
                        }
                    }
                }

                return(new Result <FormProperty>
                {
                    Grid = list,
                    Type = ResultType.Success
                });
            }
            catch (Exception e)
            {
                return(new Result <FormProperty>
                {
                    Type = ResultType.Fail,
                    Message = e.Message
                });
            }
        }
        protected virtual async Task <Result <InboxTaskViewModel <TModel> > > DoAction(string taskId,
                                                                                       WorkflowContinueRequestStatus requestStatus, bool notClaim = false)
        {
            try
            {
                var username = HttpContext.Current.Session["loggedInUsername"];
                if (username == null || string.IsNullOrEmpty(username.ToString()))
                {
                    throw new Exception("کاربر کنونی وارد نشده است");
                }

                var request = new WorkflowContinueRequest
                {
                    Username      = username.ToString(),
                    RequestStatus = requestStatus,
                    Assignee      = notClaim ? null : username.ToString(),
                    TaskId        = taskId
                };
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                var tasks = await workflowService.Continue(request);

                return(new Result <InboxTaskViewModel <TModel> > {
                    Type = ResultType.Success
                });
            }
            catch (HttpRequestException e)
            {
                return(new Result <InboxTaskViewModel <TModel> >
                {
                    Message = e.Message + e.InnerException?.Message + " سرور گردش کار فعال نیست خطا در اتصال ",
                    Type = ResultType.Fail
                });
            }
            catch (Exception e)
            {
                return(new Result <InboxTaskViewModel <TModel> > {
                    Message = e.Message, Type = ResultType.Fail
                });
            }
        }
Beispiel #14
0
        public async Task <Result <EngineProcessDefinitionGrid> > GetAll()
        {
            try
            {
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                return(new Result <EngineProcessDefinitionGrid>
                {
                    SingleRecord = await workflowService.GetProcessDefinitions(new ProcessDefinitionsRequest()),
                    Type = ResultType.Success
                });
            }
            catch (Exception e)
            {
                return(new Result <EngineProcessDefinitionGrid>
                {
                    Type = ResultType.Fail,
                    Message = e.Message
                });
            }
        }
        public virtual async Task <Result <byte[]> > GetDiagram(long processInstanceId)
        {
            try
            {
                var username = HttpContext.Current.Session["loggedInUsername"];
                if (username == null || string.IsNullOrEmpty(username.ToString()))
                {
                    throw new Exception("کاربر کنونی وارد نشده است");
                }

                var request = new DiagramRequest()
                {
                    Username          = username.ToString(),
                    processInstanceId = processInstanceId
                };
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                var diagram = await workflowService.GetDiagram(request);

                return(new Result <byte[]> {
                    Type = ResultType.Success, SingleRecord = diagram.Content
                });
            }
            catch (HttpRequestException e)
            {
                return(new Result <byte[]>
                {
                    Message = e.Message + e.InnerException?.Message + " سرور گردش کار فعال نیست خطا در اتصال ",
                    Type = ResultType.Fail
                });
            }
            catch (Exception e)
            {
                return(new Result <byte[]> {
                    Message = e.Message, Type = ResultType.Fail
                });
            }
        }
Beispiel #16
0
        public async Task <Result <EngineProcessDefinition> > GetProcessDefinitionById(string processDefinitionId)
        {
            try
            {
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                var model = await workflowService.GetProcessDefinitionById(processDefinitionId);

                return(new Result <EngineProcessDefinition>
                {
                    SingleRecord = model,
                    Type = ResultType.Success
                });
            }
            catch (Exception e)
            {
                return(new Result <EngineProcessDefinition>
                {
                    Type = ResultType.Fail,
                    Message = e.Message
                });
            }
        }
Beispiel #17
0
        public async Task <BpmnModel> GetModel(string processDefinitionId, string username)
        {
            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();

            return(await engineClient.GetModel(processDefinitionId, username));
        }
Beispiel #18
0
        public async Task <EngineProcessDefinition> GetProcessDefinitionById(string processDefinitionId)
        {
            var engineClient = InjectorSingleTon.Inject <IWorkflowEngineClient>();

            return(await engineClient.GetProcessDefinitionById(processDefinitionId));
        }
        public virtual async Task <Result <InboxTaskViewModel <TModel> > > GetInboxTasks(bool isClaimed)
        {
            try
            {
                var username = HttpContext.Current.Session["loggedInUsername"];
                if (username == null || string.IsNullOrEmpty(username.ToString()))
                {
                    throw new Exception("کاربر کنونی وارد نشده است");
                }

                var request = new EngineInboxTaskRequest
                {
                    assignee        = isClaimed ? username.ToString() : null,
                    candidateUser   = isClaimed ? null : username.ToString(),
                    candidateGroup  = isClaimed ? null : GetGroup(),
                    candidateGroups = isClaimed ? null : GetGroups(),
                };
                var workflowService = InjectorSingleTon.Inject <IWorkflowService>();

                var tasks = await workflowService.GetInboxTasks(request);


                List <InboxTaskViewModel <TModel> > list = new List <InboxTaskViewModel <TModel> >();
                foreach (var task in tasks.Data)
                {
                    var viewModel = new InboxTaskViewModel <TModel>();

                    //status
                    var status = task.Variables
                                 .FirstOrDefault(v => v.Name == "status");
                    int val = 0;
                    if (int.TryParse(status?.Value, out val))
                    {
                        viewModel.StatusMessage += "<br>" + " اشکال در خواندن status " + status;
                    }
                    else
                    {
                        viewModel.Status = status?.Value != null ? (ProcessInstanceStatus)val : 0;
                    }

                    viewModel.Assignee = task.Assignee;

                    // assignee Translate
                    viewModel.AssigneeTranslate = _orgChartService.GetPersonnelNameByUsername(task.Assignee);

                    //form name
                    var formName = task.Variables.Where(v => v.Name == "formName").Select(v => v.Value)
                                   .FirstOrDefault();
                    if (string.IsNullOrEmpty(formName))
                    {
                        viewModel.StatusMessage += "<br>" + " FormName  داده نشده است";
                    }
                    else
                    {
                        viewModel.FormName = formName;
                    }


                    //Id
                    var  idstr = task.Variables.Where(v => v.Name == "id").Select(v => v.Value).FirstOrDefault();
                    long id    = 0;
                    if (string.IsNullOrEmpty(idstr) || long.TryParse(idstr, out id) == false)
                    {
                        throw new Exception(" این گردش کار دارای Id نیست " + viewModel.StatusMessage);
                    }

                    var record = GetById(id).SingleRecord;
                    // subject
                    viewModel.Subject = record.Subject;

                    //record
                    viewModel.Record = record;

                    viewModel.RequestDate = task.CreateTime;


                    viewModel.ProcessInstanceId = task.ProcessInstanceId;
                    viewModel.TaskId            = task.Id;

                    list.Add(viewModel);
                }


                return(new Result <InboxTaskViewModel <TModel> > {
                    Type = ResultType.Success, Grid = list
                });
            }
            catch (HttpRequestException e)
            {
                return(new Result <InboxTaskViewModel <TModel> >
                {
                    Message = e.Message + e.InnerException?.Message + " سرور گردش کار فعال نیست خطا در اتصال ",
                    Type = ResultType.Fail
                });
            }
            catch (Exception e)
            {
                return(new Result <InboxTaskViewModel <TModel> > {
                    Message = e.Message, Type = ResultType.Fail
                });
            }
        }