Windows - Sahabat Travel

Breaking

Sahabat Travel

This Web is under maintenance.

Follow us

test banner

Post Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Tuesday, June 29, 2010

Windows


Windows Live Writer Technical Preview: New SDK Features

The June 2008 Technical Preview release of Windows Live Writer brings some enhancements to our SDK. The big news is the addition of two new plugin types: publish notification hooks and header/footer content sources. Of course, you can still create and use the same content source plugins that you might remember from Windows Live Writer 2008. With this version of the SDK, content source plugins (in addition to the two new types of plugins) can now read the title, body, and other properties from the current blog post, via IPublishingContext.PostInfo.
This document describes the new features available in the Technical Preview. It is not intended to replace our existing documentation. If you’re new to developing plugins with Windows Live Writer, be sure to read the section on content source plugins, since much of that information applies to the new plugin types as well.
Because this release of Windows Live Writer is a Technical Preview and not intended for most end users, Windows Live Gallery is not currently accepting plugin submissions that are based on the new version of the SDK. Also, please be aware that future releases of Windows Live Writer may break plugins written against the Technical Preview SDK, since the purpose of the Technical Preview is to let us get feedback from the community ahead of future betas and final releases.
We want your feedback! Please stop by our forum.

Publish Notification Hook Plugins

Publish Notification Hook plugins allow you to execute code before and after Writer posts content to a weblog. They can examine the contents of the post and have the option to cancel the publish operation.
Examples of plugins you could write using Publish Notification Hooks are:
·         Send alerts of new blog posts to microblogging sites like Twitter
·         Ask for confirmation if Tags/Keywords field is empty
·         Warn if the post contains non-validating XHTML
Publish notification hooks are the easiest type of plugin to write. Just follow these steps:
1.       Create a new .NET Class Library project using Visual Studio 2008 or any other development environment that supports creating .NET assemblies.
2.       Add a reference to the WindowsLive.Writer.Api assembly (located in the directory C:\Program Files\Windows Live\Writer)
3.       Create a new class for your plugin by extending PublishNotificationHook
4.       Annotate your plugin class with WriterPluginAttribute. The first argument is a GUID (without leading and trailing braces) that uniquely identifies your plugin. (You can generate a GUID from the Tools menu of most editions of Visual Studio, or use an online GUID generator.) The second argument is the name of your plugin.
5.       Override the OnPrePublish and/or OnPostPublish methods
using System.Windows.Forms;
using WindowsLive.Writer.Api;

[WriterPlugin("????????-????-????-????-????????????", "My Plugin Name")]
public class MyPublishNotificationHook : PublishNotificationHook
{
    public override bool OnPrePublish(IWin32Window owner, IProperties properties,
            IPublishingContext publishingContext, bool publish)
    {
        // Do pre-publish work
        return true;
    }

    public override void OnPostPublish(IWin32Window owner, IProperties properties,
            IPublishingContext publishingContext, bool publish)
    {
        // Do post-publish work
    }
}

Unlike content source plugins, publish notification hooks can be enabled or disabled by the user on a per-blog basis. The first time a publish operation occurs for a particular blog since a publish notification hook was installed, the user will be asked if the hook should be enabled or disabled for that blog.

For more details, see the PublishNotificationHook class in the API reference. For a full example, see the Twitter Notify sample plugin.

Persistent Properties

Like all plugins, each publish notification hook has access to its own set of global plugin options via the Options property.
Your plugin may also need to store its own custom state for each post. You can use the IProperties parameter of OnPrePublish/OnPostPublish for this purpose. These properties are persisted by Writer within the post file, so you can access them if the same post is ever republished in the future.

Header/Footer Source Plugins

Header/Footer Source plugins insert headers or footers during publishing (or posting as draft). Headers and footers are not directly editable by Writer users and do not appear in Writer’s editing views, but are visible in the Preview view (and of course, on the published blog post).
To write a header/footer plugin, follow these steps:
1.       Create a new .NET Class Library project using Visual Studio 2008 or any other development environment that supports creating .NET assemblies.
2.       Add a reference to the WindowsLive.Writer.Api assembly (located in the directory C:\Program Files\Windows Live\Writer)
3.       Create a new class for your plugin by extending HeaderFooterSource
4.       Annotate your plugin class with WriterPluginAttribute. The first argument is a GUID (without leading and trailing braces) that uniquely identifies your plugin. (You can generate a GUID from the Tools menu of most editions of Visual Studio, or use an online GUID generator.) The second argument is the name of your plugin.
5.       Decide whether your plugin requires a post to have a permalink to work properly; if so, override the RequiresPermalink property and return true. See Requiring Permalinks below.
6.       Override the GeneratePreviewHtml and GeneratePublishHtml methods
using System.Windows.Forms;
using WindowsLive.Writer.Api;

[WriterPlugin("????????-????-????-????-????????????", "My Plugin Name")]
public class MyHeaderFooterSource : HeaderFooterSource
{
    public override bool RequiresPermalink
    {
        get { return true; }
    }

    public override string GeneratePreviewHtml(ISmartContent smartContent,
            IPublishingContext publishingContext, out Position position)
    {
        position = Position.Footer;
        return "Digg This
"
;
    }

    public override string GeneratePublishHtml(IWin32Window dialogOwner,
            ISmartContent smartContent, IPublishingContext publishingContext,
            bool publish, out Position position)
    {
        position = Position.Footer;
        return "             + publishingContext.PostInfo.Permalink
            + "\">Digg This
";
    }
}

Unlike content source plugins, header/footer sources can be enabled or disabled by the user on a per-blog basis. The first time a publish operation occurs for a particular blog since a header/footer source was installed, the user will be asked if the header/footer source should be enabled or disabled for that blog.

For a full example, see the DiggThis sample plugin.

Managing Plugin Options

Like all plugins, each header/footer source has access to its own set of global plugin options via the Options property.

Requiring Permalinks

Some plugins might require the permalink of the post being published. Permalinks don’t exist until a post is published, yet the HTML generated by the plugin needs to 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 will actually be published twice, with the header/footer sources all being invoked in between.
A header/footer source can indicate that it requires permalinks by overriding the RequiresPermalink property and returning true. The default is false.

Overriding GeneratePreviewHtml and GeneratePublishHtml

The string values you return from GeneratePreviewHtml and GeneratePublishHtml will be 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 on the smart content parameter’s Layout property. You can also use Properties and Files on the smart content object—they work for header/footer sources just like they do for smart content sources.

Other Preview/Publish Guidelines

Header/footer sources can provide different HTML for previewing than for publishing. Writer users expect previews to load quickly, so in your implementation of GeneratePreviewHtml , make every effort to avoid performing network requests or other potentially time-consuming operations. For the same reason, you should not show dialogs from GeneratePreviewHtml.
On the other hand, it’s perfectly fine to perform long-running operations in GeneratePublishHtml. However, since GeneratePublishHtml is called directly from the main UI thread, blocking for more than a few seconds will make the entire Writer window unresponsive. Therefore, all network requests and other operations that could possibly take a second or more should be executed using TaskServices.ExecuteWithResponsiveUI. For example:
public static string DownloadHtml(string url)
{
    string html = null;
    TaskServices.ExecuteWithResponsiveUI(delegate
        {
            using (WebClient wc = new WebClient())
                html = wc.DownloadString(url);
        });
    return html;
}

It’s also fine to show modal dialogs from GeneratePublishHtml. All dialogs should be created and shown on the main UI thread using dialogOwner as the owner. Do not return from GeneratePublishHtml until all of your dialogs are closed and all background tasks completed, as interacting with any of the GeneratePublishHtml arguments after the method has returned will result in undefined behavior.

No comments:

Post a Comment

Post Top Ad

Responsive Ads Here