Windows Live Plug-in for Amazon Quick Linker – Download

In my previous post Creating a Windows Live Writer Plug-In with C# I created a plug-in for the Amazon Quick Linker.  I didn’t include the plug-in it self.  I thought It would be better to have a smaller post showing it and the download.  So here is a quick tour or FAQ on it.  Please feel free to post your questions and suggestion on this post.  I really would like to hear back from you.

Download Amazon Quick Linker Plug-in for Windows Live Writer

Installing:

  1. Close Windows Live Writer it isn’t already.
  2. Unzip the AmazonQuickLink.zip file into your “C:\Program Files\Windows Live\Writer\Plugins” directory.
  3. Open Windows Live Writer and check for the lighting icon on the bottom right menu labeled “Insert”.

AmazonQuickLinkerDemo

Please note, you need to have the Amazon Quick Linker Widget installed to use this.  In my post WordPress, Windows Live Writer, and Amazon Quick Linker I talk about how I got Amazon Quick Linker working with WordPress.

Creating a Windows Live Writer Plug-in using C# Part 2

First we will start off with the Plug-in class that inherits from ContentSource.  Please note from Part 1 that “InsertForm” is a class we will create.

 

   1: using System;

   2: using System.Collections.Generic;

   3: using System.Linq;

   4: using System.Text;

   5: using WindowsLive.Writer.Api;

   6: using System.Windows.Forms;

   7:  

   8: namespace AmazonQuickLinkPlugin

   9: {

  10:     [WriterPlugin(

  11:         "93DD80D7-9327-4375-A9D8-777C0549C1C8", 

  12:         "Amazon Quick Link", 

  13:         PublisherUrl="http://www.whatifoundout.com",

  14:         Description="Creates a Amazon Quick Link url",

  15:         ImagePath="Images.Shazam.png")]

  16:     

  17:     [InsertableContentSource("Amazon Quick Link")]

  18:     public class Plugin : ContentSource

  19:     {

  20:         public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)

  21:         {

  22:             using (InsertForm form = new InsertForm())

  23:             {

  24:                 DialogResult result = form.ShowDialog();

  25:                 if (result == DialogResult.OK)

  26:                     content = form.Link;

  27:                 

  28:                 return result;

  29:             }

  30:  

  31:         }

  32:     }

  33: }

Now that we have the basics lets create the “InsertForm” form.  First a capture of what I made it look like and then the code.

image

   1: using System;

   2: using System.Collections.Generic;

   3: using System.ComponentModel;

   4: using System.Data;

   5: using System.Drawing;

   6: using System.Linq;

   7: using System.Text;

   8: using System.Windows.Forms;

   9:  

  10: namespace AmazonQuickLinkPlugin

  11: {

  12:     public partial class InsertForm : Form

  13:     {

  14:         public string ASIN { get; set; }

  15:         public string Category { get; set; }

  16:         public string SearchTerm { get; set; }

  17:         public string InnerText { get; set; }

  18:         public string Link { get; set; }

  19:  

  20:         public InsertForm()

  21:         {

  22:             InitializeComponent();

  23:         }

  24:  

  25:         private void btnOK_Click(object sender, EventArgs e)

  26:         {

  27:             AssignProperties();

  28:             this.Link = CreateAmazonQuickLink();

  29:             this.DialogResult = DialogResult.OK;

  30:             Close();

  31:         }

  32:  

  33:         private void btnCancel_Click(object sender, EventArgs e)

  34:         {

  35:             this.DialogResult = DialogResult.Cancel;

  36:             Close();

  37:         }

  38:  

  39:         private void AssignProperties()

  40:         {

  41:             //TODO: Add validation of ASIN format

  42:             this.ASIN = txtASIN.Text.Trim();

  43:             //TODO: Get categories from Amazon

  44:             this.Category = txtCategory.Text.Trim();

  45:             this.SearchTerm = txtSearchTerm.Text.Trim();

  46:             this.InnerText = txtInnerText.Text.Trim();

  47:         }

  48:  

  49:         private void btnPreview_Click(object sender, EventArgs e)

  50:         {

  51:             AssignProperties();

  52:             txtPreview.Text = CreateAmazonQuickLink();

  53:         }

  54:  

  55:         private string CreateAmazonQuickLink()

  56:         {

  57:             StringBuilder s = new StringBuilder();

  58:             s.Append("<a type=\"amzn\" ");

  59:  

  60:             if (ASIN != string.Empty)

  61:                 s.Append("asin=\"").Append(ASIN).Append("\" ");

  62:             else

  63:             {

  64:                 if (SearchTerm != string.Empty)

  65:                 {

  66:                     s.Append("search=\"").Append(SearchTerm).Append("\"");

  67:                     if (Category != string.Empty)

  68:                         s.Append("category=\"").Append(Category).Append("\"");

  69:                 }

  70:                 else

  71:                     return string.Empty;

  72:             }

  73:  

  74:             s.Append(">").Append(InnerText).Append("</a>");

  75:  

  76:             return s.ToString();

  77:         }

  78:  

  79:     }

  80: }

I’ve added a few TODO’s but for the most part it is done and works great.  One other thing I might note.  I never did get the XCOPY command they give you in the documentation to work after the first compile.  I had to keep deleting the DLL I created in the WindowsLive Writer plug-in directory.

Here is the Amazon Quick Linker plug-in in action.  Let me recommend one of my favorite books on estimation.  Steve McConnell just knows how to put it in a way I understand.  When I read his book Software Estimation: Demystifying the Black Art (Best Practices (Microsoft)) it really opened my eyes and made my programming more enjoyable.  I hope it will do the same for you.

WordPress, Windows Live Writer, and Amazon Quick Linker

A friend of mine turned me on to Windows Live Writer for doing my blogs.  It works great with WordPress and I don’t have the trouble of waiting for post-backs or time-outs like I did when I work with WordPress.  I love it!  I can also save my drafts locally on my hard drive or to my blog and then pick them up later.  Its loaded with lots of great features.  One of my favorite is that it shows you just what your post will look like on your blog before you publish it.

I only had one problem installing it.  When I set up Amazon Quick Linker I pasted the code they gave me into the header.php file of my WordPress theme.  For some reason this stymied Windows Live Writer when it tried to return my theme.  After I removed the Quick Linker code and updated the theme in Windows Live Writer it installed correctly.  I then put the Amazon Quick Linker code back in and presto! I am off and blogging again.