示例#1
0
        private static CodeBase LoadClass(string className, Guid?processID, Guid?applicationPageID)
        {
            AppDomain.CurrentDomain.AssemblyResolve += MyResolveEventHandler;
            string compiled     = BPMSResources.FilesRoot + BPMSResources.AssemblyRoot + "\\" + BPMSResources.AssemblyCompiledRoot;
            string compiledFile = compiled + "\\" + (processID.ToStringObjNull() ?? applicationPageID.ToStringObj());

            if (!System.IO.Directory.Exists(compiled))
            {
                System.IO.Directory.CreateDirectory(compiled);
            }

            if (System.IO.File.Exists(compiledFile))
            {
                return(DynamicCodeEngine.GetAssembly(compiledFile).CreateInstance("c_" + className.Replace("-", "_")) as CodeBase);
            }
            else
            {
                CompileAssemblies(processID.HasValue ?
                                  new ProcessService().GetInfo(processID.Value).SourceCode :
                                  new DynamicFormService().GetInfoByPageID(applicationPageID.Value).SourceCode,
                                  processID.ToStringObjNull() ?? applicationPageID.ToStringObj());

                return(DynamicCodeEngine.GetAssembly(compiledFile).CreateInstance("c_" + className.Replace("-", "_")) as CodeBase);
            }
        }
示例#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);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="onlyCondition">Is true for condition rule like visibilty of form or gateway condition</param>
        /// <returns></returns>
        private (bool result, CodeBase codeBase) Execute(DesignCodeModel designCodeModel, FormModel formModel, CodeBaseSharedModel codeBaseShared, bool onlyCondition)
        {
            var      listItem = designCodeModel.CodeObjects.Cast <DCBaseModel>().ToList();
            CodeBase codeBase;
            bool     result = true;

            if (listItem.Any(c => c is DCExpressionModel))
            {
                codeBase = DynamicCodeEngine.LoadClass(designCodeModel.ID, base.EngineSharedModel.CurrentProcessID, base.EngineSharedModel.CurrentApplicationPageID);
            }
            else
            {
                codeBase = new CodeBase();
            }

            codeBase.InitialProperties(base.EngineSharedModel.CurrentProcessID, base.EngineSharedModel.CurrentThreadID, base.EngineSharedModel.CurrentApplicationPageID, base.UnitOfWork, base.EngineSharedModel.BaseQueryModel, GetCurrentUserID(base.EngineSharedModel.CurrentUserName), base.EngineSharedModel.CurrentUserName, formModel, base.EngineSharedModel.ApiSessionID, codeBaseShared);
            this.ExecuteCodeModel(listItem, codeBase, onlyCondition, string.Empty, ref result);
            return(result, codeBase);
        }
示例#5
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);
        }
示例#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));
        }