ailon's DevBlog: Development related stuff in my life

Book Review: Framework Design Guidelines. Conventions, Idioms, and Patterns for Reusable .NET Libraries by Krzysztof Cwalina and Brad Abrams (Second Edition)

6/11/2010 3:38:05 PM

5138dM4PHnL._SS500_ This book is a must-read and a must-have for anyone developing .NET libraries and frameworks. It’s basically an internal Microsoft document describing how .NET itself and related frameworks should be developed.

Guidlines are divided into DO, DON’T, CONSIDER and AVOID depending on how strong authors feel about them. In addition to official guidelines the book is filled with notes and commentary from other Microsoft gurus. Quite often these notes are even more valuable than guidelines themselves. That said there were a few places where guideline was just thrown out there without any explanation of the reasoning behind it. Sometimes it was obvious but a few times not so much.

If you are an experienced .NET developer you probably follow most of these guidelines automatically but this book provides all of them in one place. You can force your less experienced colleagues read this book and save them from learning these rules the hard way. And when in doubt it’s an excellent reference to turn to.

I must say this is not a fascinating read. To tell the truth it’s one of the most boring books I’ve ever read. Nevertheless it’s extremely valuable and I don’t hesitate to recommend it to any .NET developer. And even if you don’t do .NET you can gather quite some wisdom from it.

If you follow tech news you probably know that Brad Abrams left Microsoft and went to Google, so, I guess, we shouldn’t expect a third edition of this book (at least by the same authors) in the foreseable future. So this is probably as good as it gets for now.

Buy this book from Amazon

Tags: ,

Online Tool to Get RSA Public Key in XML Signature format

5/24/2010 6:14:01 PM

Last month I’ve posted a short how-to about getting XML Signature foramatted public key from Base64 encoded certificate. Now that I’ve launched a sub-site for my online tools I thought there’s no reason to leave that post as a how-to only, when most people just need to use it once.

So I’ve made a simple online tool that does just that – you paste your base64 encoded RSA public key into a form and get XML signature formatted version. No need to implement this yourself.

What's that for?

If you need to say verify data in .NET signed with private key and you don't have/want the public key (certificate) installed on your machine, the easiest way to go is to load public key data from XML string using RSACryptoServiceProvider.FromXmlString() method.

Problem is that it accepts key information in XML Signature format (the one with <RSAKeyValue><Modulus> etc.) and there is no easy way to get it in that format. Most of the time you get the key in base64 encoded form or in binary form from which you can get the base64 version.

This tool lets you get the XML Signature version from that base64 representation.

Tags: ,

Get RSAKeyValue from Base64 Encoded Public Key

4/27/2010 6:54:55 PM

Note: I don’t know much about encryption and certificates. This is not a tutorial or good explanation of things. It’s just a note to myself for future reference.

I needed to verify data sent to my ASP.NET app signed by 3rd party using their private RSA key. They’ve sent me their public key in base64 encoded form. You’ve probably seen it many times. It looks something like this:

-----BEGIN CERTIFICATE-----
MIIECTCCA3KgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBujELMAkGA1UEBhMCTFQx
EDAOBgNVBAgTB1ZpbG5pdXMxEDAOBgNVBAcTB1ZpbG5pdXMxHjAcBgNVBAoTFVVB

-----END CERTIFICATE-----

Problem is (as far as I understand) to verify data using RSACryptoServiceProvider you either need the key installed on your system or have it in XML Signature format. I’ve searched high and low for a way to convert that encoded key to XML equivalent but couldn’t find a simple way. Most likely I wasn’t searching for the right thing and I admit I’m not an expert in this area. I guess this can be done some other way but after combining some breadcrumbs I found here and there I came up with only 3 lines needed to to get <RSAKeyValue> representation of the key:

   1: byte[] binaryCertData = Convert.FromBase64String(mimeKey);
   2: X509Certificate2 cert = new X509Certificate2(binaryCertData);
   3: string xmlKey = cert.PublicKey.Key.ToXmlString(false);

And that was it. Does the trick.

Update: I’ve created an online tool to convert Base64 encoded public key to XML Signature format.

Tags: ,

VisualStudio.NET vNext Feature Request: Multi-target IntelliSense

4/8/2010 6:44:04 PM

Visual Studio is great. IntelliSense is great. But here’s one thing that has been slowing me down ever since I started developing for several .NET based platforms.

The Problem

WPF, Silverlight and now Silverlight for Windows Phone 7 are very similar frameworks, but they are far from being identical. Lots of code written for one can be re-used in another, but quite often it requires small modifications and it’s frustrating. It’s especially frustrating when you realize that those modifications wouldn’t be necessary if you’ve used another overload of some method or used another method altogether in the first place.

Take a look at screenshots of the IntelliSense dropdown for the same class in different environments:

Here’s one for WPF 3.5:

wpf_dropdown

And this is on for Silverlight 3:

silverlight_dropdown

Notice that there are lots of methods, properties and events that are not in Silverlight and I guess you can find some that are not in WPF (but that is not the point here). Sometimes you want to use WPF-only stuff for better performance or other very valid reasons but quite often you just use it unconsciously because finding out if something is supported in Silverlight or vice versa takes too much time and effort.

Now I wanted to add a LineSegment to the PathFigure and it has 3 constructor overloads in WPF

wpf_overloads

but only only the default constructor in Silverlight

silverlight_overloads

If I haven’t checked for the difference manually (or knew it by heart) I would end up rewriting this code once I’ve switched to a Silverlight project. So, you get the picture. The fact that I constantly have to recompile for all the platforms and/or manually check for differences takes a significant amount of my development time. I would like this to be addressed somehow and if some third party tool does something good in this area, please, let me know in the comments, but for now I have this idea/feature request for future version of Visual Studio .NET

Multi-target IntelliSense

There are numerous ways how this could be implemented and I’m not the best expert in things like this, but I’ll try to explain my vision of this anyway.

I think a project could have a set of secondary Target Framework settings. When these are set, IntelliSense would somehow highlight members or overloads that are in main target framework but not in the secondary. For example WPF methods that aren’t in Silverlight could be grayed out in the dropdown above. Same goes for method overloads. Plus some text explanation in the tooltip wouldn’t hurt too.

Something like this would be a huge time saver for me and I guess for other developers too. Especially with all the extra framework partitioning related to release of Silverlight for Windows Phone 7 which will be another very close yet not completely identical addition to the current mix of WPF & Silverlight.

I’ve ran this idea by Jesse Liberty at MIX10 and he thought it wasn’t a bad idea at all, so I decided I need to submit it to Microsoft via MS Connect. So if you like this and would like something along these lines implemented in the future version of Visual Studio, please, go there and vote it up.

Shout it

Tags: , , ,

Book Review: The Art of Unit Testing by Roy Osherove

2/2/2010 7:49:36 PM

The Art of Unit Testing by Roy Osherove

Personal preface

I must admit – I haven’t been doing any real-life unit testing until now. Back in 2004 I was leading a relatively big WinForms project and I thought we should do unit testing on it. Unfortunately we had already finalized our conceptual designs (which didn’t consider unit testing), the tooling at the time wasn’t as mature as it is now and, most importantly, we had no knowledge on how this unit testing thing should be done properly. So after playing around with NUnit for some time I’ve concluded that it was neither the time nor the place to start doing it for real and put it away.

After that project I was mostly involved with smaller ASP.NET projects and never thought that unit testing was really feasible for them. So, basically unit testing was always somewhere on my mind but not too close to the surface.

Five years later I’ve started working on amCharts for WPF & Silverlight and as we release new products, add new features and fix bugs I’ve started feeling a real fear of breaking something while fixing a bug or adding a new feature. Manual testing helps but the fear is always there. I understood that it’s time for “take 2” on unit testing.

This time I knew that I have to do it right. This is one of those subjects where you can’t just start doing it and learn as you go. That is a sure way to fail (see my experience above).

The Book

Fortunately this time there is this book and it’s targeted at .NET developers which is not essential but a nice bonus. I’ve been reading Roy Osherove’s blog for quite some time and following him on twitter. I’ve been using his Regulator regular expression testing tool before that. So, I sort of “knew” and respected the author, the book got raving reviews at Amazon – buying it was a no-brainer.

The book is short (less than 300 pages) but on point with almost none “water spilled” and space wasted. I’ve swallowed it in less than a week reading it in the evenings only. That wouldn’t be that fast for a fiction book, but I think that’s a record for me for a technical book. I usually fall asleep reading technical books in bed pretty quickly and I only did it once with this book ;)

It covers all the aspects of unit testing, writing good tests and testable code, tooling for .NET (also mentions tools for Java, C++, etc.). It also offers quite strong author’s opinions on the matters. Some people might not like this, but as long as you can see that it’s an opinion and not something written in stone, I really do like it.

Minor Criticism

I can’t say anything bad about the content of this book, but I have a few minor complaints about presentation. First of all I didn’t like the font used. I’m no expert of fonts and this could be the default Manning (publisher) font, but it didn’t feel right to me (too wide or something). The use of some “comic” type of font for ToC and headings is another story, but since it’s not the main font it didn’t bother me much. There were some minor issues with sample code too: incorrect indentation, a couple of auto-capitalized “return” statements and things like that, but nothing major.

The book comes with free access to ebook version in PDF, ePub and Mobipocket formats w/o DRM (as far as I understand). Unpleasant thing was that my name and email address was inserted in the footer of every page of the PDF. I don’t even know what is more unpleasant DRM or this. Should I protect the PDF now so it doesn’t spread over internet accidentally or something? If I wanted to spread illegal copies I’d find a way to remove this, but now I don’t even feel comfortable giving that PDF to my colleague which I consider a fair use (I’ll give him a paper book anyway). Anyway this is a minor issue and I should stop complaining.

Conclusion

If you are serious about starting unit testing or improving your skills, do yourself a favor and don’t just jump right in, but buy this book (especially if your main platform is .NET). It’s a really excellent starting point for anyone who doesn’t consider himself a unit testing guru (and I guess even gurus might find something new). After reading this book I feel pretty confident that my next project will include unit tests and I’ll have a good basis and this book as a reference if I have questions.

Links

Tags: , ,

amCharts for WPF with Scatter &amp; Bubble Chart Support

7/10/2009 9:16:27 AM

bubble chart for WPF

We’ve released a new version of amCharts for WPF with support for Scatter (XY) & Bubble charting. Check it out and help us spread the word. Thanks!

kick it on DotNetKicks.com Shout it

Tags: , ,

Creating Gapped and Bulleted Shapes in WPF/Silverlight

5/26/2009 10:08:37 AM

I’ve released a small control for creating bulleted paths in WPF. You can get it in download section of this blog. The main trick used in this control is described in my article titled “Creating Gapped and Bulleted Shapes in WPF/Silverlight” and published by dev102.com.

Tags: ,

Name scopes within templates are not supported

5/8/2009 3:03:59 PM

I’ve got an issue reported on amCharts for WPF forum suggesting that it’s impossible to use the charts in DataTemplate. I’ve verified that it was true and exception message reads as follows:

"NameScopeProperty found within the content of a FrameworkTemplate, on a 'AmCharts.Windows.LineChart' object. Name scopes within templates are not supported."

The exception was caused by the call to SetNameSpace method in the constructor of the chart base class:

NameScope.SetNameScope(this, new NameScope());

I’ve re-read documentation on name scopes and made an assumption that I have to find a way to use template’s own name scope to register my names with it and…  spent almost a day trying to figure out how to do it universally.

Finally I gave up on that branch of thought and decided to try something else. To my surprise the problem was solved by simply moving the same call to SetNameScope() from constructor to a place right before it is needed. Namely where I make the first call to RegisterName() which happens after my controls have been loaded, templates applied, etc.

Now I’m not completely sure why this worked but my understanding is that if you do it in the constructor SetNameScope() get’s called in the context of the Template (producing an exception above) and when it is called later it’s already in context of the control to which the Template is applied. Please, correct me if I’m wrong.

kick it on DotNetKicks.com Shout it

Tags: ,

4 Tips for WPF Control Developers

5/5/2009 9:52:22 AM

Dev102.com has published my article titled 4 Great Tips for Custom WPF Controls Developers.

Bonus tip: there’s a 50% discount coupon for amCharts for WPF at the end of that article ;)

Tags: ,

Book Review: Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition by Matthew MacDonald

4/29/2009 1:42:00 PM

prowpf After a pretty bland and unexciting ASP.NET book this was a very good change. Matthew MacDonald covers all aspects of WPF in a very good and interesting style. All the basics are covered, principles explained and practical advices are given.

Probably my only but pretty serious complaint is about a Chapter 24 - Custom Elements. This was one of the main chapters (aside from basic WPF principles) why I bought this book in the first place. I was developing our WPF charting controls and expected to find some insights and guidance in this chapter. Unfortunately a big chunk of the chapter (which is not so long to start with) was dedicated to explaining logical implications of building a masked text box. Probably quite interesting stuff on it’s own but not directly related to what it takes to build custom WPF elements in general.

Aside from that I’m very satisfied with this book and can highly recommend it to any .NET/C# developer interested in programming for Windows Presentation Foundation.

Verdict: close to perfect

Buy this book on Amazon.

Tags: , , ,

Copyright © 2003 - 2014 Alan Mendelevich
Powered by BlogEngine.NET 2.5.0.6