コード例 #1
0
        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);
        }
コード例 #2
0
        public static void WritePhotoContentListHtml()
        {
            List <object> ContentList()
            {
                var db = Db.Context().Result;

                return(db.PhotoContents.OrderBy(x => x.Title).Cast <object>().ToList());
            }

            var fileInfo = UserSettingsSingleton.CurrentSettings().LocalSitePhotoListFile();

            WriteSearchListHtml(ContentList, fileInfo, "Photos", UserSettingsSingleton.CurrentSettings().PhotoRssUrl());
            RssBuilder.WriteContentCommonListRss(ContentList().Cast <IContentCommon>().ToList(),
                                                 UserSettingsSingleton.CurrentSettings().LocalSitePhotoRssFile(), "Photos");
        }
コード例 #3
0
        public static void WriteAllContentCommonSearchListHtml()
        {
            List <object> ContentList()
            {
                var db           = Db.Context().Result;
                var fileContent  = db.FileContents.Cast <object>().ToList();
                var photoContent = db.PhotoContents.Cast <object>().ToList();
                var imageContent = db.ImageContents.Where(x => x.ShowInSearch).Cast <object>().ToList();
                var postContent  = db.PostContents.Cast <object>().ToList();
                var noteContent  = db.NoteContents.Cast <object>().ToList();

                return(fileContent.Concat(photoContent).Concat(imageContent).Concat(postContent).Concat(noteContent)
                       .OrderBy(x => ((IContentCommon)x).Title).ToList());
            }

            var fileInfo = UserSettingsSingleton.CurrentSettings().LocalSiteAllContentListFile();

            WriteSearchListHtml(ContentList, fileInfo, "All Content",
                                UserSettingsSingleton.CurrentSettings().AllContentRssUrl());
            RssBuilder.WriteContentCommonListRss(ContentList().Cast <IContentCommon>().ToList(),
                                                 UserSettingsSingleton.CurrentSettings().LocalSiteAllContentRssFile(), "All Content");
        }
コード例 #4
0
        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);
        }