Archive for August, 2008

IE8 Accelerators

With the release of a much more stable IE8 (beta 1 was truly, truly awful), I am now able to actually try some of the cool things that are in IE8. One of these things are the accelerators that you can install. What this means is you could highlight some text on a page and get a little icon appear in the page giving you some options for that highlighted text:

Some of the accelerators are for searching on Google/Live Search, looking stuff up on maps, etc. Now, the cool thing is you can create your own, so I’ve created one that’s for IMDB that will look up the highlighted text on IMDB, whether it be actor/actress/movie. So using the above example, this will give you the following context menu:

This will then take you to the IMDB results, in this case, it takes me to http://www.imdb.com/name/nm0515116/ which is Blake Lively’s IMDB page. If there are multiple people with the same name then it will give you the search results where you can choose. So how did I make it? It’s simple, head on over to the MSDN OpenService Accelerators Developer Guide and read what’s going on there. Then it’s just a case of creating your own xml file. Mine looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<os:openServiceDescription
    xmlns:os="http://www.microsoft.com/schemas/openservicedescription/1.0">
    <os:homepageUrl>http://www.imdb.com</os:homepageUrl>
    <os:display>
        <os:name>Look up on IMDB</os:name>
        <os:icon>http://www.imdb.com/favicon.ico</os:icon>
        <os:description>Look up someone on IMDB</os:description>
    </os:display>
    <os:activity category="Search">
        <os:activityAction context="selection">            
            <os:execute action="http://www.imdb.com/find?s=all&amp;q={selection}" />                
        </os:activityAction>
    </os:activity>
</os:openServiceDescription> 

Now, the only thing about making your own accelerator is the xml file has to be hosted on an actual domain and be callable from http or https. I thought this would be fine, just stick it on my www.scottisafool.co.uk domain, job done. But no, my host (1and1) seems to not be letting me access my ftp server, so I was stuck. Then I remembered good ol’ Windows Live. So both the xml file, and a simple html file are now both hosted on my SkyDrive area so you can install from there.

Feel free to leave any comments or problems with it 🙂

SL

Whilst writing this, I was listening to Def LeppardPromises

Advertisements

4 Comments

Writing Plugins For Windows Live Writer – Logging Errors

Sometimes your plugin will require some kind of logging, especially when it comes to logging errors that have occurred. So rather than reinvent the wheel for this, the Live Writer API has a class for doing just this, and logs it into the Windows Live Writer log file. So if you have implemented this in your plugin and you get an email come in with it giving errors or not working, you can request the log file and check what has been written. In the following example I’ll show you the code samples needed for logging to the WLW Log file.

This is a very simple thing to demonstrate, so I’ve created a simple plugin with a form and two buttons, one will call an error message box that looks like a normal Windows Live Writer error window as well as log it to the Windows Live Writer logfile. The second button will be used to try and open a file that doesn’t exist and so would normally throw an exception.

So the form looks like:

And when we click the first button we get:

When you then look in your logfile, you will see an entry at the end that says:

WindowsLiveWriter,1.11700,None,00017,05-Aug-2008 20:08:14.842,"DisplayableException occurred: WindowsLive.Writer.CoreServices.DisplayableException: Oh no, an error! – This is an error logged and displayed by the Plugin Diagnostics Plugin",""

Which as you can see is what is in that error window.

For the second button we get:

and again in the logfile:

WindowsLiveWriter,1.11200,Fail,00016,05-Aug-2008 22:55:49.828,"Unexpected Error Occurred
Exception Details:
An unexpected error has occurred within the application.
System.IO.FileNotFoundException: Could not find file ‘c:\scottisafool.scott’.
File name: ‘c:\scottisafool.scott’
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.Open(String path, FileMode mode)
   at PluginDiagosticsExample.frmMain.button2_Click(Object sender, EventArgs e)",""

With the second button, you’ll see that we aren’t presented with the standard Windows Live Writer error window, but a standard Windows error, the reason for this is because it’s the only way for the Writer team to get information about the error. What they then do is contact the plugin author and give them the details.

Now, to add this functionality to your plugin is dead simple:

        private void button1_Click(object sender, EventArgs e)
        {
            // Log a general Error Message it to the user
            string message = "This is an error logged and displayed by the Plugin Diagnostics Plugin";
            PluginDiagnostics.LogError(message);

            // This one will show the error to the user as well as log it
            PluginDiagnostics.DisplayError("Oh no, an error!", message);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // Log an exception by opening a non-existent file
            try
            {
                File.Open(@"c:\scottisafool.scott", FileMode.Open);
            }
            catch (Exception ex)
            {
                PluginDiagnostics.LogException(ex, "From Plugin Diagostics Plugin");
                // This will display an error in the same way that Windows displays its own errors.
                PluginDiagnostics.DisplayUnexpectedException(ex);
            } 
        }

It’s as easy as that! With the first button, it’s up to you whether you display the error message or not (you might not need to). If you use the DisplayError() method, this gets written to the log file automatically, so although I show both methods in that example, it’s not necessary. This goes for the LogException() and DisplayUnexpectedException() methods too.

As always, you can download the source for this little sample from my skydrive area: PluginDiagosticsExample.zip

Windows Live Tags: , , , ,

SL

Whilst writing this, I was listening to Linkin ParkOne Step Closer

6 Comments