public EntryCollection GetCategoryEntries(string categoryName) { CategoryCache cache = new CategoryCache(); cache.Ensure(data); EntryCollection entryList = new EntryCollection(); foreach (CategoryCacheEntry catEntry in cache.Entries) { if (catEntry.Name.ToUpper() == categoryName) { 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()); return(entryList); }
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); } }
public string[] GetCategoryList() { CategoryCache cache = new CategoryCache(); cache.Ensure(data); string[] cats = new string[cache.Entries.Count]; for (int i = 0; i < cats.Length; i++) { cats[i] = cache.Entries[i].Name; } return(cats); }
private void CategoryList_PreRender(object sender, System.EventArgs e) { CategoryCache cache = new CategoryCache(); cache.Ensure(data); HtmlGenericControl section = new HtmlGenericControl("div"); section.Attributes["class"] = "section"; this.Controls.Add(section); HtmlGenericControl heading = new HtmlGenericControl("h3"); heading.Controls.Add(new LiteralControl("Categories")); section.Controls.Add(heading); HtmlGenericControl list = new HtmlGenericControl("ul"); section.Controls.Add(list); foreach (CategoryCacheEntry catEntry in cache.Entries) { HtmlGenericControl item = new HtmlGenericControl("li"); list.Controls.Add(item); HyperLink catLink = new HyperLink(); catLink.Text = catEntry.Name; catLink.NavigateUrl = BlogXUtils.RelativeToRoot("CategoryView.aspx/" + catEntry.Name); item.Controls.Add(catLink); item.Controls.Add(new LiteralControl(" (")); HyperLink rssLink = new HyperLink(); rssLink.Text = "rss"; rssLink.NavigateUrl = BlogXUtils.RelativeToRoot("BlogXBrowsing.asmx/GetRssCategory?categoryName=" + catEntry.Name); item.Controls.Add(rssLink); item.Controls.Add(new LiteralControl(")")); } }
CategoryCacheEntryCollection IBlogDataService.GetCategories() { CategoryCacheEntryCollection result; CategoryCache cache = new CategoryCache(); cache.Ensure(data); if (Thread.CurrentPrincipal.IsInRole("admin")) { result = cache.Entries; } else { result = new CategoryCacheEntryCollection(); foreach (CategoryCacheEntry category in cache.Entries) { if (category.IsPublic) { result.Add(category); } } } return result; }
// TODO: Consider refactoring to use InternalGetDayEntries that takes delegates. It is slightly more // complicated because this method uses CategoryCache(). EntryCollection IBlogDataService.GetEntriesForCategory(string categoryName, string acceptLanguages) { CategoryCache cache = new CategoryCache(); cache.Ensure(data); EntryCollection entryList = new EntryCollection(); Entry entry; if (cache.UrlSafeCategories.ContainsKey(categoryName)) { categoryName = cache.UrlSafeCategories[categoryName]; } CategoryCacheEntry catEntry = cache.Entries[categoryName]; if (catEntry != null) { foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails) { DayEntry day = data.Days[detail.DayDateUtc]; if (day != null) { Predicate<Entry> entryCriteria = null; if (acceptLanguages != null && acceptLanguages.Length > 0) { entryCriteria += EntryCollectionFilter.DefaultFilters.IsInAcceptedLanguagesOrMultiLingual(acceptLanguages); } day.Load(data); entry = day.GetEntries(entryCriteria)[detail.EntryId]; if (entry != null) { entryList.Add(entry); } } } } entryList.Sort((left, right) => right.CreatedUtc.CompareTo(left.CreatedUtc)); return entryList; }
private EntryCollection BuildEntries(BlogXData data, string category, int maxDayCount) { EntryCollection entryList = new EntryCollection(); if (category != null) { int entryCount = SiteConfig.GetSiteConfig().RssEntryCount; category = category.ToUpper(); CategoryCache cache = new CategoryCache(); cache.Ensure(data); foreach (CategoryCacheEntry catEntry in cache.Entries) { if (catEntry.Name.ToUpper() == category) { 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) { entryCount--; entryList.Add(entry); if (entryCount < 0) { break; } } } } if (entryCount < 0) { break; } } // foreach (DayEntry day if (entryCount < 0) { break; } } // foreach (CategoryCacheEntryDetail } if (entryCount < 0) { break; } } // foreach (CategoryCacheEntry } else { int dayCount = 0; data.Days.Sort(new DaySorter()); foreach (DayEntry day in data.Days) { day.Load(); dayCount++; foreach (Entry entry in day.Entries) { entryList.Add(entry); } if (dayCount >= maxDayCount) { break; } } } entryList.Sort(new EntrySorter()); return(entryList); }
static int Main(string[] args) { Console.WriteLine("Radio Data Importer"); Console.WriteLine(""); foreach (string arg in args) { if (arg.Length > 6 && arg.ToLower().StartsWith("/from:")) { from = arg.Substring(6).Trim(); if (from[0] == '\"' && from[from.Length] == '\"') { from = from.Substring(1, from.Length - 2); } } else if (arg.Length > 4 && arg.ToLower().StartsWith("/to:")) { to = arg.Substring(4).Trim(); if (to[0] == '\"' && to[from.Length] == '\"') { to = to.Substring(1, to.Length - 2); } } else { break; } } if (from == null || to == null || from.Length == 0 || to.Length == 0) { Console.WriteLine("Usage: blogcmd /from:<radio directory> /to:<output directory>"); Console.WriteLine(""); return(-1); } BlogXData.Resolver = new ResolveFileCallback(FileSystemResolver); Console.WriteLine("Importing entries..."); ArrayList tables = new ArrayList(); XmlDocument masterDoc = new XmlDocument(); StringBuilder sb = new StringBuilder(); sb.Append("<tables>"); foreach (FileInfo file in new DirectoryInfo(from).GetFiles("*.xml")) { XmlDocument entry = new XmlDocument(); entry.Load(file.FullName); sb.Append(entry.FirstChild.NextSibling.OuterXml); } sb.Append("</tables>"); masterDoc.Load(new StringReader(sb.ToString())); foreach (XmlNode node in masterDoc.FirstChild) { RadioTable table = new RadioTable(); table.Name = node.Attributes["name"].Value; foreach (XmlNode child in node) { switch (child.Name) { case "date": table.Data[child.Attributes["name"].Value] = DateTime.Parse(child.Attributes["value"].Value); break; case "boolean": table.Data[child.Attributes["name"].Value] = bool.Parse(child.Attributes["value"].Value); break; case "string": table.Data[child.Attributes["name"].Value] = child.Attributes["value"].Value; break; case "table": if (child.Attributes["name"].Value == "categories") { foreach (XmlNode catNode in child) { if (catNode.Name == "boolean" && catNode.Attributes["value"].Value == "true") { if (table.Data.Contains("categories")) { table.Data["categories"] = (string)table.Data["categories"] + ";" + catNode.Attributes["name"].Value; } else { table.Data["categories"] = catNode.Attributes["name"].Value; } } } } break; } } tables.Add(table); } BlogXData data = new BlogXData(); foreach (RadioTable table in tables) { DateTime date = table.When.Date; DayEntry dayEntry = null; foreach (DayEntry target in data.Days) { if (target.Date == date) { dayEntry = target; break; } } if (dayEntry == null) { dayEntry = new DayEntry(); dayEntry.Date = date; data.Days.Add(dayEntry); } Entry entry = new Entry(); entry.Created = table.When; entry.Title = table.Title; entry.Content = table.Text; entry.Categories = table.Categories; entry.EntryId = table.UniqueId; dayEntry.Entries.Add(entry); data.IncrementEntryChange(); } Console.WriteLine("Saving entries..."); foreach (DayEntry day in data.Days) { day.Save(); } Console.WriteLine("Creating comment cache..."); CategoryCache cache = new CategoryCache(); cache.Ensure(data); Console.WriteLine("Creating entry cache..."); EntryIdCache ecache = new EntryIdCache(); ecache.Ensure(data); return(0); }