DCSIMG
July 2010 - Posts - Arik Poznanski's Blog

Arik Poznanski's Blog

It CAN be done with .NET

News

MVP

MCC

CodeProject MVP

MCPD

MCTS

Subscribe to my blog by email

Arik Poznanski LinkedIn Profile

Email: arik.com at gmail dot com
or, use this form

Locations of visitors to this page


Sela Group

Sela Canada

DZone MVB

Links

Official Blogs

WPF / SL Blogs

Developers Blogs

July 2010 - Posts

Live Writer Plug-in for Sharing Technical Post

Adding a new post to my blog was always a daunting task.
I had to follow these steps:

  • Write the post on Windows Live Writer
  • Publish it and get the post link
  • Submit to DotNetKicks and get their counter html
  • Submit to DotNetShoutout and get their counter html
  • Prepare html for my CodeProject blog feed
  • Edit the post and add the html I’ve collected in the previous steps
  • Republish post

Well, no more!

Inspired by Guy Burstein’s post I’ve decided to write my own Live Writer Plug-in that will handle all of this mess for me.

In order to test the plug-in I have to publish something on my blog.
So, this is it. Wish me luck.

How to implement a Windows Live Writer Plug-in that adds sharing buttons to your post

First, credit goes to Guy Burstein for providing a reflectable DLL in his post.
Also, I’ve used guidelines for Windows Live Writer Plug-in written by Scøtt Lovegrove.

The end result is a plug-in that adds to your posts the following share icons:

image

Since enough information already exists on this subject, I’ll just quickly review the steps I’ve followed:

1. Create new Class Library project, using .NET Framework 2.0 (!)

Not sure why, but Microsoft recommends to use version 2.0 of the .NET Framework when writing a Windows Liver Writer plug-in.

2. Add reference to WindowsLive.Writer.Api.Dll, which resides in the Windows Live Writer folder (e.g. \Program Files\Windows Live\Writer\)

3. Add “using WindowsLive.Writer.Api;”

4. Create a class that inherits HeaderFooterSource

This type of plug-in allows us to add custom generated html in either the header or the footer of the post.

5. Put WriterPlugin attribute on the class

Here is the code for a basic version of the plug-in (only has one button):

using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace ShareTechPost
{
    [WriterPlugin("00407F92-2152-4339-A9A5-B89873EB77A7",
        "Share Technological Post",
        PublisherUrl = "http://blogs.microsoft.co.il/blogs/arik/",
        Description = "A plugin that lets you share a technological" +
                      " post on numerous sharing sites.",
        ImagePath = "writer.png",
        HasEditableOptions = true)]
    public class ShareTechPostPlugin : HeaderFooterSource
    {
        private Settings _settings;

        public override bool RequiresPermalink
        {
            get
            {
                return true;
            }
        }

        public override void Initialize(IProperties pluginOptions)
        {
            base.Initialize(pluginOptions);

            _settings = new Settings(pluginOptions);
        }

        public override void EditOptions(IWin32Window dialogOwner)
        {
            SettingsForm settingsForm = new SettingsForm(_settings);
            settingsForm.ShowDialog(dialogOwner);
        }

        public override string GeneratePreviewHtml(
            ISmartContent smartContent,
            IPublishingContext publishingContext,
            out Position position)
        {
            position = Position.Footer;

            StringBuilder generatedHtml = new StringBuilder();

            if (_settings.AddDotNetKicks)
            {
                generatedHtml.AppendFormat
                    ("<a href=\"http://www.dotnetkicks.com/kick/" +
                    "?url={0}\"><img border=\"0\" "+
                    "alt=\"kick it on DotNetKicks.com\" " +
                    "src=\"http://www.dotnetkicks.com/" +
                    "Services/Images/KickItImageGenerator.ashx" +
                    "?url={0}&amp;bgcolor=6600FF\" /></a> ",
                    publishingContext.PostInfo.Permalink);
            }
                        
            return generatedHtml.ToString();
        }

        public override string GeneratePublishHtml(
            IWin32Window dialogOwner,
            ISmartContent smartContent,
            IPublishingContext publishingContext,
            bool publish,
            out Position position)
        {
            return GeneratePreviewHtml(
                smartContent,
                publishingContext,
                out position);
        }
    }
}

The Settings class and SettingsForm just lets you control some of the sharing options.

This is how the settings form look like:

image

You can find the full source for this plug-in here.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

Step Into .NET Framework 4.0 Source Code

In this post I’ll show you how to configure your Visual Studio 2010 to step into the source code of .NET Framework 4.0

Why?

Because its cool.

Because it helps with debugging.
Not only you can see the code but you can step into it.

Because unlike with Reflector, you get the code with the original comments and variable names!

Step 1: Download Source

Go to http://referencesource.microsoft.com/netframework.aspx

Download from the line marked with Product Name: .Net , Version: 4
That's a 175MB download.

image 

Step 2: Install Source

Install “Net_4.msi”, which you have downloaded at the previous step.

I’ve installed it into: “D:\RefSrc\”
The installed size is approximately 1GB of source and symbols (are you excited yet?)

 image

 

Step 3: Setup Visual Studio 2010

For configuring Visual Studio 2010:

1. Launch Visual Studio 2010

2. From the Tools menu, choose Options.

3. In the Options dialog box, open the Debugging node and select General

- Uncheck "Enable Just My Code (Managed only)"

- Check "Enable source server support"

- Uncheck "Require source files to exactly match the original version"

- Optional: Uncheck “Step over properties and operators (Managed only)”

image

4. Select Symbols under Debugging.  

In the Symbol File Locations box, add the downloaded symbols location: 
“D:\RefSrc\Symbols”

Note: To add the Symbols path Click on the folder icon.
    
Enter in text box under 'Cache symbols in this directory’: 
“D:\RefSrc\Symbols\Cache”

image

That’s it, you can now try to F11 (Step Into) .NET source code.

Troubleshooting

If you fail to see the symbols, try one of the followings:

  • Make sure you debug a program under .NET Framework 4.0

image

  • Make sure you didn’t install it in to \Program Files\, since you need elevated permissions to write to there. If you already installed it there, you can either run Visual Studio 2010 as Administrator or just change the cache folder to some other writable folder.
  • While running, Right Click on the Call Stack, on some grayed .NET functions, select “Load Symbols From” and then “Symbol Path”.

 image

  • If you encounter the “No Source Available” screen, try to press “Browse to Find Source” and find the file you need in the source directory. You should probably need to use files search to find it.
    This is done only once, since from now on Visual Studio remembers this location and search there for missing source files.

image

Finally, you can find more information at: http://referencesource.microsoft.com/

That’s it for now,
Arik Poznanski

kick it on DotNetKicks.com Shout it