Saturday, 12 January 2013

Some Very Useful Libraries

I'm talking about the .Net ecosystem here, but I guess it applies to most other development environments. I think we tend to talk, discuss, praise... mainly about frameworks and libraries dealing with the last cool and funny stuff (IoC, Dynamic Proxies, RIA development, REST...) and tend to forget about other smaller pieces of software tackling more mundane tasks that oddly enough are not covered by the BCL. At the end of the day these less popular libraries are so or even more important than the other "trendy ones", and given that they get quite less fuzz around them, I think I could pay them a kind of little homage (as if someone was going to read this... :-) by listing here the ones I've found myself using more intensively in the last years

  • HTMLAgilityPack. Bearing in mind the vast amount of Xml support provided by the .Net BCL (XmlDocument, XmlReader, Linq To Xml...) it's really hard to explain why there's not any html parsing and manipulation support, but hopefully, the open source HTML Agility Pack brilliantly fills the gap. It provides a powerful Html parser that will create a read/write DOM for you. It works pretty neat with not too well formed (and sadly too common) html documents.
  • ExcelDataReader Over the years I've used all sort of approaches to such a common task like reading Excel files: Interop and COM (please, avoid this by all means if your code is going to run on a server and don't want to end up with tons of excel.exe processes running in the background), using odbc or ado, saving the excel file to a CSV or TSV file and reading it with an in house built parser... but in the last times I've moved to this small library. It's not perfect (it's given me problems with some very large files), but overall I recommend it.
  • ClosedXml If reading excel data is more problematic that it should be, creating or updating excel files is much worse. Using COM is a mess (as it is for just reading) so years ago we used to leverage an in house library built by a very clever guy at work. With the advent of Office Open Xml, I expected things would be much easier, but seriously, OpenXml is a rather complicated format, and any basic manipulation involves tons of repetitive lines of code. Hopefully, some clever guy has made the effort to write a beautiful library that makes it bread and butter writing non trivial Excel OpenXml files. I've used it quite extensively, and it works like a charm, so, thumbs up and many thanks!
    Notice that (it should be obvious) it relies on Microsoft's DocumentFormat.OpenXml.dll library (you don't need to install the OpenXml SDK, just get hold of this dll).
  • MigraDoc and PDFSharp Last year I had to decide on some free tool for generating Pdf documents from .Net. The list of options is not too large, and in the end we settled on Migradoc. It perfectly served our needs (that I have to admit where not too complex, we were generating simple pdf documents), so it's well deserved a reference here.
  • MS LogParser I assume that the developers of this tool would get a fair salary from Microsoft, so probably some praise in an irrelevant blog won't have much effect on them :-) but anyway, here I go.
    Another blogger explains pretty well in a few words how powerful this tool is

    Log Parser is often misunderstood and underestimated. It could possibly be the best forensic analysis tool ever devised. Imagine having the ability to take almost any chunk of data and quickly search it using SQL-based grammar. That's Log Parser in a nutshell. It is a lightweight SQL-based search engine that operates on a staggering number of different input types

    The LogParser.exe tool comes really handy for some stand alone parsing, but in my case I needed to integrate that parsing in a custom reporting application I was developing, and for that, you can leverage all the power of LogParser through its COM interface. The functionality lives in the LogParser.dll COM library, so .Net developers we'll have to generate the .Net wrapper for this COM, by means of tlbimp:

    tlbimp "C:\Program Files (x86)\Log Parser 2.2\LogParser.dll" /out:Interop.LopParser.dll

    Now add the reference to Interop.LogParser.dll (or whatever you've called it) to your project and you're ready to go.

No comments:

Post a Comment