Header/Footer Source Plugins
Header/footer source plugins enhance Windows Live Writer by inserting headers or footers during either publishing or posting of a draft. Headers and footers are not directly editable by users of Writer and do not appear in the editing views in Writer, but are visible in the Preview view (and, of course, on the published blog post).
You can create a header/footer source plugin for Windows Live Writer by following these steps:.
Follow the steps in Creating a Plugin, using HeaderFooterSource Class as the base class for your plugin.
Decide whether your plugin requires a post to have a permanent URL (permalink) to work properly. If it does, override the HeaderFooterSource.RequiresPermalink Property and return true.
Override the HeaderFooterSource.GeneratePreviewHtml Method and HeaderFooterSource.GeneratePublishHtml Method to customize the behavior of your plugin.
Some plugins require the permalink of the post that is being published. Permalinks don’t exist until a post is published, but the HTML that is generated by the plugin must be included in the published post. Therefore, when a new post is published and there is at least one active header/footer source that requires a permalink, the post is actually published twice and the header/footer sources are invoked in between the two publishing actions.
A header/footer source can indicate that it requires permalinks by overriding the HeaderFooterSource.RequiresPermalink Property and returning true. The default is false.
Overriding GeneratePreviewHtml and GeneratePublishHtml
The string values that you return from HeaderFooterSource.GeneratePreviewHtml Method and HeaderFooterSource.GeneratePublishHtml Method are wrapped in an HTML DIV element and inserted above or below the rest of your body content. The position is determined by the value you set for the position out parameter.
You can control the alignment and margin of the wrapper DIV by modifying values in the smart content parameter’s ISmartContent.Layout Property. You can also use ISmartContent.Properties Property and ISmartContent.Files Property on the smart content object; they work for header/footer sources just like they do for smart content sources.
Header/footer sources can provide HTML for previewing that is different from what they provide for publishing. Windows Live Writer users expect previews to load quickly, so in your implementation of the HeaderFooterSource.GeneratePreviewHtml Method, make every effort to avoid performing network requests or other potentially time-consuming operations. For the same reason, you should not show dialog boxes from GeneratePreviewHtml.
On the other hand, it is fine to perform long-running operations in the HeaderFooterSource.GeneratePublishHtml Method. However, because GeneratePublishHtml is called directly from the main user interface (UI) thread, blocking that thread for more than a few seconds makes the entire Writer window unresponsive. Therefore, perform all network requests and other operations that could take a second or more by using the TaskServices.ExecuteWithResponsiveUI Method.It is also fine to display modal dialog boxes from GeneratePublishHtml. Create and display all dialog boxes on the main UI thread and use dialogOwner as the owner. Do not return from GeneratePublishHtml until all of your dialog boxes are closed and all background tasks are complete, because interacting with any of the GeneratePublishHtml arguments after the method has returned will result in undefined behavior.