Esempio 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));
        }
Esempio n. 2
0
        public EngineFormModel PreviewForm(Guid formID, string userName)
        {
            sysBpmsDynamicForm dynamicForm = this.GetInfo(formID);

            EngineSharedModel engineSharedModel = dynamicForm.ApplicationPageID.HasValue ?
                                                  new EngineSharedModel(dynamicForm.ApplicationPageID.Value, new List <QueryModel>(), userName, string.Empty) :
                                                  new EngineSharedModel(Guid.Empty, dynamicForm.ProcessId, new List <QueryModel>(), userName, string.Empty);

            FormModel formModel = new FormModel();
            //convert form xml code to json object
            JObject obj = JObject.Parse(dynamicForm.DesignJson);
            HtmlElementHelperModel htmlElementHelperModel = HtmlElementHelper.MakeModel(engineSharedModel, base.UnitOfWork, HtmlElementHelperModel.e_FormAction.Preview, 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);
            }
            EngineFormModel engineForm = dynamicForm.ApplicationPageID.HasValue ?
                                         new EngineFormModel(formModel, dynamicForm.ApplicationPageID) :
                                         new EngineFormModel(formModel, Guid.Empty, Guid.Empty, dynamicForm.ProcessId);

            return(engineForm);
        }
Esempio n. 3
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());
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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));
        }