05 March 2009

Copy DataTable to clipboard with an extension method

Finally I had an opportunity to create an extension method that I think could be useful to some devs out there, here under you can see (and copy) the code that inserted in your project allows you to then use something like:


dataTable.CopyDataToClipboard();


I looked for something easier and maybe .NET had already built-in; I couldn't find it (could be I was just lazy-searching) and so ... here it is.


public static class DataTableExtensions
{
public static void CopyDataToClipboard(this DataTable dataTable)
{
var sb = new StringBuilder();

for (var i = 0; i < dataTable.Columns.Count; i++)
sb.Append(dataTable.Columns[i].ColumnName).Append("\t");
sb.AppendLine();

foreach (DataRow row in dataTable.Rows)
{
for (var i = 0; i < dataTable.Columns.Count; i++)
sb.Append(row[i] ?? string.Empty).Append("\t");
sb.AppendLine();
}

Clipboard.Clear();
Clipboard.SetText(sb.ToString());
}
}

14 November 2008

Am I working too hard?

Take a look at the picture ....



Am I working too hard?!

23 June 2008

Preferred programming books so far ...

When you start freelancing you need to build your customer's base and you find yourself having more time to study and read. I just finished reading "Code Complete", by Steve McConnell, and having found it a really EXCELLENT book (that I recommend to every developer) I though to put here the list of the books I enjoyed the most.

Each one of these books gave me a new or different view of the various aspects involved in our profession, I hope this list will help the growth path of somebody else like they did with mine.




The Mythical Man Month and Other Essays on Software Engineering
Amazon links:






The Pragmatic Programmer
Amazon links:






Code Complete: A Practical Handbook of Software Construction

Amazon links:






Peopleware: Productive Projects and Teams

Amazon links:






Design patterns : elements of reusable object-oriented software

Amazon links:






Refactoring: Improving the Design of Existing Code

Amazon links:






Software Estimation: Demystifying the Black Art: The Black Art Demystified

Amazon links:






UML Distilled: A Brief Guide to the Standard Object Modeling Language

Amazon links:



12 June 2008

Jetbrain Partnership (ID: 43762) - Resharper

I'm pleased to say that I've just entered the JetBrains Partner Program, it's a pleasure to be involved in the promotion of this terrific tool for developers.

I therefore I'm available for suggestions, tips and other informations.

I can also help you have some benefits with your licence. For example if you
drop me an email I can let you have a key for an evaluation period of 60 days,
but there are also other promotions I can help you with...

If you are interested just drop me an email
(first part: patrickriva domain: gmail.com).


ENJOY!





I can help you with the following Jetbrains products:

ReSharper 4.0 Full Edition Commercial License
ReSharper 4.0 Full Edition Personal License
ReSharper 4.0 C# Edition Commercial License
ReSharper 4.0 C# Edition Personal License
ReSharper 4.0 VB.NET Edition Commercial License
ReSharper 4.0 VB.NET Edition Personal License

09 June 2008

Error/event IDs and failure codes are not enough!!

I'm using Windows Vista since March, and despite the many criticisms I heard about it I can say that I am (was?) quite enjoying it, very good stability, and the UAC is not so annoying for me as other people say.

The "was?" in the previous sentence is because I had a problem with the OS last week: suddenly, without any minimal change in the OS, the internet dial-up connection didn't work, and so I had to get in touch with Microsoft technical support to fix it, since every damn uninstall/install or configuration hack I tried didn't work. Moreover looking for the error codes on Google gave me just a handful of results (Google search) that didn't provide any fix or hint about possible actions.

I never needed to call the official support for a Microsoft OS, but this time I had few choices: either try with a format/install (where install is the install of the OS, office apps, VS, Resharper, etc etc etc!!!) or call the support, give them the bunch of IDs I had in my hands and ask what dll/reg key to modify in order to resolve the problem.

I did my bit, I was able to see that every time I tried to connect an error event was generated by the RasClient, with ID: 20227. Moreover in the details there was always the same description ending with "the error code returned on failure is 31".
Having a so precise description of the problem I was thinking 'It's going to be 10 or 20 minutes, they'll lookup for the codes, send me a couple of dll to replace or a tell me the registry keys I need to correct and it's done' ...

Well, it wasn't exactly so, in order to solve it I went through the following fix-trials suggested by the support:
- alter a couple of keys in the registry + reboots
- remove antivirus + uninstall modem sw + install modem sw + reboots
- remove SP1 + uninstall modem sw + install modem sw + reboots
I let you guess how much time that took.

I was finally given a procedure to try that did work ... perform an in-place upgrade of Vista!.
Yes, I had to reinstall the system on itself! Many hours of work gone, but at least I was able to have my modem working again and the in-place upgrade took care of keeping all the registry setting of the installed applications and avoided me days of extra installations.

But why do you need to go through all that when you have a module name an event id and a description of the failure? Shouldn't it be possible to replace only the more specific dlls the module is relying on? Should the support people have access to the event id documentation and/or source code to give a better explanation of a problem?








p.s. a very long time from the last post innit?! The reason is going to have it's second birthday next month! :)

18 January 2007

Power tools: ReSharper, definitely the most intelligent add-in to VS

O'Reilly has invited developers (here) to blog about their favourite tools, the "ones you couldn't do without" and so I felt I own this to the JetBrains' guys and I'm giving all .NET developers (especially C# ones) a sincere advice:


try ReSharper and I'm sure you'll too find it wonderful.



ReSharper has not only very good refactoring features (this days refactoring has become a quite common feature and in VS 2005 it's delivered "in the box") but it has also a couple of things that really makes your life easier: real-time error checking, extended code completion and unit testing integration.

Real-time error checking

When you use Word you like to have your typos underlined in red as soon as you write them? if the answer is yes well you'll simply love ReSharper when it will highlight the code that will throw some compiler error as soon as you complete it (and some times it'll suggest too a resolution and apply automatically for you if you want!).


Extended code completion

ReSharper offers you a customisable and really efficient code completion, you can have brackets added automatically or not, you can complete class names that belong to assemblies not yet referenced by a using statement (and if you decide to use one class in that assembly ReSharper will add that statement for you), or you can use an intelligent completion that will try to guess which variable name or parameter you are going to write evaluating the type expected in that point).


Unit testing integration

ReSharper finally offers a very cool integration with Nunit and csUnit (I'm using the first one) so that your tests are just a couple of click away when you have the test code opened in the editor.


Just try it, and you'll love it.






Disclaimer: I've not received any money, gift, free licence or discount to write this blog entry. I'm currently using a licence of ReSharper regularly bought by my employer at the standard price.

08 January 2007

Strange internal links in Windows XP!

Yesterday I run into a really, really .... really strange problem with a PerformanceCounter object on a .NET application developed more than one year ago, and that since then has been in production without any problem.

I opened the application solution with VS and then as a first thing I tried to run it, but I received an error on a Performance counter that was there to monitor the processor usage.



PerformanceCounter pc;
pc = new PerformanceCounter("Processor",
"% Processor Time",
"_Total");


The error was something like this:

System.InvalidOperationException: Category does not exist.
at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
at System.Diagnostics.PerformanceCounter.Initialize()
...


and I spent quite a while trying to find the reason of it. Only after one hour of so of searching I came across a document talking about a Missing Processor Performance Counter which at some point talks about the page file, and there the light was back on! A few weeks ago I disabled the page file to speed up my laptop and probably that's the reason now I received that error. In fact re enabling the swap file makes the error disappear, disabling it makes the error come back ...

Ok now the point is, where is the link between a processor performance counter and the page file? (My only explanation is that the function measuring the performance of the processor is so tied up with the function measuring the performance of the page file that is hard to run the first if the second has to be disabled, but ... come on can that be true?)

Anyway reading more carefully the messages in the previous link I found a Microsoft support page with the title Some performance objects and counters are not available in the System Monitor tool on your Windows XP-based computer [Article ID: 884558]. It confirms the problem is linked to the disabled page file and gives a link where is possible to get in touch with Microsoft support to require a patch.