public List<SelectOption> Get() { var items = new List<SelectOption>(); string url = "http://dotnetblogengine.net/syndication.axd"; try { var cnt = 0; var reader = XmlReader.Create(url); var feed = SyndicationFeed.Load(reader); reader.Close(); foreach (SyndicationItem item in feed.Items) { var option = new SelectOption(); option.OptionName = item.Title.Text; option.OptionValue = item.Id; items.Add(option); cnt++; if (cnt > 2) break; } } catch (Exception ex) { BlogEngine.Core.Utils.Log("Dashboard news feed", ex); } return items; }
/// <summary> /// Get page converted to json /// </summary> /// <param name="page">Page</param> /// <returns>Json page</returns> public static PageItem GetPage(Page page) { Page parent = null; SelectOption parentOption = null; if (page.Parent != Guid.Empty) { parent = Page.Pages.FirstOrDefault(p => p.Id.Equals(page.Parent)); parentOption = new SelectOption { IsSelected = false, OptionName = parent.Title, OptionValue = parent.Id.ToString() }; } return new PageItem { Id = page.Id, ShowInList = page.ShowInList, Title = page.Title, Slug = page.Slug, Parent = parentOption, Keywords = page.Keywords, DateCreated = page.DateCreated.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture), HasChildren = page.HasChildPages, IsPublished = page.IsPublished, IsFrontPage = page.IsFrontPage, SortOrder = page.SortOrder, }; }
IEnumerable<SelectOption> GetLogFile() { string fileLocation = HostingEnvironment.MapPath(Path.Combine(BlogConfig.StorageLocation, "logger.txt")); var items = new List<SelectOption>(); if (File.Exists(fileLocation)) { using (var sw = new StreamReader(fileLocation)) { string line; string logItem = ""; int count = 1; while ((line = sw.ReadLine()) != null) { if (line.Contains("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*")) { // new log item if (!string.IsNullOrEmpty(logItem)) { var item = new SelectOption(); item.OptionName = "Line" + count.ToString(); item.OptionValue = logItem; items.Add(item); logItem = ""; count++; } } else { // append line to log item logItem = logItem + line + "<br/>"; } } sw.Close(); return items; } } else { return new List<SelectOption>(); } }
static PageDetail ToJsonDetail(Page page) { Page parent = null; SelectOption parentOption = null; if (page.Parent != Guid.Empty) { parent = Page.Pages.FirstOrDefault(p => p.Id.Equals(page.Parent)); parentOption = new SelectOption { IsSelected = false, OptionName = parent.Title, OptionValue = parent.Id.ToString() }; } return new PageDetail { Id = page.Id, ShowInList = page.ShowInList, Title = page.Title, Slug = page.Slug, RelativeLink = page.RelativeLink, Content = page.Content, Parent = parentOption, Description = page.Description, Keywords = page.Keywords, DateCreated = page.DateCreated.ToString("yyyy-MM-dd HH:mm"), HasChildren = page.HasChildPages, IsPublished = page.IsPublished, IsFrontPage = page.IsFrontPage, IsDeleted = page.IsDeleted }; }