/// <summary>
        /// this method add variable dependies to whereclause which have relation with current variable.
        /// </summary>
        /// <param name="queryParams">it would update this parameter.</param>
        private void AddDependencyClause(sysBpmsVariable variable, List <SqlParameter> queryParams, List <SqlParameter> insertColumnParams, ref string whereClause, List <QueryModel> additionalParams, Dictionary <string, DataModel> allSavedEntities = null)
        {
            //add variable dependies where clause which have relation with current variable
            if (variable.DependentVariableDependencies.Any())
            {
                foreach (sysBpmsVariableDependency item in variable.DependentVariableDependencies)
                {
                    object value      = null;
                    var    toVariable = new VariableService(base.UnitOfWork).GetInfo(item.ToVariableID.Value);
                    //set BindTrace to find a field of a entity variable if the variable is entity.
                    string BindTrace = $"{toVariable.Name}{(!string.IsNullOrWhiteSpace(item.ToPropertyName) ? ("." + item.ToPropertyName) : "")}";
                    whereClause += $"{(string.IsNullOrWhiteSpace(whereClause) ? "" : " and ")}{item.DependentPropertyName}=@{BindTrace.Replace(".", "_")}";

                    if (allSavedEntities?.ContainsKey(toVariable.Name) == true && allSavedEntities[toVariable.Name][BindTrace.Split('.').LastOrDefault()] != null)
                    {
                        value = allSavedEntities[toVariable.Name][BindTrace.Split('.').LastOrDefault()];
                    }
                    else
                    {
                        value = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork).GetValueByBinding(BindTrace, base.GetAllQueryModels(additionalParams));
                    }

                    queryParams.Add(new SqlParameter($"@{BindTrace.Replace(".", "_")}", value ?? DBNull.Value));

                    if (insertColumnParams != null)
                    {
                        if (!insertColumnParams.Any(c => c.ParameterName.TrimStart('@') == item.DependentPropertyName))
                        {
                            insertColumnParams.Add(new SqlParameter("@" + item.DependentPropertyName, value ?? DBNull.Value));
                        }
                    }
                }
            }
            whereClause = string.IsNullOrWhiteSpace(whereClause) ? "" : (whereClause.Trim().StartsWith("where") ? whereClause : (" where " + whereClause));
        }
 private void AddVariableParameters(ref string sqlQuery, List <SqlParameter> queryParams)
 {
     if (!string.IsNullOrWhiteSpace(sqlQuery))
     {
         IDataManageEngine dataManageEngine = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork);
         List <string>     extractedParams  = DomainUtility.GetParameters(sqlQuery);
         foreach (string parameter in extractedParams)
         {
             if (!queryParams.Any(c => c.ParameterName == parameter.Replace(".", "_")) && Regex.Matches(sqlQuery, "declare(\\s*?)" + parameter).Count == 0)
             {
                 var result = dataManageEngine.GetValueByBinding(parameter.TrimStart('@'));
                 if (result != null)
                 {
                     queryParams.Add(new SqlParameter(parameter.Replace(".", "_"), result));
                     sqlQuery = sqlQuery.Replace(parameter, parameter.Replace(".", "_"));
                 }
             }
         }
     }
 }
Example #3
0
        public ResultOperation SendMessage(sysBpmsEvent senderEvent)
        {
            ResultOperation    resultOperation    = new ResultOperation();
            EventService       eventService       = new EventService(base.UnitOfWork);
            ThreadEventService threadEventService = new ThreadEventService(base.UnitOfWork);
            DataManageEngine   dataManageEngine   = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork);

            string senderKey = string.Empty;

            switch ((SubTypeMessageEventModel.e_KeyType)senderEvent.SubTypeMessageEventModel.KeyType)
            {
            case SubTypeMessageEventModel.e_KeyType.Static:
                senderKey = senderEvent.SubTypeMessageEventModel.Key;
                break;

            case SubTypeMessageEventModel.e_KeyType.Variable:
                senderKey = dataManageEngine.GetValueByBinding(senderEvent.SubTypeMessageEventModel.Key).ToStringObj();
                break;
            }
            sysBpmsMessageType messageType = new MessageTypeService(base.UnitOfWork).GetInfo(senderEvent.MessageTypeID.Value);

            Dictionary <string, object> listParameter = senderEvent.SubTypeMessageEventModel.MessageParams.ToDictionary(c => c.Name, c =>
            {
                return(dataManageEngine.GetValueByBinding(c.Variable));
            });
            //start events
            List <sysBpmsEvent> sysStartEvents = eventService.GetListStartMessage(senderEvent.ProcessID, senderKey, senderEvent.MessageTypeID.Value);

            foreach (sysBpmsEvent item in sysStartEvents)
            {
                Dictionary <string, object> listDefaultVariables = item.SubTypeMessageEventModel.MessageParams.ToDictionary(c => c.Variable, c =>
                {
                    return(listParameter.FirstOrDefault(d => d.Key == c.Name).Value);
                });
                new ProcessEngine(new EngineSharedModel(currentThread: null, item.ProcessID, base.EngineSharedModel.BaseQueryModel, base.EngineSharedModel.CurrentUserName, base.EngineSharedModel.ApiSessionID), base.UnitOfWork).StartProcessBySystem(listDefaultVariables);
                return(resultOperation);
            }

            //intermediate and boundary events
            List <sysBpmsThreadEvent> sysBpmsThreadEvents = threadEventService.GetMessageActive(senderEvent.ProcessID, senderEvent.MessageTypeID.Value, new string[] { nameof(sysBpmsThreadEvent.Event), nameof(sysBpmsThreadEvent.Thread) });

            foreach (sysBpmsThreadEvent item in sysBpmsThreadEvents)
            {
                DataManageEngine receiverDataManage = new DataManageEngine(new EngineSharedModel(item.Thread, item.Event.ProcessID, base.EngineSharedModel.BaseQueryModel, base.EngineSharedModel.CurrentUserName, base.EngineSharedModel.ApiSessionID), base.UnitOfWork);
                string           receiverKey        = string.Empty;;
                switch ((SubTypeMessageEventModel.e_KeyType)item.Event.SubTypeMessageEventModel.KeyType)
                {
                case SubTypeMessageEventModel.e_KeyType.Static:
                    receiverKey = item.Event.SubTypeMessageEventModel.Key;
                    break;

                case SubTypeMessageEventModel.e_KeyType.Variable:
                    receiverKey = receiverDataManage.GetValueByBinding(item.Event.SubTypeMessageEventModel.Key).ToStringObj();
                    break;
                }
                if (senderKey == receiverKey)
                {
                    Dictionary <string, object> listDefaultVariables = item.Event.SubTypeMessageEventModel?.MessageParams?.Where(c => !string.IsNullOrWhiteSpace(c.Variable)).ToDictionary(c => c.Variable, c =>
                    {
                        return(listParameter.FirstOrDefault(d => d.Key == c.Name).Value);
                    });
                    new ProcessEngine(new EngineSharedModel(item.Thread, item.Event.ProcessID, base.EngineSharedModel.BaseQueryModel, base.EngineSharedModel.CurrentUserName, base.EngineSharedModel.ApiSessionID), base.UnitOfWork).ContinueProcess(item, true, listDefaultVariables);
                    //Even if there is a error , this method must continue and log that error.
                    return(resultOperation);
                }
            }

            return(resultOperation);
        }
Example #4
0
        private void SetThreadEventOnInterval(sysBpmsEvent _event, sysBpmsThreadEvent newThreadEvent, sysBpmsThreadEvent lastExecutedThreadEvent)
        {
            IDataManageEngine  dataManageEngine   = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork);
            string             variableData       = _event.SubTypeTimerEventModel.VariableData;
            ThreadEventService threadEventService = new ThreadEventService(base.UnitOfWork);
            int executedCount = 0;

            if (_event.TypeLU == (int)sysBpmsEvent.e_TypeLU.StartEvent)
            {
                executedCount = threadEventService.GetCount(null, _event.ID, base.EngineSharedModel.CurrentProcessID, (int)sysBpmsThreadEvent.e_StatusLU.Done);
            }
            else
            {
                executedCount = threadEventService.GetCount(base.EngineSharedModel.CurrentThreadID, _event.ID, null, (int)sysBpmsThreadEvent.e_StatusLU.Done);
            }
            PersianCalendar pc = new PersianCalendar();

            if (_event.SubTypeTimerEventModel.RepeatTimes.ToIntObj() == 0 || _event.SubTypeTimerEventModel.RepeatTimes > executedCount)
            {
                switch ((SubTypeTimerEventModel.e_IntervalType)_event.SubTypeTimerEventModel.IntervalType)
                {
                case SubTypeTimerEventModel.e_IntervalType.SpecificMinute:
                    switch ((SubTypeTimerEventModel.e_SetType)_event.SubTypeTimerEventModel.SetType)
                    {
                    case SubTypeTimerEventModel.e_SetType.Static:
                        newThreadEvent.ExecuteDate = DateTime.Now.AddMinutes(_event.SubTypeTimerEventModel.Minute.ToIntObj());
                        break;

                    case SubTypeTimerEventModel.e_SetType.Variable:
                        newThreadEvent.ExecuteDate = DateTime.Now.AddMinutes(dataManageEngine.GetValueByBinding(variableData).ToIntObj());
                        break;
                    }
                    break;

                case SubTypeTimerEventModel.e_IntervalType.EveryMonth:
                    int lastDayExecuted = DateTime.Now.Day - 1;
                    if (lastExecutedThreadEvent != null && lastExecutedThreadEvent.ExecuteDate.AreInTheSameMonth(DateTime.Now))
                    {
                        lastDayExecuted = lastExecutedThreadEvent.ExecuteDate.Day;
                    }

                    List <int> MonthDays = null;
                    switch ((SubTypeTimerEventModel.e_SetType)_event.SubTypeTimerEventModel.SetType)
                    {
                    case SubTypeTimerEventModel.e_SetType.Static:
                        MonthDays = _event.SubTypeTimerEventModel.GetListMonthDays;
                        break;

                    case SubTypeTimerEventModel.e_SetType.Variable:
                        MonthDays = dataManageEngine.GetValueByBinding(variableData).ToStringObj().Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.ToIntObj()).ToList();
                        break;
                    }
                    int?persianMonthDay = MonthDays.FirstOrDefault(c => c > lastDayExecuted);
                    //if persianMonthDay is null ,monthDate must be filled by next month ,otherwise it is filled by current month.
                    DateTime monthDate = persianMonthDay.HasValue ? DateTime.Now : DateTime.Now.AddMonths(1);
                    if (!persianMonthDay.HasValue)
                    {
                        //if lastDayExecuted is not in the same month with persianMonthDay
                        persianMonthDay = MonthDays.FirstOrDefault();
                    }
                    newThreadEvent.ExecuteDate = pc.ToDateTime(monthDate.Year, monthDate.Month, persianMonthDay.Value, _event.SubTypeTimerEventModel.TimeHour.ToIntObj(), _event.SubTypeTimerEventModel.TimeMinute.ToIntObj(), 0, 0);
                    break;

                case SubTypeTimerEventModel.e_IntervalType.EveryWeek:
                    lastDayExecuted = DateTime.Now.GetDayOfWeekBy7() - 1;
                    if (lastExecutedThreadEvent != null && lastExecutedThreadEvent.ExecuteDate.AreInTheSameWeek(DateTime.Now))
                    {
                        lastDayExecuted = lastExecutedThreadEvent.ExecuteDate.GetDayOfWeekBy7();
                    }

                    List <int> weekDays = null;
                    switch ((SubTypeTimerEventModel.e_SetType)_event.SubTypeTimerEventModel.SetType)
                    {
                    case SubTypeTimerEventModel.e_SetType.Static:
                        weekDays = _event.SubTypeTimerEventModel.GetListWeekDays;
                        break;

                    case SubTypeTimerEventModel.e_SetType.Variable:
                        weekDays = dataManageEngine.GetValueByBinding(variableData).ToStringObj().Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.ToIntObj()).ToList();
                        break;
                    }
                    //if weekDays has a day bigger than last day executed
                    int?weekDay7 = weekDays.FirstOrDefault(c => c > lastDayExecuted);

                    //if need to go next week because ther is no greater day of week in weekDays and start from the first day of week selected by user after monday.
                    if (!weekDay7.HasValue)
                    {
                        weekDay7 = weekDays.FirstOrDefault();
                        //lastDayExecuted is not in the same week with persianWeekDay
                        newThreadEvent.ExecuteDate = DateTime.Now.AddDays(weekDay7.Value + (7 - DateTime.Now.GetDayOfWeekBy7()));
                    }
                    else
                    {
                        //lastDayExecuted is in the same week with persianWeekDay
                        newThreadEvent.ExecuteDate = DateTime.Now.AddDays(weekDay7.Value - lastDayExecuted);
                    }
                    break;
                }
            }
        }
Example #5
0
        public ResultOperation SendEmail(sysBpmsEvent _event)
        {
            ResultOperation        resultOperation  = new ResultOperation();
            SubTypeEmailEventModel email            = _event.SubTypeMessageEventModel.Email;
            sysBpmsEmailAccount    fromEmailAccount = new sysBpmsEmailAccount();
            DataManageEngine       dataManageEngine = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork);

            List <string> toEmailList = new List <string>();

            switch (email.From.ToIntObj())
            {
            case (int)SubTypeEmailEventModel.e_FromType.CurrentUser:
                sysBpmsUser user = new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);
                if (user != null)
                {
                    fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault();
                }
                break;

            case (int)SubTypeEmailEventModel.e_FromType.CurrentThreadUser:
                user = base.EngineSharedModel.CurrentThread != null && base.EngineSharedModel.CurrentThread.UserID.HasValue ? new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentThread.UserID.Value) : null;
                if (user != null)
                {
                    fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault();
                }
                break;

            default:
                fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetInfo(email.From.ToGuidObj());
                break;
            }

            switch ((SubTypeEmailEventModel.e_ToType)email.ToType)
            {
            case SubTypeEmailEventModel.e_ToType.Static:
                toEmailList = email.To.Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
                break;

            case SubTypeEmailEventModel.e_ToType.Systemic:
                switch ((SubTypeEmailEventModel.e_ToSystemicType)email.To.ToIntObj())
                {
                case SubTypeEmailEventModel.e_ToSystemicType.CurrentUser:
                    sysBpmsUser user = new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);
                    if (user != null)
                    {
                        toEmailList.Add(user.Email);
                    }
                    break;

                case SubTypeEmailEventModel.e_ToSystemicType.CurrentThreadUser:
                    user = base.EngineSharedModel.CurrentThread != null && base.EngineSharedModel.CurrentThread.UserID.HasValue ? new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentThread.UserID.Value) : null;
                    if (user != null)
                    {
                        toEmailList.Add(user.Email);
                    }
                    break;
                }
                break;

            case SubTypeEmailEventModel.e_ToType.Variable:
                toEmailList = dataManageEngine.GetValueByBinding(email.To).ToStringObj().Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
                break;
            }

            string subject = email.Subject;
            string content = email.Content;

            if (!string.IsNullOrWhiteSpace(subject))
            {
                foreach (string item in DomainUtility.GetRegularValue("[", "]", subject).Distinct())
                {
                    subject = subject.Replace("[" + item + "]", dataManageEngine.GetValueByBinding(item.Trim()).ToStringObj());
                }
            }

            if (!string.IsNullOrWhiteSpace(content))
            {
                foreach (string item in DomainUtility.GetRegularValue("[", "]", content).Distinct())
                {
                    content = content.Replace("[" + item + "]", dataManageEngine.GetValueByBinding(item.Trim()).ToStringObj());
                }
            }

            new EmailService().SendEmailAsync(fromEmailAccount.Email, fromEmailAccount.MailPassword, fromEmailAccount.SMTP, fromEmailAccount.Port.ToIntObj(), toEmailList, "", "", subject, content);
            return(resultOperation);
        }
        public void SetAccessInfoTo(sysBpmsThreadTask threadTask, Domain.sysBpmsTask task, EngineSharedModel engineSharedModel)
        {
            if (task.OwnerTypeLU.HasValue)
            {
                switch ((sysBpmsTask.e_OwnerTypeLU)task.OwnerTypeLU)
                {
                case sysBpmsTask.e_OwnerTypeLU.User:
                    switch ((UserTaskRuleModel.e_UserAccessType)task.UserTaskRuleModel.AccessType)
                    {
                    case UserTaskRuleModel.e_UserAccessType.Static:
                        threadTask.UpdateAccessInfo(task.UserID.ToGuidObj(), null);
                        break;

                    case UserTaskRuleModel.e_UserAccessType.Variable:
                        Guid?variableUserID = new DataManageEngine(engineSharedModel, base.UnitOfWork).GetValueByBinding(task.UserTaskRuleModel.Variable).ToGuidObjNull();
                        if (!variableUserID.HasValue)
                        {
                            throw new Exception(LangUtility.Get("UserNotFound.Text", nameof(sysBpmsThreadTask)));
                        }

                        threadTask.UpdateAccessInfo(variableUserID, null);
                        break;
                    }
                    break;

                case sysBpmsTask.e_OwnerTypeLU.Role:
                    switch ((UserTaskRuleModel.e_RoleAccessType)task.UserTaskRuleModel.AccessType)
                    {
                    case UserTaskRuleModel.e_RoleAccessType.Static:
                        //if this userTask must be seen by requester user, this add thread userId to new threadTask
                        if (task.IsInRole(null, (int)sysBpmsDepartmentMember.e_RoleLU.Requester))
                        {
                            threadTask.UpdateAccessInfo(engineSharedModel.CurrentThread?.UserID, null);
                        }
                        else
                        {
                            threadTask.UpdateAccessInfo(null, task.GetDepartmentRoles);
                        }
                        break;

                    case UserTaskRuleModel.e_RoleAccessType.Variable:
                        string roleName = new DataManageEngine(engineSharedModel, base.UnitOfWork).GetValueByBinding(task.UserTaskRuleModel.Variable).ToStringObj();
                        if (string.IsNullOrWhiteSpace(roleName))
                        {
                            throw new Exception(LangUtility.Get("RoleNotFound.Text", nameof(sysBpmsThreadTask)));
                        }

                        task.SetRoleDepartment(roleName, task.UserTaskRuleModel.SpecificDepartmentId);
                        //if this userTask must be seen by requester user, this add thread userId to new threadTask
                        if (task.IsInRole(null, (int)sysBpmsDepartmentMember.e_RoleLU.Requester))
                        {
                            threadTask.UpdateAccessInfo(engineSharedModel.CurrentThread?.UserID, null);
                        }
                        else
                        {
                            threadTask.UpdateAccessInfo(null, task.GetDepartmentRoles);
                        }
                        break;

                    case UserTaskRuleModel.e_RoleAccessType.CorrespondentRole:
                        Guid?userId       = task.UserTaskRuleModel.UserType == (int)UserTaskRuleModel.e_UserType.CurrentUserID ? new UserService(base.UnitOfWork).GetInfo(engineSharedModel.CurrentUserName ?? "")?.ID : engineSharedModel.CurrentThread?.UserID;
                        Guid?departmentId = new AccessCodeHelper(base.UnitOfWork).GetDepartmentHierarchyByUserId(userId.ToGuidObj(), task.UserTaskRuleModel.RoleCode.ToIntObj(), task.UserTaskRuleModel.GoUpDepartment);
                        if (!departmentId.HasValue)
                        {
                            throw new Exception(LangUtility.Get("OrganizationNotFound.Text", nameof(sysBpmsThreadTask)));
                        }

                        threadTask.UpdateAccessInfo(null, new List <Tuple <Guid?, string> >()
                        {
                            new Tuple <Guid?, string>(departmentId, task.UserTaskRuleModel.RoleCode)
                        });
                        break;
                    }
                    break;
                }
            }
            else
            {
                throw new Exception(LangUtility.Get("NextNoAccessSetting.Text", nameof(sysBpmsThreadTask)));
            }
        }
        public List <sysBpmsThreadTask> GetMultiInstanceTask(Domain.sysBpmsTask task, EngineSharedModel engineSharedModel)
        {
            sysBpmsThreadTask        threadTask = null;
            List <sysBpmsThreadTask> list       = new List <sysBpmsThreadTask>();

            switch ((sysBpmsTask.e_OwnerTypeLU)task.OwnerTypeLU)
            {
            case sysBpmsTask.e_OwnerTypeLU.User:
                switch ((UserTaskRuleModel.e_UserAccessType)task.UserTaskRuleModel.AccessType)
                {
                case UserTaskRuleModel.e_UserAccessType.Static:
                case UserTaskRuleModel.e_UserAccessType.Variable:
                    string userId = task.UserID;
                    if (task.UserTaskRuleModel.AccessType == (int)UserTaskRuleModel.e_UserAccessType.Variable)
                    {
                        userId = new DataManageEngine(engineSharedModel, base.UnitOfWork).GetValueByBinding(task.UserTaskRuleModel.Variable).ToStringObj();
                    }
                    int i = 0;
                    foreach (string item in userId.Split(','))
                    {
                        threadTask = new sysBpmsThreadTask();
                        threadTask.Update(engineSharedModel.CurrentThreadID.Value, task.ID, DateTime.Now.AddSeconds(i++), null, string.Empty, 0, (int)sysBpmsThreadTask.e_StatusLU.New);
                        threadTask.UpdateAccessInfo(item.ToGuidObj(), null);
                        list.Add(threadTask);
                    }
                    break;
                }
                break;

            case sysBpmsTask.e_OwnerTypeLU.Role:
                switch ((UserTaskRuleModel.e_RoleAccessType)task.UserTaskRuleModel.AccessType)
                {
                case UserTaskRuleModel.e_RoleAccessType.Static:
                case UserTaskRuleModel.e_RoleAccessType.Variable:
                    if (task.UserTaskRuleModel.AccessType == (int)UserTaskRuleModel.e_RoleAccessType.Variable)
                    {
                        task.SetRoleDepartment(new DataManageEngine(engineSharedModel, base.UnitOfWork).GetValueByBinding(task.UserTaskRuleModel.Variable).ToStringObj(), task.UserTaskRuleModel.SpecificDepartmentId);
                    }
                    foreach (var item in task.GetDepartmentRoles)
                    {
                        List <Guid> users = new DepartmentMemberService(base.UnitOfWork).GetList(item.Item1, item.Item2.ToIntObj(), null).Select(c => c.UserID).ToList();
                        //It is used  for sequential task.
                        int i = 0;
                        foreach (Guid uId in users)
                        {
                            threadTask = new sysBpmsThreadTask();
                            threadTask.Update(engineSharedModel.CurrentThreadID.Value, task.ID, DateTime.Now.AddSeconds(i++), null, string.Empty, 0, (int)sysBpmsThreadTask.e_StatusLU.New);
                            threadTask.UpdateAccessInfo(uId, null);
                            list.Add(threadTask);
                        }
                    }
                    break;

                case UserTaskRuleModel.e_RoleAccessType.CorrespondentRole:

                    Guid?userId       = task.UserTaskRuleModel.UserType == (int)UserTaskRuleModel.e_UserType.CurrentUserID ? new UserService(base.UnitOfWork).GetInfo(engineSharedModel.CurrentUserName ?? "")?.ID : engineSharedModel.CurrentThread?.UserID;
                    Guid?departmentId = new AccessCodeHelper(base.UnitOfWork).GetDepartmentHierarchyByUserId(userId.ToGuidObj(), task.UserTaskRuleModel.RoleCode.ToIntObj(), task.UserTaskRuleModel.GoUpDepartment);
                    if (!departmentId.HasValue)
                    {
                        throw new Exception(LangUtility.Get("OrganizationNotFound.Text", nameof(sysBpmsThreadTask)));
                    }
                    {
                        List <Guid> users = new DepartmentMemberService(base.UnitOfWork).GetList(departmentId, task.UserTaskRuleModel.RoleCode.ToIntObj(), null).Select(c => c.UserID).ToList();
                        //It is used  for sequential task.
                        int i = 0;
                        foreach (Guid uId in users)
                        {
                            threadTask = new sysBpmsThreadTask();
                            threadTask.Update(engineSharedModel.CurrentThreadID.Value, task.ID, DateTime.Now.AddSeconds(i++), null, string.Empty, 0, (int)sysBpmsThreadTask.e_StatusLU.New);
                            threadTask.UpdateAccessInfo(uId, null);
                            list.Add(threadTask);
                        }
                    }
                    break;
                }

                break;
            }
            return(list);
        }
Example #8
0
        private EngineResponseModel SaveContentHtmlByPage(Guid applicationPageId, string buttonControlId)
        {
            ResultOperation     resultOperation  = new ResultOperation();
            RedirectUrlModel    redirectUrlModel = null;
            CodeBaseSharedModel codeBaseShared   = new CodeBaseSharedModel();

            try
            {
                FormModel          formModel   = new FormModel();
                sysBpmsDynamicForm dynamicForm = new DynamicFormService(base.UnitOfWork).GetInfoByPageID(applicationPageId);

                //conver form xml code to json object
                JObject obj = JObject.Parse(dynamicForm.DesignJson);
                //if json object has a control with type = CONTENT
                if (obj != null && obj["type"].ToString() == "CONTENT")
                {
                    formModel       = new FormModel(obj, HtmlElementHelper.MakeModel(base.EngineSharedModel, base.UnitOfWork, HtmlElementHelperModel.e_FormAction.OnPost, dynamicForm), null, null, dynamicForm, false);
                    resultOperation = formModel.ResultOperation;
                }
                this.BeginTransaction();
                if (resultOperation.IsSuccess)
                {
                    CodeResultModel codeResultModel;
                    //It sets variables by form's widgets and adds to the codeBaseShared's ListSetVariable.
                    resultOperation = DataManageEngine.SetVariableByForms(formModel.ContentHtml, codeBaseShared, base.EngineSharedModel.BaseQueryModel);
                    if (resultOperation.IsSuccess)
                    {
                        //execute form button backend code.
                        if (!string.IsNullOrWhiteSpace(buttonControlId))
                        {
                            ButtonHtml        buttonHtml        = (ButtonHtml)formModel.ContentHtml.FindControlByID(buttonControlId);
                            DynamicCodeEngine dynamicCodeEngine = new DynamicCodeEngine(base.EngineSharedModel, base.UnitOfWork);
                            codeResultModel  = dynamicCodeEngine.SaveButtonCode(buttonHtml, resultOperation, formModel, codeBaseShared);
                            redirectUrlModel = codeResultModel?.RedirectUrlModel ?? redirectUrlModel;
                            if (buttonHtml.subtype != ButtonHtml.e_subtype.submit)
                            {
                                //If in code any variable is set, it Will save them all at the end
                                dynamicCodeEngine.SaveExternalVariable(codeResultModel);

                                base.FinalizeService(resultOperation);
                                return(new EngineResponseModel().InitPost(resultOperation, codeBaseShared.MessageList, redirectUrlModel, isSubmit: false, listDownloadModel: codeBaseShared.ListDownloadModel));
                            }
                        }
                        //execute form OnExitFormCode
                        if (!string.IsNullOrWhiteSpace(dynamicForm.OnExitFormCode))
                        {
                            codeResultModel = new DynamicCodeEngine(base.EngineSharedModel, base.UnitOfWork).ExecuteOnExitFormCode(DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnExitFormCode), formModel, codeBaseShared);
                            DynamicCodeEngine.SetToErrorMessage(codeResultModel, resultOperation);
                            redirectUrlModel = codeResultModel?.RedirectUrlModel ?? redirectUrlModel;
                        }
                        if (resultOperation.IsSuccess)
                        {
                            //save html element values into database.
                            resultOperation = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork).SaveIntoDataBase(formModel.ContentHtml, null, codeBaseShared.ListSetVariable, null);
                        }
                    }
                }
                base.FinalizeService(resultOperation);

                resultOperation.CurrentObject = formModel;
            }
            catch (Exception ex)
            {
                return(new EngineResponseModel().InitPost(base.ExceptionHandler(ex), codeBaseShared.MessageList, null));
            }

            return(new EngineResponseModel().InitPost(resultOperation, codeBaseShared.MessageList, redirectUrlModel, listDownloadModel: codeBaseShared.ListDownloadModel));
        }