CSDN和CnBlogs都不錯,兩個都想用著,所以就寫了這麼一個外掛程式。用途嘛,當然就是把文章發布到多個部落格上。
經常換Blog的或還沒決定用哪一個的朋友也可以用這個,免得遷來遷去~
特 性:在任意一個帳號編輯完文章,點擊“發送”後,將啟動外掛程式,提示使用者選擇帳號與目錄,然後將文章發布到指定的各個帳號。
:https://sourceforge.net/projects/livewriterpost/
總 結:
1、幾個比較常用的命名空間:
WindowsLive.Writer.Api;
WindowsLive.Writer.Passport;
WindowsLive.Writer.BlogClient;
WindowsLive.Writer.BlogClient.Clients;
WindowsLive.Writer.Extensibility.BlogClient;
2、使用WindowsLive.Writer.BlogClient.BlogSettings.GetBlogs函數擷取帳戶的列表,該函數返回一個BlogDescriptor數組。
3、WindowsLive.Writer.BlogClient.Blog對象包含一個帳戶的較完整資訊(包括目錄),使用建構函式建立對象即可。
4、使用BlogSettings.ForBlogId函數擷取指定帳戶的設定資訊。該函數返回一個BlogSettings對象。
5、WindowsLive.Writer.Api.PublishNotificationHook是“發布”操作的介面。
主要代碼:
public override bool OnPrePublish(System.Windows.Forms.IWin32Window dialogOwner, IProperties properties, IPublishingContext publishingContext, bool publish) { bool Result = false; if (Posting) return true; //選擇帳戶 if (DialogBlogSelect.ShowDialog() != System.Windows.Forms.DialogResult.OK) { Posting = false; return false; } //排除當前帳戶 for (int i = 0; i < DialogBlogSelect.SelectedBlogs.Count; i++) { if (DialogBlogSelect.SelectedBlogs[i].ID.ToString() == publishingContext.AccountId) { DialogBlogSelect.SelectedBlogs.RemoveAt(i); Result = true; break; } } //發送到所選擇的帳戶 foreach (AccountItem blog in DialogBlogSelect.SelectedBlogs) { string str; XmlDocument document; BlogSettings settings = BlogSettings.ForBlogId(blog.ID.ToString()); IBlogClient client = BlogClientManager.CreateClient(settings); string postId = client.NewPost(settings.HostBlogId, publishingContext.PostInfo as BlogPost, NullNewCategoryContext.Instance, true, out str, out document); BlogPost post = client.GetPost(settings.HostBlogId, postId); string permalink = post.Permalink; if (!Uri.IsWellFormedUriString(permalink, UriKind.Absolute)) { permalink = new Uri(new Uri(settings.HomepageUrl), new Uri(post.Permalink, UriKind.Relative)).ToString(); } ProcessStartInfo startInfo = new ProcessStartInfo(permalink); startInfo.UseShellExecute = true; Process.Start(startInfo); } Posting = false; return Result; }
其中有關發布的代碼參考了網上某位同學發布的一個外掛程式,是從其dll中Reflector出來的。不過我忘了出處了,Sorry!
趕工趕出來的,想完善的隨便改去好了。
本文即通過此外掛程式發布。