Tuesday, January 11, 2011

How to fix the blog’s look?

This post was moved to my real blog: How to fix the blog’s look?

Writing a Windows Live Writer Plugin

Well Windows live writer is great but…

1. I really want to be able to see where the <p> tag are placed, since it’s doing some damage to my blog.

2. I really want to add tags more easily

So, I found this post on the web. But once I opened VS I quickly found out that the example was for a previous version or that it didn’t go into the details I required. So I Googled some more and found projects on CodePlex implementing plugins for Windows Live Writer.

I thought to start with the tags project and even gave it the good name of “DllShepherdDotNet.WindowsLiveWriter.TagAdderDeluxe”. I thought it’s going to be easy since I found a project named Windows Live Writer Auto Tag Generator but looking at the source code made me realize fairly quickly that it doesn’t create tags only create a list of tags in the user’s clipboard. A red flag went up in my mind - why didn’t the creators of the plugin add a tag automatically? And the answer to that after looking in the API for WLW - there are no references to Tags anywhere in the API (actually I found one reference in here, with the line: “Ask for confirmation if the Tags/Keywords field is empty.” and I couldn’t find a Tags field!).

I was still not entirely convinced it’s a lost cause, so I tried copy paste the html of the tag - it worked:

<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ad4b3bac-273e-4b93-af2a-ec81181d364b" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/Windows+live+writer" rel="tag">Windows live writer</a>,<a href="http://del.icio.us/popular/blog" rel="tag">blog</a>,<a href="http://del.icio.us/popular/plugin" rel="tag">plugin</a>,<a href="http://del.icio.us/popular/add-on" rel="tag">add-on</a>,<a href="http://del.icio.us/popular/tag" rel="tag">tag</a>,<a href="http://del.icio.us/popular/paragraph" rel="tag">paragraph</a></div>

The blue bold 0767317B-992E-4b12-91E0-4F059A8CECA8 seems to be the id for tags. Whereas the bold red ad4b3bac-273e-4b93-af2a-ec81181d364b seems to be the id of the tag. So I tried to change the id to something random – it seemed to work until I tried editing it through the Tag dialog, then this happened:

image

I tried restarting WLM the pop up still popped. I tried moving the draft to someplace else and still it popped. At the end a restart solved the problem.

The error report contained the following files:

dwstacktrace.txt

System.NullReferenceException: Object reference not set to an instance of an object.

at WindowsLive.Writer.Mshtml.MshtmlEditor.AddEditDesigner()

at WindowsLive.Writer.Mshtml.MshtmlEditor.ReadyStateChangedHandler(Object sender, EventArgs ea)

 

dwlog.txt

00000 09:18:39:46 PM User is opted out of CEIP

00001 09:18:39:48 PM Starting Windows Live Writer 14.0.8117.416

00002 09:18:39:48 PM .NET version: 2.0.50727.3615

00003 09:18:39:56 PM No legacy directory to monitor for plugins. Ignoring legacy directory.

00004 09:18:40:07 PM 499 499

00005 09:18:41:29 PM Fail Unexpected Error Occurred

Exception Details:

An unexpected error has occurred within the application.

System.NullReferenceException: Object reference not set to an instance of an object.

at WindowsLive.Writer.Mshtml.MshtmlEditor.AddEditDesigner()

at WindowsLive.Writer.Mshtml.MshtmlEditor.ReadyStateChangedHandler(Object sender, EventArgs ea)

//TODO: check out this 

 

After all that, lets work on some paragraphs plugin…

 

 

//TODO: replace WLM with Windows Live Writer

//TODO: copy XML from VS

 

Resources:

MSDN: Windows Live SDK

Writing a simple Windows Live Writer plugin

 

Keywords: Windows live writer, blog, plugin, add-on, tag, paragraph, error, problem, object reference, NullReferenceException,

Unit Tests: What to Test?

Have you read the book Pragmatic Unit Testing in c# with NUnit?
No, read it (it's a must):

 

Well the book has this poster at the back:

Unit-Tests-what-to-test

(click here to get a PDF version directly from their site)


 

Well what I like to test are these things:

1. Right: given good parameters is the function returning good results?

2. Boundary Conditions: given parameters such as null values, empty string, empty list, negative/zero index, out of bound indexes is the method returning the right results (either returns an error, throws an exception or does nothing).

3. Inverse: if you can write some code that returns your parameters back, test that you are getting them back. For example 3++ = 4 , 4-- = 3

4. Cross-Check: if you can write some code that runs the method in a different way, test that for the same input you get the same results. For example: 3++ = 4 , 3+1 = 4

5. Error Condition: test for exceptions – for the right parameters the method throws an exception of the right type. For example when dividing by zero an exception of type DivideByZeroException is thrown.

6. Performance: test for the time/memory/CPU the method took to run



My preferred way of writing Unit tests is:

  1. public class TestedClassTests
  2. {
  3.     public void TestedMethod_WhatIsTested_ExpectedResult(){...}
  4. }

If you tried that and are using Resharper you will get a warning that the naming convention is wrong but there is a solution.

 

Now I usually use a Live Template from Resharper that automatically creates regions with test methods for all the test cases. I have put the template in my Codeplex Project: ResharperTemplates\TestTemplate_ResharperLive.xml



//TODO: Add VS Snippets
Resources:
How to change the ReSharper naming style for test methods

http://stackoverflow.com/questions/463595/poll-c-apps-memory-usage-at-runtime

http://stackoverflow.com/questions/275957/can-a-c-program-measure-its-own-cpu-usage-somehow


Keywords: Unit test, beginner, ExpectException, Exception, Resharper