Windows Live Writer plug-in development

Source: Internet
Author: User

A few months ago I saw a video on Channel9. Charles tegou, the Development Manager of Windows Live Writer, told me how to develop the Writer plug-in. Yesterday, I saw Xu xiaozhuo's WebCast. I felt that the content was the same. After reading it, I felt that the food was not good, and I had objections to this classmate in some details. In fact, I have never met Xu xiaozhuo, not to mention the holidays. I just want to summarize and archive the contents of him and Charles, give some entry-level references to other students who want to get involved in Live Writer plug-in development. I hope Xiao Zhuo won't be angry after reading my article. I'm not saying that your code is wrong, but there is something obvious. Since you write code on MSDN WebCast, I think it is still necessary to comply with Microsoft's coding specifications. For example, the local variable declaration should start with lowercase letters, although if you write them up, compilation is not affected. All in all, I do not advocate that the literati are sour, but that they only pursue common progress.

To put it bluntly, there is not much code in this article, but I have put the entire Solution on CodePlex. You can directly go to http://www.codeplex.com/writerplugin#or download all the source code.

Microsoft has released the Windows Live Writer SDK, which consists of three parts:

  • Application API
  • Used to start the Live Writer application and edit existing data types, such as hyperlinks, text, and images;
  • Content Source Plugin API
    • Used to expand the support capability of new data types;
  • Provider Customization API
    • It is used to customize existing functions and add new functions;

This article mainly describes the development practices of Application APIs. I believe that as long as you understand how to use Application APIs to do what you want, the other two APIs will be accessible.

A Brief Introduction to the Application Scenario: Some people may need to insert some text content into Live Writer, and these text content will always go through a fixed process during insertion, like adding a watermark to an image, simple copy and paste operations are not enough. Do we need to develop an independent application for him to process the image? What should I do when I write this article!

First, open Visual Studio 2008 and create a Class Library project. After the project is created, you need to add reference to the dynamic link Library file of the Application API, instead of downloading it on MSDN, after installing Live Writer, you can find this WindowsLive file in the installation directory. writer. api. dll file. If your plug-in needs to open the Windows window, you also need to add references such as System. Windows. Forms.

According to the business needs of our hypothetical scenario, we need a Windows window to receive and process the original text content to be inserted by the user, that is, convert the string to uppercase and add the Autumoon Lab tag. Note that when inserting text content into Live Writer, you should use HTML tags instead of escape characters in C, for example, use "<br/>" instead of "\ n.

How will code work according to our ideas? We first declare a class AutumoonPlugin, inherit the ContentSource class, And reload the CreateContent to implement our own text insertion process:

   1: [WriterPlugin("7c371eef-e350-4aae-af28-91613a9137e3", "Autumoon", PublisherUrl = "http://www.Autumoon.com", Description = "This is an Autumoon Lab plugin.", Name = "Autumoon")]
   2: [InsertableContentSource("iAutumoon", SidebarText = "iAutumoon")]
   3: public class AutumoonPlugin : ContentSource
   4: {
   5:     public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
   6:     {
   7:         new ProcessForm().ShowDialog();
   8:  
   9:         content = ContentProcessor.ProcessedContent;
  10:  
  11:         return (!String.IsNullOrEmpty(content) ? DialogResult.OK : DialogResult.No);
  12:     }
  13: }

You need to add two features to this class: WriterPlugin and InsertableContentSource. And set the attribute value. According to the attribute name, you can understand what it means and I will not repeat it. To emphasize that the first parameter of WriterPlugin is the id value. You can set it by yourself, I just used a Guid value. Don't be confused.

Based on the above lines of code, we can see our process: open a window to accept the user's inserted content; get the processed text from a fixed place, and then use DialogResult. OK to tell Live Writer to insert content. Now I understand why content is ref.

Our insert window is not gorgeous at all, but it is very practical. In addition, we also have a tool class for content processing:

   1: public static void Process(string originalContent)
   2: {
   3:     ProcessedContent = (!String.IsNullOrEmpty(originalContent)
   4:         ? String.Format("<p>{0}<br/>
   5:         : String.Empty);
   6: }

This method simply processes the text to be inserted. As long as you master the development method of the Live Writer plug-in, you can freely use it.

Then we compile the code and copy the compiled dll file to the Plugins folder under the installation directory of Windows Live Writer, run Live Writer and you will see the plug-in we have created in the sidebar.

I sincerely hope that more students will develop more, better, and more powerful Live Writer plug-ins in the next few days and see more, better, and more brilliant technical articles!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.