示例#1
0
        public static async Task SyncPostAsync()
        {
            var sectionBlog = Setting.sectionBlog;
            var blogService = Setting.blogService;

            foreach (var item in sectionBlog.ITIronManArticleURI)
            {
                var lstITposts = ITIronManSyncPostService.GetITIronManPosts(item).Result;
                foreach (var itpost in lstITposts)
                {
                    //檢查有沒有資料,如果有資料更新動作
                    var id   = itpost.link.Replace("https://ithelp.ithome.com.tw/articles/", "");
                    var post = blogService.GetPostById(id).Result ?? new Miniblog.Core.Models.Post()
                    {
                        ID = id
                    };
                    post.Content = $"IT鐵人賽連結:<a href='{itpost.link}'>{itpost.link}</a><hr/>" + itpost.Content;
                    post.Excerpt = $"IT鐵人賽連結:<a href='{itpost.link}'>{itpost.link}</a><hr/>" + HtmlHelper.HtmlInnerText(itpost.Content);
                    var title = itpost.Title;
                    foreach (var replaceString in sectionBlog.ITIronManReplaceString)
                    {
                        title = title.Replace(replaceString, "");
                    }
                    post.Title       = title;
                    post.Categories  = new string[] { itpost.Article };
                    post.IsPublished = true;
                    post.IsMarkDown  = true;
                    post.PubDate     = itpost.PubDate;
                    post.Slug        = id;
                    await blogService.SavePost(post);
                }
                ;
            }
        }
示例#2
0
 private void DoWork(object state)
 {
     if (!ITIronManSyncPostService.SyncPostAsync().GetAwaiter().IsCompleted)
     {
         throw new Exception("Excute failed");
     }
 }
示例#3
0
        public async static Task <IList <Post> > GetITIronManPosts(string url)
        {
            var itironman = new ITIronManSyncPostService();

            itironman._url = url;
            await itironman.ExecuteAsync();

            return(itironman.Posts);
        }