自從寫完第一個Hello World之後,本來緊接著就打算繼續把PublishNotificationHook放入原來的第一個Hello World之中。
參考網路這篇文章(The New Live Writer SDK)裡面的source code,單純的把code加入之後,就像以下的狀態。
1 using WindowsLive.Writer.Api;
2
3 namespace LiveWriterHelloWorld
4 {
5 [WriterPluginAttribute
6 ("2f437bf1-fe57-41c8-931a-d20066ea174e", "Hello World!2",
7 PublisherUrl = "http://wlwextensionlearning.blogspot.com/",
8 Description = "Going to 2nd testing code")]
9 [InsertableContentSourceAttribute("Hello World!", SidebarText = "Hello World!")]
10 public class HelloWorldPlugin : ContentSource
11 {
12 public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
13 {
14 content = "<b>Hello World!</b>";
15
16 return DialogResult.OK;
17 }
18 }
19 public class PublishNotificationExample : PublishNotificationHook
20 {
21 public override bool OnPrePublish(IWin32Window dialogOwner,
22 IProperties properties, IPublishingContext publishingContext,
23 bool publish)
24 {
25 // Check the post contents to see if liveside appears, if it does, // return true (publish),
26 // if it doesn't, return false (cancel publish)
27 return publishingContext.PostInfo.Contents.ToLower().Contains("liveside");
28 }
29 public override void OnPostPublish(IWin32Window dialogOwner,
30 IProperties properties, IPublishingContext publishingContext,
31 bool publish)
32 {
33 // If this post is a draft (false), don't do anything
34 // if it's an actual publish, then publish = true;
35 if (!publish)
36 return;
37
38 string updateTwitter = string.Format("{0} - {1}",
39 publishingContext.PostInfo.Title,
40 publishingContext.PostInfo.Permalink);
41
42 // Code to update Twitter
43 }
44 }
45 }
編譯完之後,會發現無法收到callback event… 持續探討(The New Live Writer SDK) 的原始碼之後。 發現問題可能出在
1 public class HelloWorldPlugin : ContentSource
2 {
3 public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
4 {
5 content = "<b>Hello World!</b>";
6
7 return DialogResult.OK;
8 }
9 }
10
也就是主要是因為有implement ContentSource 的關係,造成無法收到相關的event。 這個主要原因可能有待詳細查看。當你改好並且把DLL 複製好之後你就會在你的blog 的plugin上面查看到。

以上..