Ejemplo n.º 1
0
        public string GetControlEvent(int elementId = 0, bool isSingle = false)
        {
            //获取件动作
            var eventActionTypeList = PubUiEngineGet.GetEventActionConfigList;
            var model = EventManager.GetInstance.GetEeventList.FindAll(it => it.Name.IsIn("getValue", "setValue").IsFalse());

            foreach (var it in model)
            {
                it.ActionTypeList = eventActionTypeList;
            }
            var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEditorDir, "event.cshtml");

            if (isSingle == true)
            {
                cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEditorDir, "eventSingle.cshtml");
            }
            var html = FileSugar.FileToString(cshtmlPath);

            if (elementId > 0)
            {
                var events = _db.Queryable <SysBest_ElementEvent>().Where(it => it.ElementId == elementId).ToList();
                var reval  = RazorEngineExtension.RazorPars(cshtmlPath, html, new { Key = model, Value = events });
                return(reval);
            }
            else
            {
                var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, new { Key = model, Value = new List <SysBest_ElementEvent>() });
                return(reval);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据配置生成对应的文件 表单生成
        /// </summary>
        /// <param name="config"></param>
        public static void generateForm(GenerateFormConfig_Model config)
        {
            //2.获取html
            //2.1根据配置拆分
            var list_afterChunk = config.columns.Chunk(config.columnsInRowNumber);
            //2.2声明行数据容器
            List <List <FormElement> > list = new List <List <FormElement> >();

            foreach (var info in list_afterChunk)
            {
                List <FormElement> row_temp = new List <FormElement>();
                //遍历当前行
                foreach (var item_info in info)
                {
                    row_temp.Add(new generateHelp().generateHtmlByType(item_info));//取列
                }
                //生成行html
                list.Add(row_temp);
            }
            //3.渲染razor模板
            string templatePath = FileSugar.MergeUrl(globalProperty.templateDic, "formElement", "form.cshtml");
            var    tempCode     = RazorEngineExtension.RazorPars(templatePath, FileSugar.FileToString(templatePath), new { FormElementTable = list });

            //4.将生成的form字符串写入html文件
            FileSugar.WriteFile($"../../html/{config.tableName}.html", tempCode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取事件HTML
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public string GetEventActionHtml(string name, List <EventActionTypeParas> pars, string id)
        {
            var path   = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEventActionDir, name + ".cshtml");
            var cshtml = FileSugar.FileToString(path);
            var reval  = RazorEngineExtension.RazorPars(path, cshtml, new { Data = pars, id = id });

            return(reval);
        }
Ejemplo n.º 4
0
        public string GetTemplateCodeByName(string tempName, object model)
        {
            string dir      = FileSugar.MergeUrl(_uiEngineDir, "buildCode");
            string filePath = FileSugar.MergeUrl(dir, tempName);
            var    tempCode = RazorEngineExtension.RazorPars(filePath, FileSugar.FileToString(filePath), model);

            return(tempCode);
        }
Ejemplo n.º 5
0
        public FormElement generateImg(Column col)
        {
            string templatePath = FileSugar.MergeUrl(globalProperty.templateDic, "formElement", "img", "template.cshtml");

            return(new FormElement()
            {
                elementHtml = generateHelp.getParseString(templatePath, col),
                col = col
            });
        }
Ejemplo n.º 6
0
        //public void RestoreLayoutElement(string htmlId, string key, int addressId, int languageId)
        //{
        //    var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsDir, "layout", key + ".cshtml");
        //    var content = _.sysBest_PageContentService.GetSingle(it => it.LanguageId == languageId && it.AddressId == addressId);
        //    var elementList = _.sysBest_ElementService.GetElementListByHtmlIdArray(new string[] { htmlId });
        //    content.Html = GetRestoreHtml(content.Html, elementList, htmlId);
        //    _.sysBest_PageContentService.Update(content);
        //}

        /// <summary>
        /// 获取还原后的HTML
        /// </summary>
        /// <param name="html"></param>
        /// <param name="elementList"></param>
        /// <param name="htmlId"></param>
        /// <returns></returns>
        public string GetRestoreHtml(string html, List <SysBest_Element> elementList, string htmlId)
        {
            if (!elementList.Any(el => el.Html_Id == htmlId))
            {
                return(html);
            }
            //根据htmlID查对应的元素
            var ele = elementList.Single(el => el.Html_Id == htmlId);
            //正则匹配出对应的占位span标签
            var span = Regex.Match(html, @"\<span.{1,30}?data\-id\=""" + htmlId + @""".*?\<\/span\>").Value;
            //正则匹配出控件类型
            var categoryKey = Regex.Match(span, @"\<.*?data\-categorykey\=""(.+?)"".*?", RegexOptions.Singleline).Groups[1].Value;
            //正则匹配控件Key
            var key = Regex.Match(span, @"\<.*?data\-key\=""(.+?)"".*?").Groups[1].Value;
            var buildTemplatePath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsDir, categoryKey, "items", key, "build.cshtml");

            if (FileSugar.IsExistFile(buildTemplatePath))
            {
                BuildModel buildModel = new BuildModel();
                buildModel.elementId = ele.Id;
                buildModel.addressId = ele.AddressId;



                var attrs  = _db.Queryable <SysBest_ElementAttr>().Where(it => it.ElementId == ele.Id).ToList();
                var events = _db.Queryable <SysBest_ElementEvent>().Where(it => it.ElementId == ele.Id).ToList();
                buildModel.attrList = attrs.Select(attr => new KeyValuePair <string, string>(attr.Key, attr.Value)).ToDictionary(it => it.Key, it => it.Value);
                if (buildModel.attrList == null)
                {
                    buildModel.attrList = new Dictionary <string, string>();
                }
                buildModel.attrList.Add("name", ele.EleName);
                buildModel.eventList = new Dictionary <string, string>();
                foreach (var eve in events)
                {
                    List <EventActionTypeParas> pars = new List <EventActionTypeParas>();
                    if (eve.Pars.IsValuable())
                    {
                        pars = eve.Pars.JsonToModel <List <EventActionTypeParas> >();
                    }
                    string eveValue = GetEventActionHtml(eve.Value, pars, ele.EleName);
                    buildModel.eventList.Add(eve.Key, eveValue);
                }
                var cshtml = FileSugar.FileToString(buildTemplatePath);
                buildModel.api = GetApiUrlByElement(ele);
                string finallyThisIsMyParsedTemplate = "";

                finallyThisIsMyParsedTemplate = RazorEngineExtension.RazorPars(buildTemplatePath, cshtml, buildModel);

                var replaceHtml = finallyThisIsMyParsedTemplate;
                html = html.Replace(span, replaceHtml);
            }

            return(html);
        }
Ejemplo n.º 7
0
        private string GetFileName(ProjectViewModel project, EntitiesGen item)
        {
            var p = ".";

            project.FileSuffix = project.FileSuffix.TrimStart('.');
            if (project.FileSuffix.Contains("."))
            {
                p = null;
            }
            return(FileSugar.MergeUrl(project.Path, item.ClassName + p + project.FileSuffix));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 将错误信息写入日志
        /// </summary>
        /// <param name="ex"></param>
        private static void WriteExMessage(Exception ex)
        {
            var logPath = FileSugar.MergeUrl(
                FileSugar.GetMapPath("~/"),
                "log",
                DateTime.Now.ToString("yyyy-MM-dd.txt")
                );

            FileSugar.AppendText(logPath, "***********{0}{1}***********".ToFormat("开始:", DateTime.Now));
            FileSugar.AppendText(logPath, ex.Message);
            FileSugar.AppendText(logPath, "***********{0}***********\r\n".ToFormat("结束"));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 开始生成表单
        /// </summary>
        public static void StartGenerateForm()
        {
            //1.解析配置
            string configPath = FileSugar.MergeUrl(System.Environment.CurrentDirectory, "generateFormConfig.json");
            //得到配置的json字符串
            string json = FileSugar.FileToString(configPath);
            List <GenerateFormConfig_Model> config = JsonConvert.DeserializeObject <List <GenerateFormConfig_Model> >(json);

            foreach (var item in config)
            {
                //根据配置生成表单
                generateForm(item);
            }
        }
Ejemplo n.º 10
0
        //获取插入ueditor里面的HTML
        /// <summary>
        /// 获取插入ueditor里面的HTML
        /// </summary>
        /// <param name="key">控件的Key</param>
        /// <param name="categoryKey">控件类型的Key</param>
        /// <param name="hasSource"></param>
        /// <returns></returns>
        public string GetEditor(string key, string categoryKey, bool?hasSource)
        {
            //控件模板地址
            var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineEditorDir, "template.cshtml");
            //控件图标地址
            var icon = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsWebDir, categoryKey, "items", key, "icon.png");
            //传给raozr的Model
            var model = new { categoryKey = categoryKey, key = key, icon = icon, hasSource = hasSource };
            //razor模板对应的文本
            var html = FileSugar.FileToString(cshtmlPath);
            //解析razor生成最终的文本
            var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, model);

            return(reval);
        }
Ejemplo n.º 11
0
        public ApiResult <bool> Exportfile([FromForm] string model, [FromForm] int dbid)
        {
            ApiResult <bool> result = new ApiResult <bool>()
            {
                IsSuccess = true
            };
            var tableDb = base.GetTryDb(dbid);
            var dts     = Export(model, tableDb);
            var bytes   = Table_ToExcel.ExportExcel(dts, "数据库文档.xlsx");
            var url     = FileSugar.MergeUrl(Startup.GetCurrentDirectory(), "excel/数据库文档" + SqlSugar.SnowFlakeSingle.Instance.getID() + ".xlsx");

            FileSugar.CreateFile(url, bytes);
            OpenPath(url);
            return(result);
        }
Ejemplo n.º 12
0
        public string GetControlAttribute(string key, string categoryKey, int elementId = 0)
        {
            var cshtmlPath = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsDir, categoryKey, "items", key, "attribute.cshtml");
            var html       = FileSugar.FileToString(cshtmlPath);

            if (elementId > 0)
            {
                var attrs = _db.Queryable <SysBest_ElementAttr>().Where(it => it.ElementId == elementId).ToList();
                var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, attrs);
                return(reval);
            }
            else
            {
                var reval = RazorEngineExtension.RazorPars(cshtmlPath, html, new List <SysBest_ElementAttr>());
                return(reval);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 获取UI引擎控件信息
        /// </summary>
        /// <param name="item"></param>
        private ControlType GetControlType(string item)
        {
            ControlType   type = new ControlType();
            DirectoryInfo di   = new DirectoryInfo(item);

            type.key  = di.Name;
            type.icon = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsWebDir, type.key, "icon.png");
            string webTypeDir    = FileSugar.MergeUrl(PubUiEngineGet.GetUiEngineControlsWebDir, type.key);
            string configPath    = FileSugar.MergeUrl(item, "config.json");
            string code          = FileSugar.FileToString(configPath);
            var    controlConfig = code.JsonToModel <ControlConfig>();

            type.controlConfig = controlConfig;
            string itemsPath = FileSugar.MergeUrl(item, "items");

            type.items = GetControlList(itemsPath, webTypeDir);
            return(type);
        }
Ejemplo n.º 14
0
        private string GetFileName(Project project, EntitiesGen item)
        {
            var    p    = ".";
            string name = item.ClassName;

            project.FileSuffix = project.FileSuffix.TrimStart('.');
            if (project.FileSuffix.Contains("."))
            {
                p = null;
            }
            if (project.NameFormat != null && project.NameFormat.Contains("@(") && project.NameFormat.Contains(")"))
            {
                var format = project.NameFormat.Replace("{0}", "Model.ClassName");
                name = TemplateHelper.GetTemplateValue(project.NameFormat + "format", format, item);
            }
            else if (!string.IsNullOrEmpty(project.NameFormat))
            {
                name = string.Format(project.NameFormat, item.ClassName);
            }
            return(FileSugar.MergeUrl(project.Path, name + p + project.FileSuffix));
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 写入日志文件
 /// </summary>
 /// <param name="ex"></param>
 public static void WirteExp(Exception ex)
 {
     try
     {
         var logPath = FileSugar.MergeUrl(
             FileSugar.GetMapPath("~/"),
             "log",
             DateTime.Now.ToString("yyyy-MM-dd") + ".txt"
             );
         if (FileSugar.IsExistFile(logPath).IsFalse())
         {
             FileSugar.CreateFile(logPath);
         }
         FileSugar.AppendText(logPath, "***********{0}{1}***********".ToFormat("开始:", DateTime.Now));
         FileSugar.AppendText(logPath, ex.Message);
         FileSugar.AppendText(logPath, "***********{0}***********\r\n".ToFormat("结束"));
     }
     catch
     {
     }
 }
Ejemplo n.º 16
0
        public void Excute(int menuAddressId, int languageId, string uiEngineDir)
        {
            _uiEngineDir = uiEngineDir;
            var data = _db.Queryable <SysBest_MenuAddress>().FirstOrDefault(it => it.Id == menuAddressId);

            _data       = data;
            _languageId = languageId;
            string areaBoxDir           = FileSugar.MergeUrl(_solutionDir, "Areas", data.AreaName);
            string areaDir              = FileSugar.MergeUrl(_solutionDir, "Areas", data.AreaName);
            string viewsDir             = FileSugar.MergeUrl(areaDir, "Views");
            string areaRegistrationPath = FileSugar.MergeUrl(areaDir, "{0}AreaRegistration.cs".ToFormat(data.AreaName));
            string controllerDir        = FileSugar.MergeUrl(areaDir, "Controllers", data.ControllerName + "App");
            string controllerDomainDir  = FileSugar.MergeUrl(areaDir, "Controllers", data.ControllerName + "App", "Domain");
            string controllerDomainPath = FileSugar.MergeUrl(areaDir, "Controllers", data.ControllerName + "App", "Domain", data.ControllerName + "Domain.cs");
            string configPath           = FileSugar.MergeUrl(viewsDir, "Web.config");
            string viewPath             = FileSugar.MergeUrl(viewsDir, _data.ControllerName, _data.ActionName + ".cshtml");

            var lan = _db.Queryable <SysBest_Language>().FirstOrDefault(it => it.Id == languageId).Suffix;

            if (lan.IsValuable() && lan != "zh")
            {
                viewPath = FileSugar.MergeUrl(viewsDir, _data.ControllerName, _data.ActionName + $"_{lan}.cshtml");
            }
            string controllerPath = FileSugar.MergeUrl(controllerDir, data.ControllerName + "Controller.cs");
            string path           = _solutionDir + @"\" + _projectName + ".csproj";

            try
            {
                XDocument doc = XDocument.Load(path);
                BuildArea(areaDir, viewsDir, controllerDomainDir, areaRegistrationPath, configPath, doc);
                BuildController(controllerDir, controllerPath, controllerDomainPath, doc);
                BuildView(viewPath, doc);
                BuildDatabaseTableTable();
                doc.Save(path);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 17
0
        private List <ControlItem> GetControlList(string itemsPath, string webTypeDir)
        {
            var reval           = new List <ControlItem>();
            var controlsDirList = FileSugar.GetDirectories(itemsPath);

            if (controlsDirList.IsValuable())
            {
                foreach (var item in controlsDirList)
                {
                    ControlItem   control = new ControlItem();
                    DirectoryInfo di      = new DirectoryInfo(item);
                    control.key  = di.Name;
                    control.icon = FileSugar.MergeUrl(webTypeDir, "items", control.key, "icon.png");
                    string configPath    = FileSugar.MergeUrl(itemsPath, control.key, "config.json");
                    string code          = FileSugar.FileToString(configPath);
                    var    controlConfig = code.JsonToModel <ControlConfig>();
                    control.controlConfig = controlConfig;
                    reval.Add(control);
                }
            }
            return(reval);
        }