private static void WriteContentListRss() { var settings = UserSettingsSingleton.CurrentSettings(); var db = Db.Context().Result; var content = db.LinkStreams.Where(x => x.ShowInLinkRss).OrderByDescending(x => x.CreatedOn).ToList(); var feed = new SyndicationFeed(settings.SiteName, $"{settings.SiteSummary} - Links", new Uri($"https://{settings.SiteUrl}"), $"https:{settings.LinkRssUrl()}", DateTime.Now) { Copyright = new TextSyndicationContent($"{DateTime.Now.Year} {settings.SiteAuthors}") }; var items = new List <string>(); foreach (var loopContent in content) { var linkParts = new List <string>(); if (!string.IsNullOrWhiteSpace(loopContent.Site)) { linkParts.Add(loopContent.Site); } if (!string.IsNullOrWhiteSpace(loopContent.Author)) { linkParts.Add(loopContent.Author); } if (loopContent.LinkDate != null) { linkParts.Add(loopContent.LinkDate.Value.ToString("M/d/yyyy")); } if (!string.IsNullOrWhiteSpace(loopContent.Description)) { linkParts.Add(loopContent.Description); } if (!string.IsNullOrWhiteSpace(loopContent.Comments)) { linkParts.Add(loopContent.Comments); } items.Add(RssBuilder.RssItemString(loopContent.Title, loopContent.Url, string.Join(" - ", linkParts), loopContent.CreatedOn, loopContent.ContentId.ToString())); } var localIndexFile = settings.LocalSiteLinkRssFile(); if (localIndexFile.Exists) { localIndexFile.Delete(); localIndexFile.Refresh(); } File.WriteAllText(localIndexFile.FullName, RssBuilder.RssFileString($"{UserSettingsSingleton.CurrentSettings().SiteName} - Link List", string.Join(Environment.NewLine, items)), Encoding.UTF8); }
public void WriteRss() { var items = new List <string>(); foreach (var loopPosts in IndexContent) { if (loopPosts.GetType() == typeof(PostContent)) { var post = new SinglePostDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(NoteContent)) { var post = new SingleNoteDiv(loopPosts); var content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(PhotoContent)) { var post = new SinglePostDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } } if (loopPosts.GetType() == typeof(ImageContent)) { var post = new SingleImageDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(FileContent)) { var post = new SingleFileDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } } var localIndexFile = UserSettingsSingleton.CurrentSettings().LocalSiteRssIndexFeedListFile(); if (localIndexFile.Exists) { localIndexFile.Delete(); localIndexFile.Refresh(); } File.WriteAllText(localIndexFile.FullName, RssBuilder.RssFileString($"{UserSettingsSingleton.CurrentSettings().SiteName}", string.Join(Environment.NewLine, items)), Encoding.UTF8); }