Ejemplo n.º 1
0
        private EngineResponseModel GetContentHtmlByPage(Guid applicationPageId)
        {
            CodeBaseSharedModel codeBaseShared  = new CodeBaseSharedModel();
            FormModel           formModel       = new FormModel();
            sysBpmsDynamicForm  dynamicForm     = new DynamicFormService(base.UnitOfWork).GetInfoByPageID(applicationPageId);
            ResultOperation     resultOperation = new ResultOperation();
            //convert form xml code to json object
            JObject obj = JObject.Parse(dynamicForm.DesignJson);
            HtmlElementHelperModel htmlElementHelperModel = HtmlElementHelper.MakeModel(base.EngineSharedModel, base.UnitOfWork, HtmlElementHelperModel.e_FormAction.Onload, dynamicForm);

            //if json object has a control with type = CONTENT
            if (obj != null && obj["type"].ToString() == "CONTENT")
            {
                formModel       = new FormModel(obj, htmlElementHelperModel, null, null, dynamicForm, false);
                resultOperation = formModel.ResultOperation;
            }
            CodeResultModel codeResultModel = null;

            if (resultOperation.IsSuccess)
            {
                if (!string.IsNullOrWhiteSpace(dynamicForm.OnEntryFormCode))
                {
                    DynamicCodeEngine dynamicCodeEngine = new DynamicCodeEngine(base.EngineSharedModel, base.UnitOfWork);
                    codeResultModel = dynamicCodeEngine.ExecuteOnEntryFormCode(DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnEntryFormCode), formModel, codeBaseShared);
                    DynamicCodeEngine.SetToErrorMessage(codeResultModel, resultOperation);
                    //If in code any variable is set, it Will save them all at the end
                    dynamicCodeEngine.SaveExternalVariable(codeResultModel);
                }
            }

            return(new EngineResponseModel().InitGet(resultOperation, codeBaseShared.MessageList, codeResultModel?.RedirectUrlModel, formModel));
        }
        //It will GetSourceCode and generate assemblies
        public void GetSourceCode(sysBpmsProcess sysBpmsProcess)
        {
            string makeClass(DesignCodeModel designCode)
            {
                string code = string.Empty;

                if (designCode != null && !string.IsNullOrWhiteSpace(designCode.Code))
                {
                    code = DynamicCodeEngine.MakeClass(designCode.Code, designCode.ID);
                }
                return(code);
            }

            string                  sourceCode           = string.Empty;
            DynamicFormService      dynamicFormService   = new DynamicFormService(base.UnitOfWork);
            List <sysBpmsTask>      sysBpmsTaskList      = new TaskService(base.UnitOfWork).GetList(null, sysBpmsProcess.ID);
            List <sysBpmsCondition> sysBpmsConditionList = new ConditionService(base.UnitOfWork).GetList(null, null, sysBpmsProcess.ID);

            List <sysBpmsDynamicForm> sysBpmsDynamicFormList = dynamicFormService.GetList(sysBpmsProcess.ID, null, null, "", null, null);

            foreach (var item in sysBpmsDynamicFormList)
            {
                if (!string.IsNullOrWhiteSpace(item.SourceCode))
                {
                    sourceCode += item.SourceCode + Environment.NewLine;
                }
            }

            foreach (var item in sysBpmsTaskList)
            {
                //Service and script task
                if (!string.IsNullOrWhiteSpace(item.Code))
                {
                    sourceCode += makeClass(DesignCodeUtility.GetDesignCodeFromXml(item.Code));
                }
                //Rule
                if (!string.IsNullOrWhiteSpace(item.Rule))
                {
                    sourceCode += makeClass(DesignCodeUtility.GetDesignCodeFromXml(item.Rule));
                }
            }

            foreach (var item in sysBpmsConditionList)
            {
                if (!string.IsNullOrWhiteSpace(item.Code))
                {
                    sourceCode += makeClass(DesignCodeUtility.GetDesignCodeFromXml(item.Code));
                }
            }

            sysBpmsProcess.SourceCode = sourceCode;
            DynamicCodeEngine.GenerateProcessAssembly(sysBpmsProcess);
        }
Ejemplo n.º 3
0
        public bool CheckUserAccessByForm(Guid dynamicFormID, ElementBase.e_AccessType e_AccessType)
        {
            sysBpmsDynamicForm dynamicForm = new DynamicFormService(base.UnitOfWork).GetInfo(dynamicFormID);

            if (dynamicForm == null)
            {
                return(false);
            }
            if (!dynamicForm.ApplicationPageID.HasValue)
            {
                return(true);
            }
            if (base.EngineSharedModel == null)
            {
                return(true);
            }
            sysBpmsUser user = string.IsNullOrWhiteSpace(base.EngineSharedModel.CurrentUserName) ? null :
                               new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);

            return(this.UnitOfWork.Repository <IApplicationPageAccessRepository>().GetUserAccess(user?.ID, dynamicForm.ApplicationPageID.Value, e_AccessType));
        }
        public ResultOperation Delete(Guid processId)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                this.BeginTransaction();
                sysBpmsProcess process = this.GetInfo(processId);
                if (this.GetList(null, process.ID).Any())
                {
                    resultOperation.AddError(LangUtility.Get("OldVersionDeleteError.Text", nameof(sysBpmsProcess)));
                }
                int countThread = new ThreadService().GetCount(process.ID);
                if (countThread > 0)
                {
                    resultOperation.AddError(string.Format(LangUtility.Get("DeleteProcessThreadError.Text", nameof(sysBpmsProcess)), countThread));
                }
                if (resultOperation.IsSuccess)
                {
                    //Delete Gateway
                    foreach (sysBpmsGateway gateway in new GatewayService(base.UnitOfWork).GetList(processId))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new GatewayService(base.UnitOfWork).Delete(gateway.ID);
                        }
                    }

                    //Delete Task
                    foreach (sysBpmsTask task in new TaskService(base.UnitOfWork).GetList(null, processId))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new TaskService(base.UnitOfWork).Delete(task.ID);
                        }
                    }

                    //Delete Event
                    foreach (sysBpmsEvent @event in new EventService(base.UnitOfWork).GetList(null, processId, "", null))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new EventService(base.UnitOfWork).Delete(@event.ID);
                        }
                    }

                    //Delete DynamicForm
                    foreach (sysBpmsDynamicForm dynamicForm in new DynamicFormService(base.UnitOfWork).GetList(processId, null, null, "", null, null))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new DynamicFormService(base.UnitOfWork).Delete(dynamicForm.ID);
                        }
                    }

                    //Delete Variable
                    foreach (sysBpmsVariable variable in new VariableService(base.UnitOfWork).GetList(processId, null, null, "", null, null))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            resultOperation = new VariableService(base.UnitOfWork).Delete(variable.ID);
                        }
                    }

                    //Delete Process
                    if (resultOperation.IsSuccess)
                    {
                        this.UnitOfWork.Repository <IProcessRepository>().Delete(processId);
                        this.UnitOfWork.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }
        public ResultOperation NewVersion(sysBpmsProcess current, string userName)
        {
            ResultOperation resultOperation;

            try
            {
                resultOperation = new ResultOperation();
                if (resultOperation.IsSuccess)
                {
                    if (this.GetList((int)sysBpmsProcess.Enum_StatusLU.Draft, current.ParentProcessID ?? current.ID).Any())
                    {
                        resultOperation.AddError(LangUtility.Get("NewVersionError.Text", nameof(sysBpmsProcess)));
                        return(resultOperation);
                    }
                    this.BeginTransaction();

                    //Create new process
                    sysBpmsProcess newProcess = this.GetInfo(current.ID);
                    newProcess.CreateDate      = DateTime.Now;
                    newProcess.UpdateDate      = DateTime.Now;
                    newProcess.StatusLU        = (int)sysBpmsProcess.Enum_StatusLU.Draft;
                    newProcess.ProcessVersion  = newProcess.ProcessVersion + 1;
                    newProcess.ParentProcessID = current.ParentProcessID.HasValue ? current.ParentProcessID.Value : current.ID;
                    newProcess.Number          = this.CalculateSerlialNumber(this.UnitOfWork.Repository <IProcessRepository>().MaxNumber() + 1);
                    newProcess.FormattedNumber = this.CalculateFormatNumber(newProcess.Number.Value, DateTime.Now.Date);

                    this.UnitOfWork.Repository <IProcessRepository>().Add(newProcess);
                    this.UnitOfWork.Save();
                    //Copy Variable
                    Dictionary <Guid, Guid> variableConvertID   = new Dictionary <Guid, Guid>();
                    VariableService         variableService     = new VariableService(base.UnitOfWork);
                    List <sysBpmsVariable>  sysBpmsVariableList = variableService.GetList(current.ID, null, null, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsVariable item in sysBpmsVariableList)
                        {
                            Guid oldGuidID = item.ID;
                            item.ProcessID  = newProcess.ID;
                            resultOperation = variableService.Add(item, null);
                            variableConvertID.Add(oldGuidID, item.ID);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy VariableDependency
                    VariableDependencyService        variableDependencyService     = new VariableDependencyService(base.UnitOfWork);
                    List <sysBpmsVariableDependency> sysBpmsVariableDependencyList = variableDependencyService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsVariableDependency item in sysBpmsVariableDependencyList)
                        {
                            if (item.ToVariableID.HasValue)
                            {
                                item.ToVariableID = variableConvertID[item.ToVariableID.Value];
                            }
                            item.DependentVariableID = variableConvertID[item.DependentVariableID];
                            resultOperation          = variableDependencyService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy Element
                    ElementService        elementService     = new ElementService(base.UnitOfWork);
                    List <sysBpmsElement> sysBpmsElementList = elementService.GetList(current.ID, null, "");
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsElement item in sysBpmsElementList)
                        {
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            resultOperation = elementService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy Lane
                    LaneService        laneService     = new LaneService(base.UnitOfWork);
                    List <sysBpmsLane> sysBpmsLaneList = laneService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsLane item in sysBpmsLaneList)
                        {
                            item.ID        = Guid.NewGuid();
                            item.ProcessID = newProcess.ID;
                            item.Element   = null;
                            laneService.Add(item);
                        }
                    }
                    //Copy event
                    EventService        eventService     = new EventService(base.UnitOfWork);
                    List <sysBpmsEvent> sysBpmsEventList = eventService.GetList(null, current.ID, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsEvent item in sysBpmsEventList)
                        {
                            item.ID         = Guid.NewGuid();
                            item.ProcessID  = newProcess.ID;
                            item.Element    = null;
                            resultOperation = eventService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy SequenceFlow
                    Dictionary <Guid, Guid>    flowConvertID           = new Dictionary <Guid, Guid>();
                    SequenceFlowService        sequenceFlowService     = new SequenceFlowService(base.UnitOfWork);
                    List <sysBpmsSequenceFlow> sysBpmsSequenceFlowList = sequenceFlowService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsSequenceFlow item in sysBpmsSequenceFlowList)
                        {
                            Guid flowNewId = Guid.NewGuid();
                            flowConvertID.Add(item.ID, flowNewId);
                            item.ID         = flowNewId;
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            item.Element    = null;
                            resultOperation = sequenceFlowService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy gateway
                    GatewayService        gatewayService     = new GatewayService(base.UnitOfWork);
                    ConditionService      conditionService   = new ConditionService(base.UnitOfWork);
                    List <sysBpmsGateway> sysBpmsGatewayList = gatewayService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsGateway item in sysBpmsGatewayList)
                        {
                            List <sysBpmsCondition> sysBpmsConditionList = conditionService.GetList(item.ID, null, null);
                            item.ID        = Guid.NewGuid();
                            item.ProcessID = newProcess.ID;
                            item.Element   = null;
                            if (item.DefaultSequenceFlowID.HasValue)
                            {
                                item.DefaultSequenceFlowID = flowConvertID[item.DefaultSequenceFlowID.Value];
                            }
                            resultOperation = gatewayService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                            foreach (sysBpmsCondition condition in sysBpmsConditionList)
                            {
                                condition.GatewayID = item.ID;
                                if (condition.SequenceFlowID.HasValue)
                                {
                                    condition.SequenceFlowID = flowConvertID[condition.SequenceFlowID.Value];
                                }
                                condition.Gateway      = null;
                                condition.SequenceFlow = null;
                                resultOperation        = conditionService.Add(condition);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Copy dynamicForm
                    Dictionary <Guid, Guid>   formConvertID          = new Dictionary <Guid, Guid>();
                    DynamicFormService        dynamicFormService     = new DynamicFormService(base.UnitOfWork);
                    ApplicationPageService    applicationPageService = new ApplicationPageService(base.UnitOfWork);
                    List <sysBpmsDynamicForm> sysBpmsDynamicFormList = dynamicFormService.GetList(current.ID, null, null, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsDynamicForm item in sysBpmsDynamicFormList)
                        {
                            Guid oldID = item.ID;
                            item.ProcessId = newProcess.ID;
                            //First change code id.
                            dynamicFormService.UpdateBackendCodeID(item);
                            //Then update sourceCode value.
                            dynamicFormService.GetSourceCode(item);
                            item.Process    = null;
                            resultOperation = dynamicFormService.Add(item,
                                                                     item.ApplicationPageID.HasValue ? applicationPageService.GetInfo(item.ApplicationPageID.Value) : null, userName);
                            formConvertID.Add(oldID, item.ID);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Update formHtml control formid property
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsDynamicForm item in sysBpmsDynamicFormList)
                        {
                            if (item.DesignJson.Contains("formId"))
                            {
                                formConvertID.ToList().ForEach(c =>
                                {
                                    item.DesignJson = item.DesignJson.Replace(c.Key.ToString(), c.Value.ToString());
                                });
                                resultOperation = dynamicFormService.Update(item, userName);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Copy task
                    TaskService        taskService     = new TaskService(base.UnitOfWork);
                    StepService        stepService     = new StepService(base.UnitOfWork);
                    List <sysBpmsTask> sysBpmsTaskList = taskService.GetList(null, current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsTask item in sysBpmsTaskList)
                        {
                            List <sysBpmsStep> sysBpmsStepList = stepService.GetList(item.ID, null);
                            item.ID         = Guid.NewGuid();
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            item.Element    = null;
                            resultOperation = taskService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                            foreach (sysBpmsStep step in sysBpmsStepList)
                            {
                                step.TaskID = item.ID;
                                if (step.DynamicFormID.HasValue)
                                {
                                    step.DynamicFormID = formConvertID[step.DynamicFormID.Value];
                                }
                                step.DynamicForm = null;
                                step.Task        = null;
                                resultOperation  = stepService.Add(step);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    this.UnitOfWork.Save();
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
Ejemplo n.º 6
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));
        }