public static void Publish(int PageID, bool IsGenerateCode) { if (IsGenerateCode) { DataTable TagList = TemplateControler.GetTagList(PageID); foreach (DataRow TagRow in TagList.Rows) { string ServerID = TagRow["serverid"].ToString(); int TagID = Convert.ToInt32(TagRow["tagid"]); string TagTitle = TagRow["tagname"].ToString(); TagModel Tag = TagControler.GetModel(TagID); if (Tag.TagType == 2) { string Content = TagControler.GenerateDefaultCode(TagID, null); TagContentModel TagContent = new TagContentModel(); TagContent.PageID = PageID; TagContent.ServerID = ServerID; TagContent.TagID = TagID; TagContent.Content = Content; TagControler.TagContentImport(TagContent); } } } Publish(PageID); }
public static DataTable GetTagList(int PageID) { PageModel page = PageControler.GetModel(PageID); StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath(page.TempatePath), Encoding.UTF8); MatchCollection matches = Regex.Matches(sr.ReadToEnd(), "(?<tag>(<dd:CMSTag.+/>))", RegexOptions.Multiline); sr.Close(); DataTable dt = new DataTable(); DataColumnCollection columns = dt.Columns; columns.Add("serverid", typeof(string)); columns.Add("Description", typeof(string)); columns.Add("TagID", typeof(string)); columns.Add("examplepicture", typeof(string)); columns.Add("ispublic", typeof(bool)); columns.Add("tagname", typeof(string)); foreach (Match match in matches) { if (match.Success) { string reg = "<dd:CMSTag ID=\"(?<serverid>(\\w+))\" Description=\"(?<des>(\\w+))\" TagID=\"(?<tagid>(\\d+))\" "; Match m = Regex.Match(match.Groups[0].Value, reg, RegexOptions.IgnoreCase); if (m.Groups["serverid"].Success && m.Groups["des"].Success && m.Groups["tagid"].Success) { DataRow row = dt.NewRow(); row["serverid"] = m.Groups["serverid"].Value; row["Description"] = m.Groups["des"].Value; row["TagID"] = m.Groups["tagid"].Value; TagModel tag = TagControler.GetModel(Convert.ToInt32(m.Groups["tagid"].Value)); row["examplepicture"] = tag.ExamplePicture; row["ispublic"] = tag.IsPublic; row["tagname"] = tag.TagName; dt.Rows.Add(row); } } } return(dt); }