Esempio n. 1
0
        public void CompileHome(int siteId)
        {
            //获取网站模板风格
            var siteModel = _cmsCoreDB.Site.FirstOrDefault(p => p.ID == siteId);

            if (siteModel != null)
            {
                var homeTemplatePath = string.Format("{0}\\Templates\\{1}\\index.cshtml",
                                                     AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'),
                                                     siteModel.DefaultStyle);

                var viewBag = new DynamicViewBag();
                viewBag.AddValue("Data", siteModel);

                var parseResult = ParsePathContent(homeTemplatePath, viewBag);

                if (!string.IsNullOrEmpty(parseResult))
                {
                    var publishResult = new PublishResult
                    {
                        Context      = parseResult,
                        Path         = siteModel.RootPath,
                        FileName     = "Index",
                        ReleasePoint = siteModel.ReleasePointId
                    };
                    _publishEngine.Push(publishResult);
                }
            }
        }
Esempio n. 2
0
        public void CompileCategory(int categoryId)
        {
            //编译栏目首页
            //传递参数:模板文件[单页、模型]、SEOMeta
            //发布结果:解析结果、网站发布点、保存路径、保存文件名

            var categoryModel = _cmsCoreDB.Category.FirstOrDefault(p => p.ID == categoryId);

            if (categoryModel != null)
            {
                var templatePath = string.Empty;
                var parseResult  = string.Empty;
                var viewBag      = new DynamicViewBag();

                if (categoryModel.ModelType == 0)
                {
                    //单页内容模板
                    var singlePageModel = _cmsCoreDB.SinglePage.FirstOrDefault(p => p.ID == categoryModel.ModelId);
                    if (singlePageModel != null)
                    {
                        templatePath = string.Format("{0}\\Templates\\{1}\\{2}",
                                                     AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'),
                                                     singlePageModel.DefaultStyle,
                                                     singlePageModel.Template.Replace("/", "\\"));

                        viewBag.AddValue("Data", singlePageModel);

                        parseResult = ParsePathContent(templatePath, viewBag);
                    }
                }
                else if (categoryModel.ModelType == 1)
                {
                    //自定义内容模型
                    templatePath = string.Format("{0}\\Templates\\{1}\\{2}",
                                                 AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'),
                                                 categoryModel.DefaultStyle,
                                                 categoryModel.CategoryTemplate.Replace("/", "\\"));

                    viewBag.AddValue("Data", categoryModel);

                    parseResult = ParsePathContent(templatePath, null);
                }
                else
                {
                    return;
                }

                //发布
                if (!string.IsNullOrEmpty(parseResult))
                {
                    var publishResult = new PublishResult
                    {
                        Context  = parseResult,
                        Path     = categoryModel.CatPath, //递归路径
                        FileName = "Index",
                    };
                    _publishEngine.Push(publishResult);
                }
            }
        }
Esempio n. 3
0
        public void Push(PublishResult result)
        {
            //构建本地目录
            var directoryPath = string.Format("{0}\\{1}",
                                              AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'),
                                              result.Path.TrimStart('/').Trim().Replace("/", "\\"));

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            var filePath = string.Format("{0}\\{1}.html", directoryPath.TrimEnd('\\'), result.FileName);

            //删除现有的文件
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            //模板渲染结果写入到本地文件
            File.AppendAllText(filePath, result.Context, Encoding.UTF8);
        }
Esempio n. 4
0
        public void CompileCategoryContent(int categoryId)
        {
            //逐条生成

            //获取栏目实体
            var categoryModel = _cmsCoreDB.Category.FirstOrDefault(p => p.ID == categoryId);

            if (categoryModel != null)
            {
                //自定义内容模型
                if (categoryModel.ModelType == 1)
                {
                    var customContentModel = _cmsCoreDB.ContentModel.FirstOrDefault(p => p.ID == categoryModel.ModelId);
                    if (customContentModel != null)
                    {
                        var pageSize         = categoryModel.ShowPageSize;
                        var pageIndex        = 0;
                        var templateFilePath = string.Format("{0}\\Templates\\{1}\\{2}",
                                                             AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'),
                                                             categoryModel.DefaultStyle,
                                                             categoryModel.ShowTemplate.Replace("/", "\\"));

                        //按分页遍历生成
                        var dataModelManage = new DataModelManage();

                        //GOTO返回获取数据标志
RELOADPAGELIST:

                        #region GOTO循环获取分页数据,直至分页为0

                        var pageListModel = dataModelManage.GetPageList(customContentModel.TableName, categoryId, pageIndex, pageSize);

                        //如果存在数据
                        var listModel = pageListModel as dynamic[] ?? pageListModel.ToArray();
                        if (listModel.Any())
                        {
                            //逐个渲染模型
                            foreach (var m in listModel)
                            {
                                var viewBag = new DynamicViewBag();

                                viewBag.AddValue("Data", m);

                                //渲染
                                var parseResult = ParsePathContent(templateFilePath, viewBag);

                                //发布
                                if (!string.IsNullOrEmpty(parseResult))
                                {
                                    var publishResult = new PublishResult
                                    {
                                        Context = parseResult,
                                        Path    = categoryModel.CatPath, //递归路径
                                    };

                                    publishResult.FileName = m.ID.ToString();

                                    _publishEngine.Push(publishResult);
                                }
                            }

                            //当前分页索引递增至下一页
                            pageIndex++;

                            //重新获取下一分页数据
                            goto RELOADPAGELIST;
                        }

                        #endregion
                    }
                }
            }
        }