Esempio n. 1
0
        public override void Layout()
        {
            BlogApp blog = ctx.app.obj as BlogApp;

            if (blog == null)
            {
                throw new NullReferenceException("BlogApp");
            }
            blogService.AddHits(blog);

            set("adminUrl", to(new Admin.MyListController().Index));
            bindAdminLink();


            bindAppInfo(blog);

            load("blog.UserMenu", new Users.ProfileController().UserMenu);

            BlogSetting s = blog.GetSettingsObj();

            List <BlogCategory> categories = categoryService.GetByApp(ctx.app.Id);
            List <BlogPost>     newBlogs   = postService.GetNewBlog(ctx.app.Id, s.NewBlogCount);

            List <OpenComment> comments = commentService.GetByApp(typeof(BlogPost), ctx.app.Id, s.NewCommentCount);

            List <Blogroll> blogrolls = rollService.GetByApp(ctx.app.Id, ctx.owner.obj.Id);

            bindBlogroll(blogrolls);
            bindCategories(categories);
            bindPostList(newBlogs);
            bindComments(comments);
        }
        public async Task SaveBlogMeta(BlogSetting blogSetting, BlogMeta blogMeta)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }
            if (blogMeta == null)
            {
                throw new ArgumentNullException(nameof(blogMeta));
            }

            var existingMeta =
                await
                    this.DbContext.BlogMetas.SingleOrDefaultLocalOrSourceAsync(
                        x => x.BlogKey.Equals(blogSetting.BlogKey, StringComparison.OrdinalIgnoreCase));

            if (existingMeta == null)
            {
                existingMeta = new BlogMeta { BlogKey = blogSetting.BlogKey };
                await this.DbContext.BlogMetas.AddAsync(existingMeta);
            }

            existingMeta.Description = blogMeta.Description;
            existingMeta.Name = blogMeta.Name;
            existingMeta.PublishedAt = blogMeta.PublishedAt;
            existingMeta.SourceId = blogMeta.SourceId;
            existingMeta.UpdatedAt = blogMeta.UpdatedAt;
            existingMeta.Url = blogMeta.Url;

            await this.DbContext.SaveChangesAsync();
        }
        private async Task<IReadOnlyList<BlogPost>> GetSourcePosts(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            IReadOnlyList<BlogPost> sourcePosts;
            try
            {
                sourcePosts = await this.config.BlogSource.GetBlogPosts(blogSetting, lastUpdatedAt);
            }
            catch (Exception ex)
            {
                string message =
                    $"{nameof(this.config.BlogSource)} threw an unexpected excetion from {nameof(this.config.BlogSource.GetBlogPosts)}"
                    + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}': {ex.Message.TrimEnd('.')}.";
                throw new BlogSyncBlogSourceException(message, ex);
            }

            //if (sourcePosts == null)
            //{
            //    string message =
            //        $"{nameof(this.config.BlogSource)} returned a null result from {nameof(this.config.BlogSource.GetBlogPosts)}"
            //        + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}'.";
            //    throw new BlogSyncBlogSourceResultException(message);
            //}

            if (sourcePosts != null)
            {
                sourcePosts = CleanBlogPosts(sourcePosts);
            }

            return sourcePosts;
        }
        private async Task<IReadOnlyList<BlogPostBase>> GetDataStoragePosts(
            BlogSetting blogSetting,
            DateTime? lastUpdatedAt)
        {
            IReadOnlyList<BlogPostBase> dataStoragePosts;
            try
            {
                dataStoragePosts = await this.config.DataStorage.GetBlogPosts(blogSetting, lastUpdatedAt);
            }
            catch (Exception ex)
            {
                string message =
                    $"{nameof(this.config.DataStorage)} threw an unexpected excetion from {nameof(this.config.DataStorage.GetBlogPosts)}"
                    + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}': {ex.Message.TrimEnd('.')}.";
                throw new BlogSyncDataStorageException(message, ex);
            }

            if (dataStoragePosts == null)
            {
                string message =
                    $"{nameof(this.config.DataStorage)} returned a null result from {nameof(this.config.DataStorage.GetBlogPosts)}"
                    + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}'.";
                throw new BlogSyncDataStorageResultException(message);
            }

            return dataStoragePosts;
        }
Esempio n. 5
0
        private static BlogPost GetBlogPost(BloggerPostData post, BlogSetting blogSetting)
        {
            var blogPost = BloggerDataConverter.ConvertPost(post);
            blogPost.BlogKey = blogSetting.BlogKey;

            return blogPost;
        }
Esempio n. 6
0
        public virtual void bindSettings(BlogSetting s)
        {
            Dictionary <String, String> dic = new Dictionary <string, string>();

            String chk = "checked=\"checked\"";

            set("s.AllowComment", s.AllowComment == 1 ? chk : "");
            set("s.AllowAnonymousComment", s.AllowAnonymousComment == 1 ? chk : "");
            set("s.IsShowStats", s.IsShowStats == 1 ? chk : "");

            set("s.PerPageBlogs", dropList("PerPageBlogs", 3, 20, s.PerPageBlogs));
            set("s.StickyCount", dropList("StickyCount", 1, 20, s.StickyCount));

            set("s.NewBlogCount", dropList("NewBlogCount", 3, 20, s.NewBlogCount));
            set("s.NewCommentCount", dropList("NewCommentCount", 3, 20, s.NewCommentCount));
            set("s.RssCount", dropList("RssCount", 5, 20, s.RssCount));

            set("s.ListModeFull", s.ListMode == BlogListMode.Full ? chk : "");
            set("s.ListModeAbstract", s.ListMode == BlogListMode.Abstract ? chk : "");

            String[] options = new String[] {
                "100", "200", "300", "500", "600", "800", "1000", "1200", "1500", "2000", "3000"
            };
            radioList("blogSetting.ListAbstractLength", options, s.ListAbstractLength);
        }
Esempio n. 7
0
        public void Index()
        {
            ctx.Page.Title = lang("blog");

            BlogApp app = ctx.app.obj as BlogApp;

            if (app == null)
            {
                echoError("app不存在");
                return;
            }

            BlogSetting s = app.GetSettingsObj();

            DataPage <BlogPost> results = postService.GetPage(ctx.app.Id, s.PerPageBlogs);

            IBlock block = getBlock("topblog");

            if (ctx.route.page == 1)
            {
                bindTopPosts(s, block);
            }

            bindPosts(results, s);

            set("pager", results.PageBar);
        }
Esempio n. 8
0
        private void bindPostOne(IBlock listBlock, BlogPost post, BlogSetting s)
        {
            String status = string.Empty;

            if (post.IsTop == 1)
            {
                status = "<span class=\"lblTop\">[" + lang("sticky") + "]</span>";
            }
            if (post.IsPick == 1)
            {
                status = status + "<span class=\"lblTop\">[" + lang("picked") + "]</span>";
            }


            listBlock.Set("blogpost.Status", status);
            listBlock.Set("blogpost.Title", post.Title);
            listBlock.Set("blogpost.Url", alink.ToAppData(post));

            String body = s.ListMode == BlogListMode.Full ? post.Content : strUtil.ParseHtml(post.Content, 300);

            listBlock.Set("blogpost.Body", body);


            listBlock.Set("author", ctx.owner.obj.Name);
            listBlock.Set("authroUrl", Link.ToMember(ctx.owner.obj));
            listBlock.Set("blogpost.CreateTime", post.Created.ToShortTimeString());
            listBlock.Set("blogpost.CreateDate", post.Created.ToShortDateString());
            listBlock.Set("blogpost.Hits", post.Hits);
            listBlock.Set("blogpost.ReplyCount", post.Replies);
        }
Esempio n. 9
0
        public async Task SaveBlogMeta(BlogSetting blogSetting, BlogMeta blogMeta)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }
            if (blogMeta == null)
            {
                throw new ArgumentNullException(nameof(blogMeta));
            }

            using (var session = this.DocumentStore.OpenAsyncSession())
            {
                string blogMetaId = RavenDbIdConventions.GetBlogMetaId(blogSetting.BlogKey);

                var existingMeta = await session.LoadAsync<BlogMeta>(blogMetaId);
                if (existingMeta == null)
                {
                    existingMeta = new BlogMeta { BlogKey = blogSetting.BlogKey };
                    await session.StoreAsync(existingMeta);
                }

                existingMeta.Description = blogMeta.Description;
                existingMeta.Name = blogMeta.Name;
                existingMeta.PublishedAt = blogMeta.PublishedAt;
                existingMeta.SourceId = blogMeta.SourceId;
                existingMeta.UpdatedAt = blogMeta.UpdatedAt;
                existingMeta.Url = blogMeta.Url;

                await session.SaveChangesAsync();
            }
        }
Esempio n. 10
0
        public override void Layout()
        {
            BlogApp blog = ctx.app.obj as BlogApp;

            blogService.AddHits(blog);

            set("adminUrl", to(new Admin.MyListController().Index));


            bindAppInfo(blog);

            load("blog.UserMenu", new Users.ProfileController().UserMenu);

            BlogSetting s = blog.GetSettingsObj();

            List <BlogCategory> categories = categoryService.GetByApp(ctx.app.Id);
            List <BlogPost>     newBlogs   = postService.GetNewBlog(ctx.app.Id, s.NewBlogCount);

            //List<BlogPostComment> newComments = commentService.GetNew( ctx.owner.Id, ctx.app.Id, s.NewCommentCount );
            List <BlogPostComment> newComments = BlogPostComment.find("AppId=" + ctx.app.Id).list(s.NewCommentCount);

            List <Blogroll> blogrolls = rollService.GetByApp(ctx.app.Id, ctx.owner.obj.Id);

            bindBlogroll(blogrolls);
            bindCategories(categories);
            bindPostList(newBlogs);
            bindComments(newComments);
        }
Esempio n. 11
0
        public BlogSetting AddBlog()
        {
            var blog = new BlogSetting {
                BlogName = "New", Language = "HTML"
            };

            blog.BeginEdit();

            var blogSettings = blogSettingsCreator();

            blogSettings.InitializeBlog(blog);

            var result = windowManager.ShowDialog(blogSettings);

            if (result != true)
            {
                blog.CancelEdit();
                return(null);
            }

            blog.EndEdit();
            var blogs = GetBlogs();

            blogs.Add(blog);
            SaveBlogs(blogs);

            return(blog);
        }
Esempio n. 12
0
        public bool EditBlog(BlogSetting currentBlog)
        {
            var blogs        = GetBlogs();
            var blogToUpdate = blogs.SingleOrDefault(b => SameBlog(currentBlog, b));

            currentBlog.BeginEdit();

            var blogSettings = blogSettingsCreator();

            blogSettings.InitializeBlog(currentBlog);

            var result = windowManager.ShowDialog(blogSettings);

            if (result != true)
            {
                currentBlog.CancelEdit();
                return(false);
            }

            var index = blogs.IndexOf(blogToUpdate);

            blogs[index] = currentBlog;

            currentBlog.EndEdit();
            SaveBlogs(blogs);
            return(true);
        }
        public async Task<BlogMeta> Update(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            BlogMeta meta;
            try
            {
                meta = await this.config.BlogSource.GetMeta(blogSetting, lastUpdatedAt);
            }
            catch (Exception ex)
            {
                string message =
                    $"{nameof(this.config.BlogSource)} threw an unexpected excetion from {nameof(this.config.BlogSource.GetMeta)}"
                    + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}': {ex.Message.TrimEnd('.')}.";
                throw new BlogSyncBlogSourceException(message, ex);
            }

            //if (meta == null)
            //{
            //    string message =
            //        $"{nameof(this.config.BlogSource)} returned a null result from {nameof(this.config.BlogSource.GetMeta)}"
            //        + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}'.";
            //    throw new BlogSyncBlogSourceResultException(message);
            //}

            return meta;
        }
Esempio n. 14
0
 protected WebSiteContext(BlogSetting blog, IWebDocumentService webDocumentService, IEventAggregator eventAggregator)
 {
     this.blog = blog;
     this.webDocumentService = webDocumentService;
     this.eventAggregator    = eventAggregator;
     workingDirectory        = Path.Combine(Path.GetTempPath(), blog.BlogName);
 }
Esempio n. 15
0
 public GithubSiteContext(BlogSetting blog,
                          IWebDocumentService webDocumentService,
                          IGithubApi github,
                          IEventAggregator eventAggregator) :
     base(blog, webDocumentService, eventAggregator)
 {
     this.github = github;
 }
Esempio n. 16
0
 public MetaWeblogSiteContext(
     BlogSetting blog,
     Func <string, IMetaWeblogService> getMetaWeblog,
     IWebDocumentService webDocumentService,
     IEventAggregator eventAggregator) : base(blog, webDocumentService, eventAggregator)
 {
     this.getMetaWeblog = getMetaWeblog;
 }
Esempio n. 17
0
        public async Task <IMarkpadDocument> OpenBlogPost(BlogSetting blog, string id, string name)
        {
            var metaWeblogSiteContext = siteContextGenerator.GetWebContext(blog);

            var content = await webDocumentService.Value.GetDocumentContent(blog, id);

            return(new WebDocument(blog, id, name, content, new FileReference[0], this, webDocumentService.Value, metaWeblogSiteContext, fileSystem));
        }
Esempio n. 18
0
        public Task<BlogMeta> GetMeta(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            var blogMeta = this.blogMetas.SingleOrDefault(x => x.BlogKey == blogSetting.BlogKey);

            this.OnGetaMetaRun?.Invoke(this, blogSetting.BlogKey);

            return Task.FromResult(blogMeta);
        }
Esempio n. 19
0
        public void Remove(BlogSetting currentBlog)
        {
            var blogs        = GetBlogs();
            var blogToRemove = blogs.SingleOrDefault(b => SameBlog(currentBlog, b));

            blogs.Remove(blogToRemove);
            SaveBlogs(blogs);
        }
Esempio n. 20
0
        public Task<DateTime?> GetLastUpdatedAt(BlogSetting blogSetting)
        {
            var lastUpdatedAt = this.blogPosts.Select(x => x.UpdatedAt).OrderByDescending(x => x).FirstOrDefault();

            this.OnGetLastUpdatedAtRun?.Invoke(this, blogSetting.BlogKey);

            return Task.FromResult(lastUpdatedAt);
        }
Esempio n. 21
0
        // GET: Blog
        public ViewResult Index()
        {
            ViewBag.Title = "صفحه اخبار";
            var blogsetting = new BlogSetting();

            blogsetting.title = "اخبار";
            blogsetting.text  = "   اطلاعاتی درباره پوشاک <b> " + DateTime.Now.ToShortTimeString() + "<b/>";
            return(View(model: blogsetting));
        }
Esempio n. 22
0
        private void bindPosts(DataPage <BlogPost> results, BlogSetting s)
        {
            IBlock listBlock = getBlock("bloglist");

            foreach (BlogPost post in results.Results)
            {
                bindPostOne(listBlock, post, s);
                listBlock.Next();
            }
        }
Esempio n. 23
0
        private void bindTopPosts(BlogSetting s, IBlock block)
        {
            List <BlogPost> top = postService.GetTop(ctx.app.Id, s.StickyCount);

            foreach (BlogPost post in top)
            {
                bindPostOne(block, post, s);
                block.Next();
            }
        }
Esempio n. 24
0
        public Task<IReadOnlyList<BlogPost>> GetBlogPosts(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            var posts =
                this.blogPosts.Where(
                        x => x.BlogKey == blogSetting.BlogKey && (lastUpdatedAt == null || x.UpdatedAt > lastUpdatedAt))
                    .ToReadOnlyList();

            this.OnGetBlogPostsRun?.Invoke(this, blogSetting.BlogKey);

            return Task.FromResult(posts);
        }
Esempio n. 25
0
        public async Task <IMarkpadDocument> OpenBlogPost(BlogSetting blog, string id, string name)
        {
            var metaWeblogSiteContext = siteContextGenerator.GetWebContext(blog);

            var content = await webDocumentService.Value.GetDocumentContent(blog, id);

            var webMarkdownFile = new WebDocument(blog, id, name, content, this,
                                                  webDocumentService.Value, metaWeblogSiteContext);

            return(webMarkdownFile);
        }
Esempio n. 26
0
 public WebDocumentItem(
     IWebDocumentService webDocumentService,
     IEventAggregator eventAggregator,
     string id,
     string title,
     BlogSetting blog) :
     base(eventAggregator)
 {
     this.webDocumentService = webDocumentService;
     this.id   = id;
     this.blog = blog;
     Name      = title;
 }
        public WebSiteContext GetWebContext(BlogSetting blog)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                return(new MetaWeblogSiteContext(blog, getMetaWeblog, webDocumentService, eventAggregator));
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return(new GithubSiteContext(blog, webDocumentService, github, eventAggregator));
            }

            return(null);
        }
Esempio n. 28
0
        public static IEnumerable<BlogSetting> CreateCollection()
        {
            var setting = new BlogSetting(BlogMetaTestData.BlogKey, BlogSettingsId, BlogSettingsName);
            yield return setting;

            var setting1 = new BlogSetting(BlogMetaTestData.BlogKey1, BlogSettingsId1, BlogSettingsName1);
            yield return setting1;

            var setting2 = new BlogSetting(BlogMetaTestData.BlogKey2, BlogSettingsId2, BlogSettingsName2);
            yield return setting2;

            var setting3 = new BlogSetting(BlogMetaTestData.BlogKey3, BlogSettingsId3, BlogSettingsName3);
            yield return setting3;
        }
Esempio n. 29
0
        /// <summary>
        /// 列出相应发表日期的文章
        /// </summary>
        /// <param name="id"></param>
        public void List(int id)
        {
            BlogApp     app = ctx.app.obj as BlogApp;
            BlogSetting s   = app.GetSettingsObj();

            DataPage <BlogPost> list = postService.GetPageByCreatedCate(ctx.app.Id, id, s.PerPageBlogs);

            //bindCategory("list", "post", blogs, bindLink);

            //bindCategory( category );
            bindPostList(list);

            set("pager", list.PageBar);
        }
Esempio n. 30
0
        public virtual void Save()
        {
            BlogSetting s = ctx.PostValue <BlogSetting>();

            s.AllowComment          = ctx.PostIsCheck("blogSetting.AllowComment");
            s.AllowAnonymousComment = ctx.PostIsCheck("blogSetting.AllowAnonymousComment");
            s.IsShowStats           = ctx.PostIsCheck("blogSetting.IsShowStats");

            BlogApp app = ctx.app.obj as BlogApp;

            app.Settings = Json.ToString(s);
            app.update();

            echoRedirect(lang("opok"));
        }
Esempio n. 31
0
        public async Task DeleteDocument(BlogSetting blog, Post post)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                await getMetaWeblog(blog.WebAPI).DeletePostAsync((string)post.postid, blog);

                return;
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return;
            }

            throw new ArgumentException(string.Format("Unsupported WebSourceType ({0})", blog.WebSourceType));
        }
        public async Task<DateTime?> GetLastUpdatedAt(BlogSetting blogSetting)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            var lastPost =
                await
                    this.DbContext.BlogPosts.OrderByDescending(x => x.UpdatedAt)
                        .FirstOrDefaultAsync(
                            x => x.BlogKey.Equals(blogSetting.BlogKey, StringComparison.OrdinalIgnoreCase));

            return lastPost?.UpdatedAt;
        }
Esempio n. 33
0
        public async Task <string> GetDocumentContent(BlogSetting blog, string id)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                var post = await getMetaWeblog(blog.WebAPI).GetPostAsync(id, blog);

                return(post.description);
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return(await githubApi.FetchFileContents(blog.Token, blog.Username, blog.WebAPI, id));
            }

            throw BadWebSourceTypeException(blog);
        }
Esempio n. 34
0
 public WebDocument(
     BlogSetting blog,
     string id,
     string title,
     string content,
     IDocumentFactory documentFactory,
     IWebDocumentService webDocumentService,
     WebSiteContext siteContext) :
     base(title, content, blog.BlogName, documentFactory)
 {
     Id        = id;
     this.blog = blog;
     this.webDocumentService = webDocumentService;
     this.siteContext        = siteContext;
 }
Esempio n. 35
0
 public WebDocument(
     BlogSetting blog,
     string id,
     string title,
     string content,
     IEnumerable <FileReference> associatedFiles,
     IDocumentFactory documentFactory,
     IWebDocumentService webDocumentService,
     WebSiteContext siteContext,
     IFileSystem fileSystem) :
     base(title, content, blog.BlogName, associatedFiles, documentFactory, siteContext, fileSystem)
 {
     Id        = id;
     this.blog = blog;
     this.webDocumentService = webDocumentService;
 }
        public async Task<BlogSyncPostsChangeSet> Update(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            var sourcePosts = await this.GetSourcePosts(blogSetting, lastUpdatedAt);
            if (sourcePosts == null)
            {
                return null;
            }

            var dataStoragePosts = await this.GetDataStoragePosts(blogSetting, lastUpdatedAt);

            var changeSet = BlogSyncPostsChangeSetHelper.GetChangeSet(blogSetting.BlogKey, sourcePosts, dataStoragePosts);

            this.HandleChanges(blogSetting.BlogKey, changeSet);

            return changeSet;
        }
Esempio n. 37
0
        public void Rss()
        {
            BlogApp     app = ctx.app.obj as BlogApp;
            BlogSetting s   = app.GetSettingsObj();

            RssChannel c = postService.GetRssByAppId(ctx.app.Id, s.RssCount);

            c.Generator = ctx.url.SiteUrl;

            c.Link = strUtil.Join(ctx.url.SiteUrl, c.Link);
            foreach (RssItem i in c.RssItems)
            {
                i.Link = strUtil.Join(ctx.url.SiteUrl, i.Link);
            }

            ctx.RenderXml(c.GetRenderContent());
        }
Esempio n. 38
0
        private void bindPostOne(IBlock listBlock, BlogPost post, BlogSetting s)
        {
            String status = string.Empty;

            if (post.IsTop == 1)
            {
                status = "<span class=\"lblTop\">[" + lang("sticky") + "]</span>";
            }
            if (post.IsPick == 1)
            {
                status = status + "<span class=\"lblTop\">[" + lang("picked") + "]</span>";
            }
            if (post.AttachmentCount > 0)
            {
                status = status + string.Format("<span><img src=\"{0}\"/></span>", strUtil.Join(sys.Path.Img, "attachment.gif"));
            }

            String postLink = alink.ToAppData(post);

            listBlock.Set("blogpost.Status", status);
            listBlock.Set("blogpost.Title", post.Title);
            listBlock.Set("blogpost.Url", postLink);

            String body = s.ListMode == BlogListMode.Full ? post.Content : strUtil.ParseHtml(post.Content, s.ListAbstractLength);

            listBlock.Set("blogpost.Body", body);
            listBlock.Set("author", ctx.owner.obj.Name);
            listBlock.Set("authroUrl", Link.ToMember(ctx.owner.obj));
            listBlock.Set("blogpost.CreateTime", post.Created.ToShortTimeString());
            listBlock.Set("blogpost.CreateDate", post.Created.ToShortDateString());
            listBlock.Set("blogpost.Hits", post.Hits);

            String replies = post.Replies > 0 ?
                             string.Format("<a href=\"{0}\">{1}(<span class=\"blogItemReviews\">{2}</span>)</a>", postLink + "#comments", lang("comment"), post.Replies) :
                             string.Format("<a href=\"{0}\">发表评论</a>", postLink + "#comments");

            listBlock.Set("blogpost.ReplyCount", replies);


            listBlock.Set("blogpost.CategoryName", post.Category.Name);
            listBlock.Set("blogpost.CategoryLink", to(new CategoryController().Show, post.Category.Id));

            String tags = post.Tag.List.Count > 0 ? "tag:" + post.Tag.HtmlString : "";

            listBlock.Set("blogpost.TagList", tags);
        }
        public async Task<IReadOnlyList<BlogPostBase>> GetBlogPosts(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            var posts =
                await
                    this.DbContext.BlogPosts.Where(
                            x =>
                                x.BlogKey.Equals(blogSetting.BlogKey, StringComparison.OrdinalIgnoreCase)
                                && (lastUpdatedAt == null || x.UpdatedAt > lastUpdatedAt))
                        .OrderByDescending(x => x.PublishedAt)
                        .ToListAsync();

            return posts.ToReadOnlyList();
        }
Esempio n. 40
0
        public async Task<IReadOnlyList<BlogPost>> GetBlogPosts(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            var posts = await this.apiProvider.GetPosts(blogSetting.Id, lastUpdatedAt);
            if (posts == null)
            {
                string message =
                    $"{nameof(IBloggerApiProvider)} returned a null result from {nameof(this.apiProvider.GetPosts)}"
                    + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}'.";
                throw new BloggerBlogSourceException(message);
            }

            var blogPosts = posts.Where(x => x != null).Select(x => GetBlogPost(x, blogSetting)).ToReadOnlyList();
            return blogPosts;
        }
Esempio n. 41
0
        public void bindSettings(BlogSetting s)
        {
            Dictionary <String, String> dic = new Dictionary <string, string>();

            String chk = "checked=\"checked\"";

            set("s.AllowComment", s.AllowComment == 1 ? chk : "");
            set("s.AllowAnonymousComment", s.AllowAnonymousComment == 1 ? chk : "");
            set("s.IsShowStats", s.IsShowStats == 1 ? chk : "");

            set("s.PerPageBlogs", dropList("PerPageBlogs", 3, 20, s.PerPageBlogs));
            set("s.StickyCount", dropList("StickyCount", 1, 20, s.StickyCount));

            set("s.NewBlogCount", dropList("NewBlogCount", 3, 20, s.NewBlogCount));
            set("s.NewCommentCount", dropList("NewCommentCount", 3, 20, s.NewCommentCount));
            set("s.RssCount", dropList("RssCount", 5, 20, s.RssCount));

            set("s.ListModeFull", s.ListMode == BlogListMode.Full ? chk : "");
            set("s.ListModeAbstract", s.ListMode == BlogListMode.Abstract ? chk : "");
        }
Esempio n. 42
0
        public async Task<DateTime?> GetLastUpdatedAt(BlogSetting blogSetting)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            using (var session = this.DocumentStore.OpenAsyncSession())
            {
                var lastPost =
                    await
                        session.Query<BlogPostHead, BlogPostsIndex>()
                            .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                            .Where(x => x.BlogKey == blogSetting.BlogKey)
                            .OrderByDescending(x => x.UpdatedAt)
                            .FirstOrDefaultAsync();

                return lastPost?.UpdatedAt;
            }
        }
Esempio n. 43
0
        public Task <SaveResult> SaveDocument(BlogSetting blog, WebDocument document)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                return(TaskEx.Run(() =>
                {
                    var categories = document.Categories.ToArray();
                    return CreateOrUpdateMetaWebLogPost(document, categories, blog);
                }));
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return(CreateOrUpdateGithubPost(document.Title, document.MarkdownContent, document.AssociatedFiles, blog));
            }

            return(TaskEx.Run(new Func <SaveResult>(() =>
            {
                throw BadWebSourceTypeException(blog);
            })));
        }
Esempio n. 44
0
        public Task <string> SaveDocument(BlogSetting blog, WebDocument document)
        {
            if (blog.WebSourceType == WebSourceType.MetaWebLog)
            {
                return(TaskEx.Run(() =>
                {
                    var categories = document.Categories.ToArray();
                    return CreateOrUpdateMetaWebLogPost(document.Id, document.Title, categories, document.MarkdownContent,
                                                        document.ImagesToSaveOnPublish, blog);
                }));
            }
            if (blog.WebSourceType == WebSourceType.GitHub)
            {
                return(CreateOrUpdateGithubPost(document.Title, document.MarkdownContent, document.ImagesToSaveOnPublish, blog));
            }

            return(TaskEx.Run(new Func <string>(() =>
            {
                throw BadWebSourceTypeException(blog);
            })));
        }
Esempio n. 45
0
        public void Show(int id)
        {
            BlogCategory category = categoryService.GetById(id, ctx.owner.Id);

            if (category == null)
            {
                echoRedirect(lang("exDataNotFound"));
                return;
            }

            BlogApp     app = ctx.app.obj as BlogApp;
            BlogSetting s   = app.GetSettingsObj();


            DataPage <BlogPost> list = postService.GetPageByCategory(ctx.app.Id, id, s.PerPageBlogs);

            bindCategory(category);
            bindPostList(list);

            set("pager", list.PageBar);
        }
Esempio n. 46
0
        public async Task<BlogMeta> GetMeta(BlogSetting blogSetting, DateTime? lastUpdatedAt)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            var blog = await this.apiProvider.GetBlog(blogSetting.Id);
            if (blog == null)
            {
                string message =
                    $"{nameof(BloggerApiProvider)} returned a null result from {nameof(this.apiProvider.GetBlog)}"
                    + $" for {nameof(blogSetting.BlogKey)} '{blogSetting.BlogKey}'.";
                throw new BloggerBlogSourceException(message);
            }

            var blogMeta = BloggerDataConverter.ConvertMeta(blog);
            blogMeta.BlogKey = blogSetting.BlogKey;

            return blogMeta;
        }
Esempio n. 47
0
        public async Task<IReadOnlyList<BlogPostBase>> GetBlogPosts(
            BlogSetting blogSetting,
            DateTime? lastUpdatedAt = null)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }

            using (var session = this.DocumentStore.OpenAsyncSession())
            {
                var posts =
                    await
                        session.Query<BlogPostHead, BlogPostsIndex>()
                            .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                            .Where(x => x.BlogKey == blogSetting.BlogKey && x.UpdatedAt > lastUpdatedAt)
                            .OrderByDescending(x => x.PublishedAt)
                            .ProjectFromIndexFieldsInto<BlogPostBase>()
                            .ToListAllAsync();

                return posts.ToReadOnlyList();
            }
        }
Esempio n. 48
0
        public BlogSetting AddBlog()
        {
            var blog = new BlogSetting { BlogName = "New", Language = "HTML" };

            blog.BeginEdit();

            var blogSettings = blogSettingsCreator();
            blogSettings.InitializeBlog(blog);

            var result = windowManager.ShowDialog(blogSettings);
            if (result != true)
            {
                blog.CancelEdit();
                return null;
            }

            blog.EndEdit();
            var blogs = GetBlogs();
            blogs.Add(blog);
            SaveBlogs(blogs);

            return blog;
        }
        public bool EditBlog(BlogSetting currentBlog)
        {
            var blogs = GetBlogs();
            var blogToUpdate = blogs.SingleOrDefault(b => SameBlog(currentBlog, b));
            currentBlog.BeginEdit();

            var blogSettings = blogSettingsCreator();
            blogSettings.InitializeBlog(currentBlog);

            var result = windowManager.ShowDialog(blogSettings);

            if (result != true)
            {
                currentBlog.CancelEdit();
                return false;
            }

            var index = blogs.IndexOf(blogToUpdate);
            blogs[index] = currentBlog;

            currentBlog.EndEdit();
            SaveBlogs(blogs);
            return true;
        }
Esempio n. 50
0
        public Task SaveChanges(BlogSetting blogSetting, BlogSyncPostsChangeSet changeSet)
        {
            this.OnSaveChangesRun?.Invoke(this, blogSetting.BlogKey);

            return Task.CompletedTask;
        }
Esempio n. 51
0
        public async Task SaveChanges(BlogSetting blogSetting, BlogSyncPostsChangeSet changeSet)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }
            if (changeSet == null)
            {
                throw new ArgumentNullException(nameof(changeSet));
            }

            using (var session = this.DocumentStore.OpenAsyncSession())
            {
                session.Advanced.MaxNumberOfRequestsPerSession = int.MaxValue;

                await DeletedPosts(session, changeSet.DeletedBlogPosts);
                await InsertOrUpdatePosts(session, changeSet.InsertedBlogPosts);
                await InsertOrUpdatePosts(session, changeSet.UpdatedBlogPosts);

                await session.SaveChangesAsync();
            }
        }
 public void InitializeBlog(BlogSetting blog)
 {
     CurrentBlog = blog;
 }
        public async Task SaveChanges(BlogSetting blogSetting, BlogSyncPostsChangeSet changeSet)
        {
            if (blogSetting == null)
            {
                throw new ArgumentNullException(nameof(blogSetting));
            }
            if (changeSet == null)
            {
                throw new ArgumentNullException(nameof(changeSet));
            }

            await this.DeletedPosts(changeSet.DeletedBlogPosts);
            await this.InsertOrUpdatePosts(changeSet.InsertedBlogPosts);
            await this.InsertOrUpdatePosts(changeSet.UpdatedBlogPosts);

            await this.DbContext.SaveChangesAsync();
        }
Esempio n. 54
0
        private async Task UpdateBlogData(BlogSetting blogSetting, DateTime? lastUpdatedAt, BlogSyncResult result)
        {
            var updateMetaTask = this.metaHelper.Update(blogSetting, lastUpdatedAt);
            var updatePostsTask = this.postsHelper.Update(blogSetting, lastUpdatedAt);

            await Task.WhenAll(updateMetaTask, updatePostsTask);

            var meta = updateMetaTask.Result;
            var changeSet = updatePostsTask.Result;

            result.OnDataUpdated(meta, changeSet);

            var saveBlogMetaTask = (meta != null)
                                       ? this.Config.DataStorage.SaveBlogMeta(blogSetting, meta)
                                       : Task.CompletedTask;
            var saveChangesTask = (changeSet != null)
                                      ? this.Config.DataStorage.SaveChanges(blogSetting, changeSet)
                                      : Task.CompletedTask;

            await Task.WhenAll(saveBlogMetaTask, saveChangesTask);
        }
Esempio n. 55
0
 static bool SameBlog(BlogSetting b1, BlogSetting b2)
 {
     return b2.BlogInfo.blogName == b1.BlogInfo.blogName && b2.BlogInfo.blogid == b1.BlogInfo.blogid;
 }
Esempio n. 56
0
        public void Remove(BlogSetting currentBlog)
        {
            var blogs = GetBlogs();
            var blogToRemove = blogs.SingleOrDefault(b => SameBlog(currentBlog, b));

            blogs.Remove(blogToRemove);
            SaveBlogs(blogs);
        }
Esempio n. 57
0
        private static BlogSetting GetTestBlogSetting()
        {
            string blogId = AppSettingsHelper.GetBlogId();

            var settings = new BlogSetting(string.Empty, blogId, string.Empty);
            return settings;
        }
Esempio n. 58
0
        public Task SaveBlogMeta(BlogSetting blogSetting, BlogMeta blogMeta)
        {
            this.OnSaveBlogMetaRun?.Invoke(this, blogSetting.BlogKey);

            return Task.CompletedTask;
        }
Esempio n. 59
0
 private static BlogSetting GetTestBlogSetting()
 {
     var blogSettings = new BlogSetting(BlogMetaTestData.BlogKey, TestBlogId, TestBlogName);
     return blogSettings;
 }