/// <summary> /// 获取标签的最终输出值 /// </summary> public override object GetTagValue() { if (this.IsExist == true) { //OleDbHelper.AppendToFile("~/debug.log", this.Category.ToString() + Environment.NewLine + Environment.NewLine); //OleDbHelper.AppendToFile("~/debug.log", this.OuterDefineText + Environment.NewLine + Environment.NewLine); //OleDbHelper.AppendToFile("~/debug.log", this.Content + Environment.NewLine + Environment.NewLine); if (!ContainTags()) { return(this.GetHtmlOutPut()); } else { TagBase tag = new TagBase(this.Content); if (tag.Category == TagCategory.DataListTag) { ListTag list = ListTag.Parse(tag, this.GetResourceDependency()); if (list.PageSize > 0) { string pagedAliaContent = (string.IsNullOrEmpty(list.IDentity)) ? Guid.NewGuid().ToString() : list.IDentity; SetDynamicPagedAlia(pagedAliaContent, list); return(pagedAliaContent); } else { return(list.GetTagValue()); } } else if (tag.Category == TagCategory.PagerTag) { PagerTag pager = PagerTag.Parse(tag); string pagerAlia = (string.IsNullOrEmpty(pager.IDentity)) ? Guid.NewGuid().ToString() : pager.IDentity; SetDynamicPagerDependency(pagerAlia, pager); return(pagerAlia); } else { //Util.Debug(false, GetResourceDependency()); return(TagBase.InterpretContentWithTags(GetHtmlOutPut(), GetResourceDependency())); } } } else { //OleDbHelper.AppendToFile("~/debug.log", "NULL:" + this.OuterDefineText + Environment.NewLine + Environment.NewLine); return(null); } }
/// <summary> /// 解析模板内容 /// </summary> public void SetTaggedObjectCollection(string tptContent) { StringBuilder sb = new StringBuilder(tptContent.Length); Regex regEx = new Regex(TagBase.TagDefinitionPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); int idxBegin = 0, idxEnd = 0; //Util.Debug(false, "------------------------begin---------------"); MatchCollection mc = regEx.Matches(tptContent, idxBegin); while (mc.Count > 0) { Match m = mc[0]; idxEnd = m.Index; if (idxEnd > idxBegin) { //Util.Debug(false, tptContent.Substring(idxBegin, idxEnd - idxBegin)); sb.Append(tptContent.Substring(idxBegin, idxEnd - idxBegin)); } TagBase tag = new TagBase(m.Value, m.Index, ref tptContent); //Util.Debug(false, "#####\n" + tag.OuterDefineText + " " + tag.Category.ToString() + "\n#####"); //OleDbHelper.AppendToFile("~/debug.log", "parse Tag..." + tag.OuterDefineText + " \r\n " + tag.Category.ToString() + Environment.NewLine + Environment.NewLine); #region 处理标签内容 if (tag.Category == TagCategory.CustomTag) { DbStoredCustomTag dbTag = DbStoredCustomTag.Parse(tag); dbTag.SetResourceDependency(this.GetResourceDependency()); //Util.Debug(false, "tpp: " + this.GetResourceDependency() + dbTag.OuterDefineText); if (dbTag.IsExist == true) { dbTag.Caller = this; sb.Append(dbTag.GetTagValue()); if (!this.TagTrack.ContainsKey("B" + dbTag.IDentity)) { this.TagTrack.Add("B" + dbTag.IDentity, dbTag.PublishDate.ToString("yyyyMMddHHmmss")); } } } else if (tag.Category == TagCategory.DataListTag) { //{#List:Repeater#} ListTag list = ListTag.Parse(tag, this.GetResourceDependency()); //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + " Res:" // + this.GetResourceDependency().ToString()); if (this.GeneratorListContent == true) { #region 直接获取列表标签内容 if (list.GetPageCount() < 2) { sb.Append(list.GetTagValue()); } else { string pagedAliaContent = (string.IsNullOrEmpty(list.IDentity)) ? new Guid().ToString() : list.IDentity; SetDynamicPagedAlia(pagedAliaContent, list); sb.Append(pagedAliaContent); } #endregion } else { //设置列表标签占位符号 string pagedAliaContent = (string.IsNullOrEmpty(list.IDentity)) ? new Guid().ToString() : list.IDentity; SetDynamicPagedAlia(pagedAliaContent, list); sb.Append(pagedAliaContent); } } else if (tag.Category == TagCategory.PagerTag) { //{#Pager#} PagerTag pager = PagerTag.Parse(tag); string pagerAlia = (string.IsNullOrEmpty(pager.IDentity)) ? new Guid().ToString() : pager.IDentity; SetDynamicPagerDependency(pagerAlia, pager); sb.Append(pagerAlia); } else if (tag.Category == TagCategory.ServerTag) { //服务端标签定义格式为 } else if (tag.Category == TagCategory.SystemTag) { //系统标签(函数)定义格式为 {#$ $#} {# ... () ... #} // 系统标签: {#$this.PrimaryNews["Content"]$#} if (tag.OuterDefineText.StartsWith("{#$this.") && this._resDependency != null) { sb.Append(this.GetResourceDependency().GetDefinition(tag.OuterDefineText)); } else { SystemTag sysTag = new SystemTag(tag.TagDefinition); sysTag.SetResourceDependency(GetResourceDependency()); sb.Append(sysTag.ToString()); } //Util.Debug(false, tag.OuterDefineText); //OleDbHelper.AppendToFile("~/log.txt", tag.OuterDefineText); } else if (tag.Category == TagCategory.DefineTag) { //数据库标签定义格式为 {#%FieldName%#} if (this._resDependency != null) { //Util.Debug(false, tag.OuterDefineText); sb.Append(this.GetResourceDependency().GetDefinition(tag.OuterDefineText)); } } #endregion idxBegin = tag.DefinedIndexEnd; //Util.Debug(false, tptContent.Substring(idxBegin, 5)); //Util.Debug(m.Value); mc = regEx.Matches(tptContent, idxBegin); } if (idxBegin < tptContent.Length) { sb.Append(tptContent.Substring(idxBegin)); //Util.Debug(false, tptContent.Substring(idxBegin)); } this.ParsedResult = sb.ToString(); //Util.Debug(false, "------------------------End---------------"); //OleDbHelper.SetTextFileContent(@"~/@docs/temp.html", "utf-8", // HtmlTextGenerator.GetRightHtmlText("/templet/1/", sb.ToString())); }