mha.dk

Random thoughts of wisdom - the personal blog of Michael Holm Andersen

Going to TRSAC (once again!)

Phew! – Time goes fast!!

Once again I will be attending TRSAC together with Kim and Ruben (of litewerx), plus many other geeks from “the good old days”. If you get a chance be sure to check out TRSAC – as they say on the website: “The party was founded as a reaction to the lameness of The Party in the late 90s”.

The great thing about TRSAC is that it’s almost entirely “real geeks” (aka NOT gamers!), who are very crafted in the art of programming, producing music, making computer graphics, drawing etc. – and most of the people attending the party are working within the field on a professional basis.

Free eBook from Microsoft - Introducing Windows Server 2012

Microsoft of course would like us all to upgrade to Server 2012 as soon as possible, so they have released a free eBook about the newest edition of Windows Server. The book is available in PDF, MOBI and EPUB:

http://blogs.msdn.com/b/microsoft_press/archive/2012/06/04/free-ebook-introducing-windows-server-2012.aspx

More than 100 TechEd 2012 Hands-On Labs available online

Microsoft are putting the most popular TechEd North America Hands-On Labs available online. To get your hands on this information, head over to the TechEd website and sign-in with your myTechEd account (the Labs can be found in the TechEd Content Catalog) - TechEd Hands-On Labs (myTechEd)

If you don’t have a myTechEd Membership, it’s free to create one and you will gain access to 2011 and 2012 recorded sessions.

C# and LINQ. Extension methods overview

Found an awesome article (serie) about C# – part 3 discussed C# and LINQ and contains a detailed description of the different extension methods used in LINQ – a “must read” article:

http://www.codeproject.com/Articles/383749/How-does-it-work-in-Csharp-Part-3-Csharp-Linq-in-d

See you at TechEd Orlando !!

Phew .. again – way too long since last update!

Anyhow - I’ll be going to TechEd in Orlando this year – so if you’re going feel free to contact me, and maybe we can enjoy a cold beer after the sessions.

I also found a couple of nice link collections today:

.. and looking for a cheap, cool mockup software – I’ve decided on http://www.balsamiq.com/products/mockups

ASP.NET Viewstate Viewer add-on

If you’re a ASP.NET (WebForm) web developer and you worry about Viewstate (which you should!) – you might find this Firefox add-on very useful:

https://addons.mozilla.org/en-US/firefox/addon/aspnet-viewstate-viewer/?src=api

The add-on displays the viewstate of the current ASP.NET page in the statusbar – very handy when trying to limit the Viewstate size.

Clean copy of LinqToSQL Entity object

Often you need to make a copy of a LinqToSQL (Entity) Object with all the values intact. For some reason the .NET framework does not have a method for this.

However the below code will make a “clean copy” of a LinqToSQL object.

// Instanciate new object and copy all properties from old Bill ("clean" copy)
Bill billNew = (Bill)Entity.Copy(billOld, new Bill());

And the method actually doing the work, looks like this:

public static class Entity
{
    /// <summary>
    /// Copies an LinqToSQL entity object ("clean" copy)
    /// </summary>
    /// <param name="source">Source Entity object</param>
    /// <param name="destination">Destination Entity object</param>
    /// <returns>Destination Entity object with all properties copied from Source object</returns>
    public static object Copy(object source, object destination)
    {
 
        System.Reflection.PropertyInfo[] sourceProps = source.GetType().GetProperties();
        System.Reflection.PropertyInfo[] destinationProps = destination.GetType().GetProperties();
 
        foreach (System.Reflection.PropertyInfo sourceProp in sourceProps)
        {
            ColumnAttribute column = Attribute.GetCustomAttribute(sourceProp, typeof(ColumnAttribute)) as ColumnAttribute;
 
            if (column != null && !column.IsPrimaryKey)
            {
                foreach (System.Reflection.PropertyInfo destinationProp in destinationProps)
                {
                    if (sourceProp.Name == destinationProp.Name && destinationProp.CanWrite)
                    {
                        destinationProp.SetValue(destination, sourceProp.GetValue(source, null), null);
                        break;
                    }
                }
            }
        }
 
        return destination;
    }
}

Using Apple Keyboard on Windows 7 / mapping keys

Today I bought a new keyboard for my Windows PC. I’ve been considering buying an Apple Keyboard for quite a while for a couple of reasons:

1) The keys are really nice to use for a long period of time
2) It looks really nice!
3) It does not take a lot of space on my desk
4) It has build-in USB hub
5) It has a nice “laptop” feel to it (and is almost totally flat)

The keyboard is plug-n-play with Windows 7 (and Vista), so no problem there, however - since I’m not a Mac user - I had to re-map some of the keys on the keyboard to fit Windows 7 usage.

I used a program called “SharpKeys” which can be found at CodePlex here: http://sharpkeys.codeplex.com/

It’s really easy to use and all settings are written to Registry (so no programming will be running trying to “catch” your input, Windows supports re-mapping).

Below is a screenshot of which keys I have chosen to remap:

MHAsharpkeys-mapping

The names are pretty easy to figure out, however the 00_67-00_6A is Function key F16-F19. Of course I choose to swap the Macs “cmd” key and Alt in order to have the “Windows” key positioned correct (left) and for the right side of keyboard the "Alt Gr” key is also swapped into it’s correct location (“pc style”).

By the way .. the danish version of the keyboard look like this:

AppleKeyboardDK

Using LINQPad to test your LINQ to XML queries

If you’re a LINQPad user you’re probably used to query your DBML (LINQ to SQL), but did you know that you can also use it for LINQ to Objects, LINQ to XML etc.

A simple example of how to do a query against a XML file (make sure language is set to C# Statements):

var xml = XElement.Load (@"c:\\inetpub\\GWportal\\src\\wwwBackend\\App_Data\\axCache\\
   GWDK\productprice-mha.xml");

var query =
  from e in xml.Descendants("unittransaction").Descendants()
    where (e.Attribute("name").Value == "ItemRelation" && e.Value.Equals("10020"))
  select e.Parent;
 
query.Dump();

Which gives this result:linqtoxml

FireShot – capture, draw and add text

If you’re like me you find yourself doing quite a bit of screen capturing (to show clients what you mean, to include in bug reports etc.).

snippingtool
As a Windows 7 user I’ve been using the Snipping Tool for while and find the annotation features (being able to draw and highlight) really nice, however for some reason the tool does not have a “Insert Text” option (or the ability to print).

However if you’re screen capturing browser windows and have FireFox installed (which you should), then you might want to take a closer look at FireShot, which is a really useful (free) AddOn which let you capture the content of the entire browser window, and have features to draw shapes/lines, add text etc. as the below screencapture shows:

fireshotcapturing

To download FireShot, navigate your FireFox browser to: https://addons.mozilla.org/en-US/firefox/addon/fireshot/