JiuJitsuProGear Affiliate Plugin for Windows Live Writer

I blog a lot about Brazilian Jiu-Jitsu.  I like to add to my blogs items from JiuJitsuProGear.com.  It was a pain having to create affiliate link using their nebular look up page.  So I created a Windows Live Plugin that does it for you.  It downloads the items from JiuJitsuProGear.com and cleans them up.  You can sort and filter the items to find the one you want.  It even saves your affiliate id for you.  The first time it loads it does take some time to download the items and create the appropriate files.  You must have read/Write privileges to your Windows Live Writer plug-in directory.

If you like my plug-in please Donate $1 to help me keep creating cool stuff like that. Donate to www.whatifoundout.com

If you need help or have feed back I will respond to this post.

To Install:

  1. Download and unzip the plug-in into your Windows Live Writer Plugin file.
  2. Open Windows Live Writer and try it.  It will take a minute to load the first time.

Download it: JiuJitsuProGear Affiliate Plugin for Windows Live Writer

 

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.

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

There are a few example out there already for ContentSource but after trying to use them I found some glaring omissions.  For instance, two of the examples I looked at use InsertForm.  I just assumed that because we were using the namespace System.Windows.Forms that is where it was coming from.  Because the example were in the 2.0 Framework I thought maybe I was just missing some thing.  So when I got the error “The type or namespace name ‘InsertForm’ could not be found (are you missing a using directive or an assembly reference?)” I assumed it was just a matter of finding the reference I needed.  It was!  But to a class I should and would create.  I also had a hard time with the ImagePath property of the WriterPlugin attribute.  For starters the png file must be 16×16 despite what the documentation says, 20×18 didn’t work.  Also don’t forget to set the Build Action property on the image to Embedded Resource.  Its a minor detail that the documentation has but the examples leave out.  Please don’t go looking for a SDK to download despite what is said in the other example.  The WindowsLive.Writer.Api is in the root directory of WindowsLive Writer.

To Summarize:

  1. Your project will need a Windows Form Class added (Name if “InsertForm.cs” just for the fun of it)
  2. Make sure your image is 16×16.
  3. Make sure you set the Build Action on the image to Embedded Resource.
  4. The WindowsLive.Writer.Api file is found in C:\Program Files\Windows Live\Writer
  5. WindowsLive Writer SDK Documents

In Part 2 of this post I will share the plug-in I create and use it in the post.