CTO, Software engineer and Team leader
Posts tagged LINQ
Adding events to LINQtoCSV library
Feb 6th
The User Experience that a library provides must be at least equal with is quality and speed. And frankly, CSVtoLINQ rocks on latest two, as I presented in previous articles Import CSV file and query it with LINQ and continuing in LINQ wonder world, but lacks a little on the User Experience(in our case Developer Experience) by not having some events of starting, progress and ending of the parsing.
Especially important, while parsing huge files, is a confirmation for the user that something happens and (ideally) the point in which the processing is. That is why, thanks to Matt Perdeck for sharing the entire source of the library, I was able to improve it by adding events.
So, let’s see some code!
Modifications into LINQtoCSV library – CSVContext.cs
Important: All modifications will be made in the CsvContext class from LINQtoCSV namespace – the CSVContext.cs file.
First we’ll add the ReadStarted event to the library – it will fire when the reading of the CSV file has started.
// defining the delegate
public delegate void ReadStartedHandler(object sender, EventArgs e);
// here we define the event
public event ReadStartedHandler ReadStarted;
// the call of the event processing
protected virtual void OnReadStarted() {
if (ReadStarted != null) {
// we use empty eventargs because nothing is needed on readstarted event, just the confirmation of parsing started
ReadStarted(this, EventArgs.Empty);
}
}
Import CSV file and query it with LINQ
Feb 4th
Assume that you have an plain text, old Comma Separated Values file filled with your precious export from a legacy system. How can you process it easily now? The first answer that comes to mind is to parse it and load it into a datatable and later process it by using DataTable.Select() method. But this approach has some limitations – like splitting data into several tables and then join them.
One would imagine that parsing CSV files is a straightforward and boring task, given that it is quite a while since CSV is around. Some of them are correct – in the sense that many implementations merely use some splitting method like String.Split(). Some don’t even offer the specification of the values splitting character – so your file wouldn’t be parsed correctly if instead of , you have ; as separator – yet another thing to modify if you’re lucky enough to have the sources. Others will not handle properly field values with commas because the simple split method of the String class. But there are better implementations that take care about escaped quotes, trimming spaces before and after fields and other small and useful details, but very few that I found did it all as I liked it – and at least as importantly, in a fast and efficient manner.
MIX09 Scott Hanselman’s FILE|New Project …
Mar 22nd
Scott Hanselman had a presentation at Mix 09 conference – File | New Company: Creating NerdDinner.com with Microsoft ASP.NET MVC. This was in its unique style – fun, rich in content, tricks, advices but most of all was fun.
This year he managed to create a new type of presentation – without the actual presentation! No more constrained to some slides, just him, Visual Studio and the audience. Yes, the audience – who seemed to absorb any words spoken there, helping Scott with few advices in some key points.
PDC 2008 – Developing Applications Using Data Services
Dec 1st
This presentation, is done by Mike Flasko, Program Manager at Microsoft Corporation. Smart, well prepared and having good oratorical skills, he is one of the best presenters that I have listen to. He has several other blogs, interesting to see is also this one. He leads the Astoria team which has an interesting blog here.
For all of us who didn’t had the pleasure to go to the actual event, the link is on Channel 9 PDC area. Maybe next year we’ll shake hands with Mr. Mike Flasko.
Here are some of the things presented (this listing is just a teaser, you should discover the rest) :
- New models for communication