private static async Task CreateChannelAsync(int siteId, int channelId) { var siteInfo = SiteManager.GetSiteInfo(siteId); var nodeInfo = ChannelManager.GetChannelInfo(siteId, channelId); if (nodeInfo == null) { return; } if (!string.IsNullOrEmpty(nodeInfo.LinkUrl)) { return; } if (!ELinkTypeUtils.IsCreatable(nodeInfo)) { return; } var templateInfo = channelId == siteId ? TemplateManager.GetIndexPageTemplateInfo(siteId) : TemplateManager.GetChannelTemplateInfo(siteId, channelId); var filePath = PathUtility.GetChannelPageFilePath(siteInfo, channelId, 0); var pageInfo = new PageInfo(channelId, 0, siteInfo, templateInfo); var contextInfo = new ContextInfo(pageInfo) { ContextType = EContextType.Channel }; var contentBuilder = new StringBuilder(TemplateManager.GetTemplateContent(siteInfo, templateInfo)); var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); var stlPageContentElement = string.Empty; foreach (var label in stlLabelList) { if (!StlParserUtility.IsStlChannelElement(label, ChannelAttribute.PageContent)) { continue; } stlPageContentElement = label; break; } //如果标签中存在<stl:channel type="PageContent"></stl:channel> if (!string.IsNullOrEmpty(stlPageContentElement))//内容存在 { var innerBuilder = new StringBuilder(stlPageContentElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var contentAttributeHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, contentAttributeHtml) + 1;//一共需要的页数 Parser.Parse(siteInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.SiteInfo, pageInfo.TemplateInfo); var index = contentAttributeHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? contentAttributeHtml.Length : index; var pagedContentAttributeHtml = contentAttributeHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlPageContentElement, pagedContentAttributeHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, 0); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); if (index != -1) { contentAttributeHtml = contentAttributeHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } } //如果标签中存在<stl:pageContents> else if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageContentsElementParser.GetPageCount(out totalNum); Parser.Parse(siteInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.SiteInfo, pageInfo.TemplateInfo); var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); thePageInfo.AddLastPageScript(pageInfo); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); thePageInfo.ClearLastPageScript(pageInfo); pageInfo.ClearLastPageScript(); } } //如果标签中存在<stl:pageChannels> else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageChannelsElementParser.GetPageCount(out totalNum); Parser.Parse(siteInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.SiteInfo, pageInfo.TemplateInfo); var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:pageSqlContents> else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageSqlContentsElementParser.GetPageCount(out totalNum); Parser.Parse(siteInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.SiteInfo, pageInfo.TemplateInfo); var pageHtml = pageSqlContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:StlPageInputContents> //else if (StlParserUtility.IsStlElementExists(StlPageInputContents.ElementName, stlLabelList)) //{ // var stlElement = StlParserUtility.GetStlElement(StlPageInputContents.ElementName, stlLabelList); // var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); // var pageInputContentsElementParser = new StlPageInputContents(stlElement, pageInfo, contextInfo, true); // int totalNum; // var pageCount = pageInputContentsElementParser.GetPageCount(out totalNum); // Parser.Parse(siteInfo, pageInfo, contextInfo, contentBuilder, filePath, false); // for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) // { // var thePageInfo = new PageInfo(pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.SiteInfo, pageInfo.TemplateInfo, null); // var pageHtml = pageInputContentsElementParser.Parse(currentPageIndex, pageCount); // var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); // StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); // filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); // GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); // } //} else { Parser.Parse(siteInfo, pageInfo, contextInfo, contentBuilder, filePath, false); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); } }
//public void CreateIndex() //{ // var templateInfo = TemplateManager.GetTemplateInfo(PublishmentSystemId, 0, ETemplateType.IndexPageTemplate); // if (templateInfo == null) return; // var pageInfo = new PageInfo(PublishmentSystemId, 0, PublishmentSystemInfo, templateInfo, null); // var contextInfo = new ContextInfo(pageInfo); // var filePath = PathUtility.GetIndexPageFilePath(PublishmentSystemInfo, templateInfo.CreatedFileFullName, IsHeadquarters); // var contentBuilder = new StringBuilder(StlCacheManager.FileContent.GetTemplateContent(PublishmentSystemInfo, templateInfo)); // StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); // GenerateFile(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); //} public void CreateChannel(int nodeId) { var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemId, nodeId); if (nodeInfo == null) { return; } //if (nodeId == PublishmentSystemId) //{ // CreateIndex(); // return; //} if (!string.IsNullOrEmpty(nodeInfo.LinkUrl)) { return; } if (!ELinkTypeUtils.IsCreatable(nodeInfo)) { return; } var templateInfo = nodeId == PublishmentSystemId?TemplateManager.GetTemplateInfo(PublishmentSystemId, 0, ETemplateType.IndexPageTemplate) : TemplateManager.GetTemplateInfo(PublishmentSystemId, nodeId, ETemplateType.ChannelTemplate); var filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, nodeId, 0); var pageInfo = new PageInfo(nodeId, 0, PublishmentSystemInfo, templateInfo, null); var contextInfo = new ContextInfo(pageInfo); var contentBuilder = new StringBuilder(StlCacheManager.FileContent.GetTemplateContent(PublishmentSystemInfo, templateInfo)); var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); var stlPageContentElement = string.Empty; foreach (var label in stlLabelList) { if (!StlParserUtility.IsStlChannelElement(label, NodeAttribute.PageContent)) { continue; } stlPageContentElement = label; break; } //如果标签中存在<stl:channel type="PageContent"></stl:channel> if (!string.IsNullOrEmpty(stlPageContentElement))//内容存在 { var innerBuilder = new StringBuilder(stlPageContentElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var contentAttributeHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, contentAttributeHtml) + 1;//一共需要的页数 StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var index = contentAttributeHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? contentAttributeHtml.Length : index; var pagedContentAttributeHtml = contentAttributeHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlPageContentElement, pagedContentAttributeHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, 0); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); if (index != -1) { contentAttributeHtml = contentAttributeHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } } //如果标签中存在<stl:pageContents> else if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlPageContents.Translate(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageContentsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); thePageInfo.AddLastPageScript(pageInfo); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); thePageInfo.ClearLastPageScript(pageInfo); pageInfo.ClearLastPageScript(); } } //如果标签中存在<stl:pageChannels> else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlPageChannels.Translate(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageChannelsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:pageSqlContents> else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlPageSqlContents.Translate(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageSqlContentsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageSqlContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:StlPageInputContents> else if (StlParserUtility.IsStlElementExists(StlPageInputContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageInputContents.ElementName, stlLabelList); var stlElementTranslated = StlPageInputContents.Translate(stlElement); var pageInputContentsElementParser = new StlPageInputContents(stlElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageInputContentsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageInputContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } else { StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); } }