//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);
        }
Exemple #2
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);
        }