/// <summary> /// 存储/更新实体对象是否成功 /// </summary> public bool StoredSuccess(object Instance) { AccessWebChannel aWebChannel = Instance as AccessWebChannel; if (aWebChannel == null) { return(false); } string strOp = (aWebChannel.ChannelID == 0) ? "I" : "U@[TypeID=" + aWebChannel.ChannelID.ToString() + "]"; string sql = OleDbHelper.BuildSqlIU(OleDbHelper.DbDialect.MsAccess, "Tbl_Type", strOp, new string[] { "TypeName", "ParentTypeID", "Sort", "GroupID", "StaticFileDir", "ArchiveDays", "DisplayByPath", "OuterLinkUrl", "GenTempletRule" }, new object[] { OleDbHelper.EscapeSQL(aWebChannel.ChannelName), aWebChannel.ParentChannel.ChannelID, aWebChannel.Sort, Convert.ToInt32(aWebChannel.GetDefinition("GroupID")), OleDbHelper.EscapeSQL((aWebChannel.StaticFileGenDir + "/").Replace("//", "/")), aWebChannel.ArchiveDays, aWebChannel.IsOuterLink, OleDbHelper.EscapeSQL(aWebChannel.OuterLinkUrl), OleDbHelper.EscapeSQL(aWebChannel.GetTempletConfigStoreText(65535)) }); strOp = FanmaquerOleDbModule.GetOleDbInstance(FanmaquarConfig.ConnectionKey).ExecuteNonQuery(sql).ToString(); return(strOp != "0"); }
/// <summary> /// 通过ID初始化实例对象实现 /// </summary> public object GetInstanceById(int InstanceID) { AccessWebChannel aWebChannel = new AccessWebChannel(InstanceID); DataRow dRow = FanmaquerOleDbModule.GetOleDbInstance(FanmaquarConfig.ConnectionKey).GetDataRow(string.Format("select top 1 * from Tbl_Type where TypeID={0}", InstanceID)); if (dRow != null) { aWebChannel.ChannelName = dRow["TypeName"].ToString(); aWebChannel.Sort = Convert.ToInt32(dRow["Sort"]); aWebChannel.IsOuterLink = Convert.ToBoolean(dRow["DisplayByPath"]); aWebChannel.OuterLinkUrl = dRow["OuterLinkUrl"].ToString(); aWebChannel.StaticFileGenDir = dRow["StaticFileDir"].ToString(); aWebChannel.ArchiveDays = Convert.ToInt32(dRow["ArchiveDays"]); aWebChannel.ParentChannel = new AccessWebChannel(Convert.ToInt32(dRow["ParentTypeID"])); aWebChannel.SetDefined("GroupID", dRow["GroupID"].ToString()); #region Templet with file generate rules. string xmlTptRule = dRow["GenTempletRule"].ToString(); if (xmlTptRule.Length > 10) { StringReader sR = new StringReader(xmlTptRule); // OleDbHelper.AppendToFile(true, @"D:\wwwroot\newsign\chinaqmzxco29607\@docs\temp.xml", //"\n\r\n**" + dRow["GenTempletRule"].ToString()); XmlSerializer xSer = new XmlSerializer(typeof(TempletSetting)); aWebChannel.TempletConfig = (TempletSetting)xSer.Deserialize(sR); } #endregion aWebChannel.IsExist = true; } aWebChannel.IsFilled = true; return(aWebChannel); }
public void ProcessRequest(HttpContext context) { HttpRequest Request = context.Request; if (Util.IsNumerical(Request.QueryString["ChannelID"])) { AccessWebChannel aWebChannel = new AccessWebChannel(Int32.Parse(Request.QueryString["ChannelID"])); if (aWebChannel.IsFilled == false) { aWebChannel = (new AccessWebChannel()).GetInstanceById(aWebChannel.ChannelID) as AccessWebChannel; } if (aWebChannel != null && aWebChannel.IsExist == true && aWebChannel.IsFilled == true) { TempletSetting tptConfig = aWebChannel.TempletConfig; if (tptConfig == null) { ShowMessage("该频道没有配置模板,不能动态显示相关内容!"); return; } if (Request.QueryString["Action"] == "list") { if (tptConfig.GenerateListPage == true) { #region 列表页面生成 PageTemplet pageTpt = (new PageTemplet()).GetInstanceById(tptConfig.ListPageTemplet.TempletID) as PageTemplet; if (pageTpt != null && pageTpt.IsExist == true && pageTpt.IsFilled == true) { #region 根据模板内的列表动态显示当前页内容 if (pageTpt.IsMixedSyntax == false) { DisplayContent(HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, pageTpt.TempletRawContent)); return; } else { string realContent = "", myPageHtml = ""; TempletParse tpp = new TempletParse(); tpp.Caller = this; tpp.SetResourceDependency(aWebChannel); tpp.SetTaggedObjectCollection(pageTpt.TempletRawContent); if (this.PagedObject == null) { myPageHtml = tpp.ParsedResult; //处理分页导航内容 if (this.PagerDic.Count > 0) { foreach (string pagerKey in PagerDic.Keys) { myPageHtml = myPageHtml.Replace(pagerKey, ""); } } DisplayContent(HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, myPageHtml)); } else { string dynTpt = tpp.ParsedResult; string currentPageMatch = ""; PagedObject.SetResourceDependency(aWebChannel); if (Request.QueryString["Page"] != null && Util.IsMatch(@"^(\d+)$", Request.QueryString["Page"], 1, 1, PagedObject.GetPageCount(), out currentPageMatch)) { PagedObject.CurrentPageIndex = int.Parse(Request.QueryString["Page"]); } else { PagedObject.CurrentPageIndex = 1; } #region 显示分页内容 realContent = PagedObject.GetCurrentPageContent(); //处理当前页内容 myPageHtml = dynTpt.Replace(PagedContentAlia, realContent); //处理分页导航内容 if (this.PagerDic.Count > 0) { foreach (string pagerKey in PagerDic.Keys) { PagerTag Pager = PagerDic[pagerKey]; Pager.TotalRecordCount = PagedObject.GetTotalRecordCount(); Pager.CurrentPage = PagedObject.CurrentPageIndex; Pager.StartIndex = PagedObject.StartIndex; Pager.EndIndex = PagedObject.EndIndex; Pager.PageSize = PagedObject.PageSize; Pager.DefaultPageFormat = Request.ServerVariables["SCRIPT_NAME"] + "?ChannelID=" + aWebChannel.ChannelID.ToString() + "&action=list&Page={0}"; myPageHtml = myPageHtml.Replace(pagerKey, Pager.ToString()); } } DisplayContent(HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, myPageHtml)); #endregion } tpp.Dispose(); } #endregion } else { ShowMessage("页面模板实体还原失败,请检查配置是否正确!"); } #endregion } else { ShowMessage("没有可以直接查看的分页内容!"); } } else { if (tptConfig.GenerateSinglePage == true) { #region 单页综合生成 PageTemplet pageTpt = (new PageTemplet()).GetInstanceById(tptConfig.MixedSingleTemplet.TempletID) as PageTemplet; if (pageTpt != null && pageTpt.IsExist == true && pageTpt.IsFilled == true) { if (pageTpt.IsMixedSyntax == false) { DisplayContent(HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, pageTpt.TempletRawContent)); } else { TempletParse tpp = new TempletParse(); tpp.Caller = this; tpp.SetResourceDependency(aWebChannel); tpp.SetTaggedObjectCollection(pageTpt.TempletRawContent); DisplayContent(HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, tpp.ParsedResult)); } } else { ShowMessage("页面模板实体还原失败,请检查配置是否正确!"); } #endregion } else { ShowMessage("没有可以直接查看的单页综合内容!"); } } } else { ShowMessage("频道资料无效!"); } } else { //根据ID找到频道、 应用频道模板、分析模板内容输出 if (Util.IsNumerical(Request.QueryString["ID"])) { ViewNews(Int32.Parse(Request.QueryString["ID"])); } else { ShowMessage("请指定要查看的动态内容!"); } } }
/// <summary> /// 根据网站页面完整相对地址自动更新页面内容 /// </summary> /// <param name="fileRelatviePath">页面完整相对地址</param> public static void GeneratorByPath(string fileRelatviePath) { string trackPath = fileRelatviePath.Replace("'", ""); //先找新闻表,再找频道表 OleDbHelper hp = FanmaquerOleDbModule.GetOleDbInstance(FanmaquarConfig.ConnectionKey); object tid = hp.ExecuteScalar("select top 1 NewsID from Tbl_Articles where VirtualPath='" + trackPath + "'"); if (tid != null) { AccessWebNews news = new AccessWebNews(Convert.ToInt32(tid)); (new PageGenerator()).Generate(news); } else { tid = hp.ExecuteScalar("select top 1 TypeID from Tbl_Type where OuterLinkUrl='" + trackPath + "'"); if (tid != null) { AccessWebChannel channel = new AccessWebChannel(Convert.ToInt32(tid)); (new PageGenerator()).Generate(channel); } } }
/// <summary> /// 生成网站栏目/频道静态文件 /// </summary> /// <param name="aWebChannel">指定了ChannelID的实体</param> public void Generate(AccessWebChannel aWebChannel, ChannelGeneratorOptions options) { if (aWebChannel.IsFilled == false) { aWebChannel = (new AccessWebChannel()).GetInstanceById(aWebChannel.ChannelID) as AccessWebChannel; } if (aWebChannel != null && aWebChannel.IsExist == true && aWebChannel.IsFilled == true) { if (aWebChannel.StaticFileGenDir.IndexOf("/") == -1) { ShowMessage("生成文件目录设置有错误,系统终止!"); return; } TempletSetting tptConfig = aWebChannel.TempletConfig; if (tptConfig == null) { ShowMessage("该频道没有配置模板,不能生成相关文件!"); } else { string strGenFilePath, strFileName, strFileExt, strGenResult = ""; if (aWebChannel.StaticFileGenDir.IndexOf("{#$ChannelID$#}") != -1) { aWebChannel.StaticFileGenDir = aWebChannel.StaticFileGenDir.Replace("{#$ChannelID$#}", aWebChannel.ChannelID.ToString()); } strGenFilePath = Util.ParseAppPath(aWebChannel.StaticFileGenDir); //ShowMessage(strGenFilePath); if (!strGenFilePath.EndsWith("\\")) strGenFilePath += "\\"; //最终页面内容 string strGenFileContent = ""; string trackPath = ""; this.UTCDateBegin = DateTime.Now.ToUniversalTime(); if (options != null && options.GenerateSinglePage == false) { ShowMessage("* 已禁止单页综合内容页生成!"); } else { #region 单页综合生成 if (tptConfig.GenerateSinglePage == true) { strFileName = tptConfig.MixedSingleTemplet.FileNameConfig.FileNameTag.GetTagValue().ToString(); strFileExt = tptConfig.MixedSingleTemplet.FileNameConfig.FileExtentionName; PageTemplet pageTpt = (new PageTemplet()).GetInstanceById(tptConfig.MixedSingleTemplet.TempletID) as PageTemplet; if (pageTpt != null && pageTpt.IsExist == true && pageTpt.IsFilled == true) { if (pageTpt.IsMixedSyntax == false) { if (!pageTpt.SiteBaseDir.EndsWith("/")) pageTpt.SiteBaseDir += "/"; strGenResult = OleDbHelper.SetTextFileContent(strGenFilePath + strFileName + strFileExt, "utf-8", HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, pageTpt.TempletRawContent)); if (strGenResult == "0") { FireGeneratorFileFinished(strGenFilePath + strFileName + strFileExt); } } else { TempletParse tpp = new TempletParse(); tpp.Caller = this; tpp.SetResourceDependency(aWebChannel); tpp.TagTrack = new System.Collections.Generic.Dictionary<string, string>(); tpp.TagTrack.Add("T" + pageTpt.TempletID.ToString(), pageTpt.ModifiedTime.ToString("yyyyMMddHHmmss")); tpp.SetTaggedObjectCollection(pageTpt.TempletRawContent); strGenFileContent = HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, tpp.ParsedResult); //插入Track代码 trackPath = GetSiteRelativeUrl(strGenFilePath + strFileName + strFileExt); GetTrackHtmlInSertCode(tpp.TagTrack, trackPath, "</body>", ref strGenFileContent); strGenResult = OleDbHelper.SetTextFileContent(trackPath, "utf-8", strGenFileContent); if (strGenResult == "0") { FireGeneratorFileFinished(trackPath); } } if (strGenResult == "0") { TrackUnit.RemoveUpdateRecord(0, trackPath); ShowMessage(string.Format("单页内容生成成功!<a href=\"{0}\" target=\"_blank\">{0}</a>", GetSiteRelativeUrl(strGenFilePath + strFileName + strFileExt))); } } else { ShowMessage("页面模板实体还原失败,请检查配置是否正确!"); } } #endregion } if (options != null && options.GenerateListPage == false) { ShowMessage("* 已禁止列表页生成!"); } else { #region 列表页面生成 if (tptConfig.GenerateListPage == true) { strFileExt = tptConfig.ListPageTemplet.FileNameConfig.FileExtentionName; tptConfig.ListPageTemplet.FileNameConfig.FileNameTag.SetResourceDependency(aWebChannel); strFileName = tptConfig.ListPageTemplet.FileNameConfig.FileNameTag.GetTagValue().ToString(); PageTemplet pageTpt = (new PageTemplet()).GetInstanceById(tptConfig.ListPageTemplet.TempletID) as PageTemplet; if (pageTpt != null && pageTpt.IsExist == true && pageTpt.IsFilled == true) { strGenResult = ""; #region 根据模板内的列表动态生成多个页 if (pageTpt.IsMixedSyntax == false) { if (!pageTpt.SiteBaseDir.EndsWith("/")) pageTpt.SiteBaseDir += "/"; strGenResult = OleDbHelper.SetTextFileContent(strGenFilePath + strFileName + strFileExt, "utf-8", HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, pageTpt.TempletRawContent)); if (strGenResult == "0") { FireGeneratorFileFinished(strGenFilePath + strFileName + strFileExt); ShowMessage(string.Format("文件生成成功!<a href=\"{0}\" target=\"_blank\">{0}</a>", GetSiteRelativeUrl(strGenFilePath + strFileName + strFileExt))); } } else { string realContent = "", myPageHtml = ""; TempletParse tpp = new TempletParse(); //获取要分页变化的模块内容(含Pager) //替换分页变化的内容 + 生成多页 tpp.Caller = this; tpp.SetResourceDependency(aWebChannel); tpp.TagTrack = new System.Collections.Generic.Dictionary<string, string>(); tpp.TagTrack.Add("T" + pageTpt.TempletID.ToString(), pageTpt.ModifiedTime.ToString("yyyyMMddHHmmss")); tpp.SetTaggedObjectCollection(pageTpt.TempletRawContent); if (this.PagedObject == null) { myPageHtml = tpp.ParsedResult; //处理分页导航内容 if (this.PagerDic.Count > 0) { foreach (string pagerKey in PagerDic.Keys) { myPageHtml = myPageHtml.Replace(pagerKey, ""); } } strGenFileContent = HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, myPageHtml); //插入Track代码 trackPath = GetSiteRelativeUrl(strGenFilePath + TagBase.TrimTagDefine(strFileName, '_', '-') + strFileExt); GetTrackHtmlInSertCode(tpp.TagTrack, trackPath, "</body>", ref strGenFileContent); strGenResult = OleDbHelper.SetTextFileContent(trackPath, "utf-8", strGenFileContent); if (strGenResult == "0") { FireGeneratorFileFinished(trackPath); } TrackUnit.RemoveUpdateRecord(0, trackPath); } else { string dynTpt = tpp.ParsedResult; PagedObject.SetResourceDependency(aWebChannel); while (PagedObject.CurrentPageIndex <= PagedObject.GetPageCount()) { #region 处理分页内容 realContent = PagedObject.GetCurrentPageContent(); //处理当前页内容 myPageHtml = dynTpt.Replace(PagedContentAlia, realContent); //处理分页导航内容 if (this.PagerDic.Count > 0) { foreach (string pagerKey in PagerDic.Keys) { PagerTag Pager = PagerDic[pagerKey]; Pager.TotalRecordCount = PagedObject.GetTotalRecordCount(); Pager.CurrentPage = PagedObject.CurrentPageIndex; Pager.StartIndex = PagedObject.StartIndex; Pager.EndIndex = PagedObject.EndIndex; Pager.PageSize = PagedObject.PageSize; Pager.DefaultPageFormat = aWebChannel.StaticFileGenDir + strFileName.Replace("{#$CIDX$#}", "{0}") + strFileExt; //Util.Debug(false, Pager.ToString()); myPageHtml = myPageHtml.Replace(pagerKey, Pager.ToString()); //Util.Debug(false, this.PagerDic[pagerKey].OuterDefineText); } } int currentPage = PagedObject.CurrentPageIndex; string currentFileName = strFileName.Replace("{#$CIDX$#}", currentPage.ToString()); strGenFileContent = HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, myPageHtml); //插入Track代码 trackPath = GetSiteRelativeUrl(strGenFilePath + currentFileName + strFileExt); GetTrackHtmlInSertCode(tpp.TagTrack, trackPath, "</body>", ref strGenFileContent); strGenResult = OleDbHelper.SetTextFileContent(trackPath, "utf-8", strGenFileContent); //清除更新请求 TrackUnit.RemoveUpdateRecord(0, trackPath); if (strGenResult == "0") { FireGeneratorFileFinished(trackPath); ShowMessage(string.Format("列表页文件生成成功!<a href=\"{0}\" target=\"_blank\">{0}</a>", trackPath)); } if (currentPage == 1) { trackPath = strGenFilePath + currentFileName.Trim('1', '-', '_') + strFileExt; OleDbHelper.SetTextFileContent(trackPath, "utf-8", strGenFileContent); FireGeneratorFileFinished(trackPath); TrackUnit.RemoveUpdateRecord(0, trackPath); } PagedObject.MoveNextPage(); #endregion } } tpp.Dispose(); } #endregion if (strGenResult == "0") { ShowMessage("列表页内容生成成功完成。"); } } else { ShowMessage("页面模板实体还原失败,请检查配置是否正确!"); } } #endregion } if (options != null && options.GenerateDetailPage == false) { ShowMessage("* 已禁止详细内容页生成!"); } else { #region 详细页面生成 if (tptConfig.GenerateDetailPage == true) { strFileExt = tptConfig.DetailPageTemplet.FileNameConfig.FileExtentionName; PageTemplet pageTpt = (new PageTemplet()).GetInstanceById(tptConfig.DetailPageTemplet.TempletID) as PageTemplet; if (pageTpt != null && pageTpt.IsExist == true && pageTpt.IsFilled == true) { if (pageTpt.IsMixedSyntax == false) { strFileName = tptConfig.DetailPageTemplet.FileNameConfig.FileNameTag.GetTagValue().ToString(); if (!pageTpt.SiteBaseDir.EndsWith("/")) pageTpt.SiteBaseDir += "/"; strGenResult = OleDbHelper.SetTextFileContent(strGenFilePath + strFileName + strFileExt, "utf-8", HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, pageTpt.TempletRawContent)); if (strGenResult == "0") { FireGeneratorFileFinished(strGenFilePath + strFileName + strFileExt); } } else { TempletParse tpp = new TempletParse(); OleDbHelper hp = FanmaquerOleDbModule.GetOleDbInstance(FanmaquarConfig.ConnectionKey); DataTable dTab = hp.GetDataTable(string.Format("select * from Tbl_Articles where Pubed=True and Archived=false and TypeID={0} order by Sort asc,NewsID desc", aWebChannel.ChannelID)); if (dTab != null && dTab.Rows.Count > 0) { for (int i = 0; i < dTab.Rows.Count; i++) { AccessWebNews news = AccessWebNews.LoadFromDataRow(dTab.Rows[i]); tptConfig.DetailPageTemplet.FileNameConfig.FileNameTag.SetResourceDependency(news); strFileName = tptConfig.DetailPageTemplet.FileNameConfig.FileNameTag.GetTagValue().ToString(); MultiResDependency newsRes = new MultiResDependency(aWebChannel, news); tpp.SetResourceDependency(newsRes); tpp.TagTrack = new System.Collections.Generic.Dictionary<string, string>(); tpp.TagTrack.Add("T" + pageTpt.TempletID.ToString(), pageTpt.ModifiedTime.ToString("yyyyMMddHHmmss")); tpp.SetTaggedObjectCollection(pageTpt.TempletRawContent); string newsfileWithFullPath = strGenFilePath + strFileName + strFileExt; if (news.VirtualPath.Length > 5) { newsfileWithFullPath = Util.ParseAppPath(news.VirtualPath); } else { news.VirtualPath = aWebChannel.StaticFileGenDir + strFileName + strFileExt; news.RefreshVirtualPath(); } strGenFileContent = HtmlTextGenerator.GetRightHtmlText(pageTpt.SiteBaseDir, tpp.ParsedResult); //插入Track代码 trackPath = GetSiteRelativeUrl(newsfileWithFullPath); GetTrackHtmlInSertCode(tpp.TagTrack, trackPath, "</body>", ref strGenFileContent); strGenResult = OleDbHelper.SetTextFileContent(newsfileWithFullPath, "utf-8", strGenFileContent); if (strGenResult == "0") { TrackUnit.RemoveUpdateRecord(0, trackPath); FireGeneratorFileFinished(trackPath); ShowMessage(string.Format("内容页文件生成成功!<a href=\"{0}\" target=\"_blank\">{0}</a>", trackPath)); } } } tpp.Dispose(); } if (strGenResult == "0") { ShowMessage("详细页面内容生成成功完成。"); } } else { ShowMessage("页面模板实体还原失败,请检查配置是否正确!"); } } #endregion } } ShowMessage("已完成所有处理,如没有任何消息显示,这可能是该栏目没有内容或配置错误!"); ShowMessage("$end$"); } }
/// <summary> /// 生成网站栏目/频道静态文件 /// </summary> /// <param name="aWebChannel">指定了ChannelID的实体</param> public void Generate(AccessWebChannel aWebChannel) { Generate(aWebChannel, null); }
/// <summary> /// 通过ID初始化实例对象实现 /// </summary> public object GetInstanceById(int InstanceID) { AccessWebChannel aWebChannel = new AccessWebChannel(InstanceID); DataRow dRow = FanmaquerOleDbModule.GetOleDbInstance(FanmaquarConfig.ConnectionKey).GetDataRow(string.Format("select top 1 * from Tbl_Type where TypeID={0}", InstanceID)); if (dRow != null) { aWebChannel.ChannelName = dRow["TypeName"].ToString(); aWebChannel.Sort = Convert.ToInt32(dRow["Sort"]); aWebChannel.IsOuterLink = Convert.ToBoolean(dRow["DisplayByPath"]); aWebChannel.OuterLinkUrl = dRow["OuterLinkUrl"].ToString(); aWebChannel.StaticFileGenDir = dRow["StaticFileDir"].ToString(); aWebChannel.ArchiveDays = Convert.ToInt32(dRow["ArchiveDays"]); aWebChannel.ParentChannel = new AccessWebChannel(Convert.ToInt32(dRow["ParentTypeID"])); aWebChannel.SetDefined("GroupID", dRow["GroupID"].ToString()); #region Templet with file generate rules. string xmlTptRule = dRow["GenTempletRule"].ToString(); if (xmlTptRule.Length > 10) { StringReader sR = new StringReader(xmlTptRule); // OleDbHelper.AppendToFile(true, @"D:\wwwroot\newsign\chinaqmzxco29607\@docs\temp.xml", //"\n\r\n**" + dRow["GenTempletRule"].ToString()); XmlSerializer xSer = new XmlSerializer(typeof(TempletSetting)); aWebChannel.TempletConfig = (TempletSetting)xSer.Deserialize(sR); } #endregion aWebChannel.IsExist = true; } aWebChannel.IsFilled = true; return aWebChannel; }
/// <summary> /// 获取对象键值定义 /// </summary> public object GetDefinition(string x) { AccessWebChannel instance = this; if (this.ChannelID != 0 && this.IsFilled == false) { instance = (AccessWebChannel)this.GetInstance(); } //如果不是标签定义 if (!Regex.IsMatch(x, TagBase.TagDefinitionPattern, RegexOptions.IgnoreCase)) { return(DefinedDic[x]); } #region 数据库实体定义标签 if (Regex.IsMatch(x, @"^\{#%([\w]+)%#\}$", RegexOptions.IgnoreCase | RegexOptions.Compiled)) { object strRet = ""; x = x.Trim('{', '#', '}', '%'); switch (x.ToLower()) { case "typeid": strRet = instance.ChannelID; break; case "typename": strRet = instance.ChannelName; break; case "sort": strRet = instance.Sort; break; case "displaybypath": strRet = instance.IsOuterLink; break; case "staticfiledir": strRet = instance.StaticFileGenDir; break; case "archivedays": strRet = instance.ArchiveDays; break; case "parenttypeid": strRet = instance.ParentChannel.ChannelID; break; default: break; } return(strRet); } #endregion // List-{#$ChannelID$#}.html // 系统标签: {#$this.PrimaryNews["Content"]$#} // -- #region 频道默认新闻 if (x.StartsWith("{#$this.PrimaryNews")) { //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + " by Channel "); IWebNews pNews = instance.GetPrimaryNews(); string[] objStr; //Pattern: \[(\"|\')([\w\-_]+)(\1)\] bool isMatched = Util.GetSingleMatchValue("\\[(\\\"|\\')([\\w\\-_]+)(\\1)\\]", x, out objStr); return((pNews != null && isMatched) ? pNews.GetDefinition("{#%" + objStr[2] + "%#}") : ""); } #endregion #region 级频道定义 if (x.StartsWith("{#$ParentChannel.")) { string key = ""; if (x.StartsWith("{#$ParentChannel.PrimaryNews")) { key = x.Replace("ParentChannel.PrimaryNews", "this.PrimaryNews"); return(instance.ParentChannel.GetDefinition(key)); } key = x.Substring(17).TrimEnd('}', '$', '#'); if (instance.ParentChannel != null) { //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + key); return(instance.ParentChannel.GetDefinition(string.Concat("{#%", key, "%#}"))); } else { return(null); } } #endregion #region 频道自身定义 if (x.StartsWith("{#$Channel.")) { if (x.StartsWith("{#$Channel.ParentChannel.")) { return(GetDefinition("{#$" + x.Substring(11))); } else { return(GetDefinition("{#%" + x.Substring(11).TrimEnd('}', '#', '$') + "%#}")); } } #endregion #region 词典定义 StringBuilder sb = new StringBuilder(x.Length); Regex RE = new Regex(@"\{#\$([\w]+)\$#\}", RegexOptions.IgnoreCase | RegexOptions.Compiled); MatchCollection mc = RE.Matches(x); int idxBegin = 0, idxEnd = 0; foreach (Match m in mc) { idxEnd = m.Index; sb.Append(x.Substring(idxBegin, idxEnd - idxBegin)); //处理标签定义 string key = m.Groups[1].Value; if (DefinedDic.ContainsKey(key)) { sb.Append(DefinedDic[key].ToString()); } else { sb.Append(m.Value); } idxBegin = idxEnd + m.Length; } if (idxBegin < x.Length) { sb.Append(x.Substring(idxBegin)); } //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + "在频道中获取定义:" + x // + System.Environment.NewLine + " = " + sb.ToString()); return(sb.ToString()); #endregion }