示例#1
0
        private void BuildView(string viewPath, XDocument doc)
        {
            ConvertCshtml _cs        = new ConvertCshtml(_db);
            int           addressId  = _data.Id;
            int           languageId = _languageId;
            var           review     = _cs.ReviewModel(addressId, languageId);

            review.JsSrc   = @"/Areas/{0}/Views/_js/{1}-{2}.js".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower());
            review.CssHref = @"/Areas/{0}/Views/_css/{1}-{2}.css".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower());
            ContainConfigToCsproj(@"Areas\{0}\Views\_css\{1}-{2}.css".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower()), _solutionDir, _projectName, doc);
            ContainConfigToCsproj(@"Areas\{0}\Views\_js\{1}-{2}.js".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower()), _solutionDir, _projectName, doc);
            string jsPath  = FileSugar.GetMapPath(review.JsSrc);
            string cssPath = FileSugar.GetMapPath(review.CssHref);

            if (FileSugar.IsExistFile(jsPath).IsFalse())
            {
                FileSugar.CreateFile(jsPath);
                FileSugar.WriteFile(jsPath, "///<reference path=\"/_theme/tool/_reference.js\" />", "utf-8");
            }
            if (FileSugar.IsExistFile(cssPath).IsFalse())
            {
                FileSugar.CreateFile(cssPath);
            }
            var viewCode       = GetTemplateCodeByName("view.cshtml", review);
            var languageSuffix = string.Empty;

            if (languageId != 1)
            {
                languageSuffix = $"_{GetLanguageList.Single(it => it.Id == languageId).Suffix}";
            }
            FileSugar.WriteFile(viewPath, viewCode);
            ContainConfigToCsproj(@"Areas\{0}\Views\{1}\{2}{3}.cshtml".ToFormat(_data.AreaName, _data.ControllerName, _data.ActionName, languageSuffix), _solutionDir, _projectName, doc);
        }
示例#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);
        }
示例#3
0
        /// <summary>
        /// 生成controller
        /// </summary>
        private void BuildController(string controllerDir, string controllerPath, string controllerDomainPath, XDocument doc)
        {
            //写入控制器
            if (!FileSugar.IsExistFile(controllerPath))
            {
                FileSugar.CreateDirectory(controllerDir);
                ContainFileToCsproj(@"Areas\{0}\Controllers\{1}App\{1}Controller.cs".ToFormat(_data.AreaName, _data.ControllerName), _solutionDir, _projectName, doc);
            }

            //获取controller.cshtml的Model
            BuildControllerModel controllerModel = new BuildControllerModel()
            {
                areaName       = _data.AreaName,
                controllerName = _data.ControllerName,
                actionName     = _data.ActionName,
                siteName       = ConfigSugar.GetAppString("siteName")
            };

            var apiList    = _db.Queryable <SysBest_DataApi>().ToList();//获取所有api
            int addressId  = _data.Id;
            int languageId = _languageId;
            var eleList    = _db.Queryable <SysBest_Element>().Where(it => it.AddressId == addressId && it.LanguageId == languageId).ToList();

            var eleApidList = eleList.Where(it => it.ApiId != null && it.ApiId > 0).Select(it => it.ApiId).Distinct().ToList();//获取所有元素

            //获取元素表里面的数据接口
            controllerModel.apiList = apiList.Join(eleApidList, api => api.Id, ele => ele, (api, ele) => api).ToList();
            //获取属性表里面的数据接口
            controllerModel.apiList.AddRange(GetDataApiWithEleEventByEleId(eleList));
            controllerModel.apiList = controllerModel.apiList.Distinct().ToList();

            string controllerCode = GetTemplateCodeByName("controller.cshtml", controllerModel);

            FileSugar.WriteFile(controllerPath, controllerCode);

            //写入Domain
            if (!FileSugar.IsExistFile(controllerDomainPath))
            {
                var domainCode = GetTemplateCodeByName("controller_domain.cshtml", new { controllerName = _data.ControllerName, areaName = _data.AreaName });
                FileSugar.WriteFile(controllerDomainPath, domainCode);
                ContainFileToCsproj(@"Areas\{0}\Controllers\{1}App\Domain\{1}Domain.cs".ToFormat(_data.AreaName, _data.ControllerName), _solutionDir, _projectName, doc);
            }
        }
示例#4
0
        /// <summary>
        /// 生成area
        /// </summary>
        private void BuildArea(string areaDir, string viewsDir, string controllerDomainDir, string areaRegistrationPath, string configPath, XDocument doc)
        {
            //创建area
            if (!FileSugar.IsExistDirectory(areaDir))
            {
                //创建目录
                FileSugar.CreateDirectory(areaDir);  //创建area
                FileSugar.CreateDirectory(viewsDir); //创建views
                FileSugar.CreateDirectory(controllerDomainDir);

                //创建文件


                //创建文件
                var areaRegistrationCode = GetTemplateCodeByName("area_gobal.cshtml", new { projectName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, area = _data.AreaName });
                FileSugar.WriteFile(areaRegistrationPath, areaRegistrationCode);
                ContainFileToCsproj(@"Areas\{0}\{0}AreaRegistration.cs".ToFormat(_data.AreaName), _solutionDir, _projectName, doc);
                ContainConfigToCsproj(@"Areas\{0}\Views\Web.config".ToFormat(_data.AreaName), _solutionDir, _projectName, doc);
            }
            var webConfigCode = GetTemplateCodeByName("area_webConfig.cshtml", new { });

            FileSugar.WriteFile(configPath, webConfigCode);
        }