private void WebForm1_PreRender(object sender, System.EventArgs e) { Control root = content; string category = Request.QueryString["category"]; if (category != null && category.Length > 0) { category = category.ToUpper(); } else { category = Request.PathInfo.Substring(1).ToUpper(); } CategoryCache cache = new CategoryCache(); cache.Ensure(data); EntryCollection entryList = new EntryCollection(); foreach (CategoryCacheEntry catEntry in cache.Entries) { if (catEntry.Name.ToUpper() == category) { title.Controls.Clear(); title.Controls.Add(new LiteralControl(catEntry.Name)); foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { foreach (DayEntry day in data.Days) { if (day.Date == detail.DayDate) { day.Load(); foreach (Entry entry in day.Entries) { if (entry.EntryId == detail.EntryId) { entryList.Add(entry); } } } } } } } entryList.Sort(new EntrySorter()); foreach (Entry entry in entryList) { EntryView view = (EntryView)LoadControl("EntryView.ascx"); view.DateFormat = "MM/dd/yyyy h:mm tt"; view.Data = data; // UNDONE : perf problem! view.Extra = data.GetDayExtra(entry.Created.Date); view.Entry = entry; root.Controls.Add(view); } }
private void WebForm1_PreRender(object sender, System.EventArgs e) { Control root = blogContent; int entryCount = 0; int dayCount = 0; DateTime start = StartDate; HtmlGenericControl date = null; SiteConfig config = SiteConfig.GetSiteConfig(); categoryList.Data = data; bool needHeader = true; foreach (DayEntry day in data.Days) { if (day.Date <= start) { if (dayCount < 7) { day.Load(); day.Entries.Sort(new EntrySorter()); dayCount++; DayExtra extra = data.GetDayExtra(day.Date); needHeader = true; foreach (Entry entry in day.Entries) { if (needHeader) { date = new HtmlGenericControl("div"); date.Attributes["class"] = "date"; date.ID = day.Date.ToString("yyyy-MM-dd"); HtmlGenericControl dateHeader = new HtmlGenericControl("h2"); dateHeader.Attributes["class"] = "dateHeader"; dateHeader.Controls.Add(new LiteralControl(day.Date.ToString("MMM dd, yyyy"))); date.Controls.Add(dateHeader); root.Controls.Add(date); needHeader = false; } entryCount++; EntryView view = (EntryView)LoadControl("EntryView.ascx"); view.Data = data; view.EntryTitleAsLink = config.EntryTitleAsLink; view.Extra = extra; view.Entry = entry; date.Controls.Add(view); } } } } }
private void Page_Load(object sender, System.EventArgs e) { BlogXUtils.TrackReferrer(Request, Server); EntryIdCache ecache = new EntryIdCache(); ecache.Ensure(data); Control root = content; string entryId = Request.QueryString["guid"]; if (entryId != null && entryId.Length > 0) { entryId = entryId.ToUpper(); } else { entryId = Request.PathInfo.Substring(1).ToUpper(); } DateTime found = new DateTime(); foreach (EntryIdCacheEntry ece in ecache.Entries) { if (ece.EntryId.ToUpper() == entryId) { found = ece.Date; break; } } foreach (DayEntry day in data.Days) { if (day.Date == found) { day.Load(); DayExtra extra = data.GetDayExtra(day.Date); foreach (Entry entry in day.Entries) { if (entryId.ToUpper() == entry.EntryId.ToUpper()) { EntryView view = (EntryView)LoadControl("EntryView.ascx"); view.DateFormat = "MM/dd/yyyy h:mm tt"; view.Data = data; view.Extra = extra; view.Entry = entry; root.Controls.Add(view); break; } } } } }
private void CommentView_PreRender(object sender, System.EventArgs e) { string entryId = (string)ViewState["entryId"]; EntryIdCache ecache = new EntryIdCache(); ecache.Ensure(data); Control root = comments; DateTime found = new DateTime(); foreach (EntryIdCacheEntry ece in ecache.Entries) { if (ece.EntryId.ToUpper() == entryId) { found = ece.Date; entryId = ece.EntryId; break; } } bool obfuscateEmail = SiteConfig.GetSiteConfig().ObfuscateEmail; DayExtra extra = data.GetDayExtra(found); extra.Load(); foreach (DayEntry day in data.Days) { if (day.Date == found) { day.Load(); foreach (Entry entry in day.Entries) { if (entry.EntryId == entryId) { EntryView entryView = (EntryView)LoadControl("EntryView.ascx"); entryView.Data = data; entryView.Entry = entry; entryView.Extra = extra; comments.Controls.Add(entryView); } } } } commentSpamGuard.Visible = SiteConfig.GetSiteConfig().CommentSpamGuard; if (SiteConfig.GetSiteConfig().CommentSpamGuard) { System.Security.Cryptography.RandomNumberGenerator r = System.Security.Cryptography.RandomNumberGenerator.Create(); byte[] randomData = new byte[4]; r.GetBytes(randomData); int code = 0; for (int i = 0; i < randomData.Length; i++) { code += randomData[i]; } code = code % SiteConfig.GetCommentWords().Length; securityWordImage.ImageUrl = BlogXUtils.RelativeToRoot("verifyimagegen.ashx?code=" + code); ViewState["spamCode"] = code; } foreach (Comment c in extra.GetCommentsFor(entryId)) { SingleCommentView view = (SingleCommentView)LoadControl("SingleCommentView.ascx"); view.Comment = c; view.ObfuscateEmail = obfuscateEmail; root.Controls.Add(view); } }