Ejemplo n.º 1
0
        public CodeResultModel SaveButtonCode(ButtonHtml buttonHtml, ResultOperation resultOperation,
                                              FormModel formModel, CodeBaseSharedModel codeBaseShared)
        {
            DesignCodeModel designCodeModel = null;

            if (!string.IsNullOrWhiteSpace(buttonHtml.BackendCoding))
            {
                designCodeModel = DesignCodeUtility.GetDesignCodeFromXml(buttonHtml.BackendCoding);
            }

            if (designCodeModel != null && (designCodeModel.CodeObjects?.Any() ?? false))
            {
                var result = this.ExecuteOnExitFormCode(designCodeModel, formModel, codeBaseShared);
                if (!result.Result)
                {
                    resultOperation.SetHasError();
                    if (!(result?.CodeBaseShared.MessageList?.Any() ?? false))
                    {
                        resultOperation.AddError(LangUtility.Get("Failed.Text", "Engine"));
                    }
                }

                return(result);
            }
            return(null);
        }
Ejemplo n.º 2
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);
        }
        public object PostIndex(PostDesignCodePostIndexDTO requestModel)
        {
            Guid?           dynamicFormId = requestModel.DynamicFormId.ToGuidObjNull();
            DesignCodeModel codeModel     = DesignCodeUtility.GetDesignCodeFromXml(requestModel.DesignCode.ToStringObj());
            DesignCodeDTO   model         = new DesignCodeDTO()
            {
                Code          = codeModel?.Code,
                CodeType      = (DesignCodeDTO.e_CodeType)requestModel.CodeType,
                CallBack      = requestModel.CallBack.ToStringObj(),
                Assemblies    = codeModel?.Assemblies,
                ID            = string.IsNullOrWhiteSpace(codeModel.ID) ? Guid.NewGuid().ToString() : codeModel.ID,
                CodeObjects   = codeModel.CodeObjects,
                DynamicFormID = dynamicFormId,
                DesignCode    = codeModel.DesignCode,
                Diagram       = codeModel.Diagram.ToStringObj().Trim(),
            };

            if (model.CodeType == DesignCodeDTO.e_CodeType.ConditionCode)
            {
                Random           random           = new Random();
                DCConditionModel dcConditionModel = (DCConditionModel)model.CodeObjects?.FirstOrDefault() ??
                                                    new DCConditionModel(Guid.NewGuid().ToString(), "Condition", string.Empty, string.Empty, null, new List <DCRowConditionModel>(), true, "func" + random.Next(100, 100));
                using (VariableService variableService = new VariableService())
                    using (DynamicFormService dynamicFormService = new DynamicFormService())
                        return new
                               {
                                   OpenDirectly    = true,
                                   DesignCodeDTO   = model,
                                   ProcessControls = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                                     dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                                   ProcessVariables   = variableService.GetVariableAsComboTree(base.ProcessId, base.ApplicationPageId, null, "{0}"),
                                   ListOperationTypes = EnumObjHelper.GetEnumList <DCRowConditionModel.e_OperationType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(),
                                   Model = dcConditionModel
                               };
            }
            else
            {
                this.InitialData(model, dynamicFormId);
                return(model);
            }
        }
Ejemplo n.º 5
0
        public (List <sysBpmsSequenceFlow> flowsList, bool result) CheckGateway(sysBpmsGateway gateway, sysBpmsSequenceFlow joinFromSequenceFlow, Guid?threadTaskID)
        {
            SequenceFlowService        sequenceFlowService       = new SequenceFlowService(this.UnitOfWork);
            List <sysBpmsSequenceFlow> acceptedForkSequenceFlows = new List <sysBpmsSequenceFlow>();

            ConditionService conditionService = new ConditionService(this.UnitOfWork);

            switch ((sysBpmsGateway.e_TypeLU)gateway.TypeLU)
            {
            case sysBpmsGateway.e_TypeLU.ExclusiveGateWay:
            {
                List <sysBpmsCondition> listCondition = conditionService.GetList(gateway.ID, null, null);
                foreach (sysBpmsCondition condition in listCondition)
                {
                    if (new DynamicCodeEngine(base.EngineSharedModel, this.UnitOfWork).ExecuteBooleanCode(DesignCodeUtility.GetDesignCodeFromXml(condition.Code)))
                    {
                        acceptedForkSequenceFlows.Add(sequenceFlowService.GetInfo(condition.SequenceFlowID.Value));
                        break;
                    }
                }
            }
            break;

            case sysBpmsGateway.e_TypeLU.InclusiveGateWay:
            {
                List <sysBpmsThreadTask> listRunningThreadTask = new ThreadTaskService(base.UnitOfWork).GetListRunning(base.EngineSharedModel.CurrentThreadID.ToGuidObj());
                if (!listRunningThreadTask.Any(c => c.ID != threadTaskID && gateway.TraceToStart.ToStringObj().Split(',').Contains(c.Task.ElementID)))
                {
                    List <sysBpmsCondition> listCondition = conditionService.GetList(gateway.ID, null, null);
                    foreach (sysBpmsCondition condition in listCondition)
                    {
                        if (new DynamicCodeEngine(base.EngineSharedModel, this.UnitOfWork).ExecuteBooleanCode(DesignCodeUtility.GetDesignCodeFromXml(condition.Code)))
                        {
                            acceptedForkSequenceFlows.Add(sequenceFlowService.GetInfo(condition.SequenceFlowID.Value));
                        }
                    }
                }
                else
                {
                    return(new List <sysBpmsSequenceFlow>(), true);
                }
            }
            break;

            case sysBpmsGateway.e_TypeLU.ParallelGateWay:
            {
                List <sysBpmsSequenceFlow> listJoinSequenceFlow = sequenceFlowService.GetList(base.EngineSharedModel.CurrentProcessID.Value, gateway.ElementID, "", "");
                //if all sequence flow were executed, run condition code and clear gateway Status Xml List
                if (listJoinSequenceFlow.Where(c => c.ID != joinFromSequenceFlow.ID).All(c => base.EngineSharedModel.CurrentThread.GatewayStatus.Any(d => d.GatewayID == gateway.ID && d.List.Any(f => f.SequenceFlowID == c.ID && f.Done))) || base.EngineSharedModel.CurrentThread == null)
                {
                    acceptedForkSequenceFlows = sequenceFlowService.GetList(base.EngineSharedModel.CurrentProcessID.Value, "", gateway.ElementID, "");
                    new ThreadService(base.UnitOfWork).ClearGatewayStatusXml(base.EngineSharedModel.CurrentThread, gateway.ID);
                }
                else
                {
                    //add this sequence flow path to executed path in Thread.GatewayStatusXml
                    new ThreadService(base.UnitOfWork).AddGatewayStatusXml(base.EngineSharedModel.CurrentThread, gateway.ID, joinFromSequenceFlow.ID);
                    return(new List <sysBpmsSequenceFlow>(), true);
                }
            }
            break;
            }

            if (!acceptedForkSequenceFlows.Any() && gateway.DefaultSequenceFlowID.HasValue)
            {
                acceptedForkSequenceFlows.Add(sequenceFlowService.GetInfo(gateway.DefaultSequenceFlowID.Value));
            }

            return(acceptedForkSequenceFlows, acceptedForkSequenceFlows.Any());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// this will change all back end code id because of compiled dll duplicated.
        /// </summary>
        /// <param name="dynamicForm"></param>
        public void UpdateBackendCodeID(sysBpmsDynamicForm dynamicForm)
        {
            if (!string.IsNullOrWhiteSpace(dynamicForm.DesignJson))
            {
                FormModel formModel = new FormModel(JObject.Parse(dynamicForm.DesignJson), HtmlElementHelper.MakeModel(null, null, HtmlElementHelperModel.e_FormAction.FillMode, dynamicForm), null, null, dynamicForm, false);
                formModel.ContentHtml.Rows.ForEach((row) =>
                {
                    generateCodeID(row);
                    if (row is RowHtml)
                    {
                        readRow(row);
                    }
                    else
                    {
                        ((AccordionHtml)row).Cards.ForEach((car) =>
                        {
                            generateCodeID(car);
                            ((CardHtml)car).Rows.ForEach((item) =>
                            {
                                readRow(item);
                            });
                        });
                    }
                });

                void readRow(object row)
                {
                    ((RowHtml)row).Columns.ForEach((column) =>
                    {
                        generateCodeID(column);
                        column.children.ForEach((item) =>
                        {
                            generateCodeID(item);
                        });
                    });
                }

                void generateCodeID(object item)
                {
                    replaceID(((ElementBase)item).ExpressionVisibilityCode);
                    if (item is ButtonHtml)
                    {
                        replaceID(((ButtonHtml)item).ExpressionConfirmCode);
                        replaceID(((ButtonHtml)item).BackendCoding);
                    }
                    else
                    if (item is DataGridHtml)
                    {
                        DataGridHtml dataGridHtml = (DataGridHtml)item;
                        dataGridHtml.DataGridColumns.ForEach((column) =>
                        {
                            column.ItemList.ForEach((cItem) =>
                            {
                                if (!string.IsNullOrWhiteSpace(cItem.ExpressionConfirmCode))
                                {
                                    replaceID(cItem.ExpressionConfirmCode.FromBase64());
                                }
                                if (!string.IsNullOrWhiteSpace(cItem.RunCodeData))
                                {
                                    replaceID(cItem.RunCodeData.FromBase64());
                                }
                            });
                        });
                    }
                }

                void replaceID(string decodedCode)
                {
                    if (!string.IsNullOrWhiteSpace(decodedCode))
                    {
                        DesignCodeModel designCode = DesignCodeUtility.GetDesignCodeFromXml(decodedCode);
                        if (designCode != null && !string.IsNullOrWhiteSpace(designCode.ID))
                        {
                            dynamicForm.DesignJson = dynamicForm.DesignJson.Replace(decodedCode.ToBase64(), decodedCode.Replace(designCode.ID, Guid.NewGuid().ToStringObj()).ToBase64());
                        }
                    }
                }

                DesignCodeModel codeModel = DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnEntryFormCode);
                if (codeModel != null && !string.IsNullOrWhiteSpace(codeModel.ID))
                {
                    dynamicForm.OnEntryFormCode = dynamicForm.OnEntryFormCode.Replace(codeModel.ID, Guid.NewGuid().ToString());
                }
                codeModel = DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnExitFormCode);
                if (codeModel != null && !string.IsNullOrWhiteSpace(codeModel.ID))
                {
                    dynamicForm.OnExitFormCode = dynamicForm.OnExitFormCode.Replace(codeModel.ID, Guid.NewGuid().ToString());
                }
            }
        }
Ejemplo n.º 7
0
        public ResultOperation GetSourceCode(sysBpmsDynamicForm dynamicForm)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                FormModel formModel    = new FormModel(JObject.Parse(dynamicForm.DesignJson), HtmlElementHelper.MakeModel(null, null, HtmlElementHelperModel.e_FormAction.FillMode, dynamicForm), null, null, dynamicForm, false);
                string    renderedCode = string.Empty;
                formModel.ContentHtml.Rows.ForEach((row) =>
                {
                    renderedCode += renderCode(row);
                    if (row is RowHtml)
                    {
                        readRow(row);
                    }
                    else
                    {
                        ((AccordionHtml)row).Cards.ForEach((car) =>
                        {
                            renderedCode += renderCode(car);
                            ((CardHtml)car).Rows.ForEach((item) =>
                            {
                                readRow(item);
                            });
                        });
                    }
                });

                void readRow(object row)
                {
                    ((RowHtml)row).Columns.ForEach((column) =>
                    {
                        renderedCode += renderCode(column);
                        column.children.ForEach((item) =>
                        {
                            renderedCode += renderCode(item);
                        });
                    });
                }

                string renderCode(object item)
                {
                    DesignCodeModel designCode = null;
                    string          code       = string.Empty;

                    //VisibilityDesignCodeModel
                    code += makeClass(((ElementBase)item).VisibilityDesignCodeModel);
                    //if is button
                    if (item is ButtonHtml)
                    {
                        code += makeClass(((ButtonHtml)item).ConfirmDesignCodeModel);
                        code += makeClass(DesignCodeUtility.GetDesignCodeFromXml(((ButtonHtml)item).BackendCoding));
                    }
                    if (item is DataGridHtml)
                    {
                        DataGridHtml dataGridHtml = (DataGridHtml)item;
                        dataGridHtml.DataGridColumns.ForEach((column) =>
                        {
                            column.ItemList.ForEach((cItem) =>
                            {
                                designCode = DesignCodeUtility.GetDesignCodeFromXml(cItem.ExpressionConfirmCode.FromBase64());
                                if (designCode != null && !string.IsNullOrWhiteSpace(designCode.Code))
                                {
                                    code += makeClass(designCode);
                                }
                                designCode = DesignCodeUtility.GetDesignCodeFromXml(cItem.RunCodeData.FromBase64());
                                if (designCode != null && !string.IsNullOrWhiteSpace(designCode.Code))
                                {
                                    code += makeClass(designCode);
                                }
                            });
                        });
                    }
                    return(code);
                }

                string makeClass(DesignCodeModel designCode)
                {
                    string code = string.Empty;

                    if (designCode != null && !string.IsNullOrWhiteSpace(designCode.Code))
                    {
                        code = DynamicCodeEngine.MakeClass(designCode.Code, designCode.ID);
                    }
                    return(code);
                }
                renderedCode += makeClass(DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnEntryFormCode));
                renderedCode += makeClass(DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnExitFormCode));

                dynamicForm.SourceCode = renderedCode;
                if (dynamicForm.ApplicationPageID.HasValue)
                {
                    DynamicCodeEngine.GenerateAppPageAssembly(dynamicForm);
                }
            }
            catch (Exception ex)
            {
                resultOperation.AddError(ex.ToString());
                resultOperation.AddError("Error while creating code");
            }
            return(resultOperation);
        }
Ejemplo n.º 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));
        }