blog.mha.dk
The on-line blog of Michael Holm Andersen

ASP.NET Viewstate Viewer add-on

Wednesday, 30 November 2011 10:23 by mha

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.

Categories:   ASP.NET | Tools
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Clean copy of LinqToSQL Entity object

Monday, 28 November 2011 09:53 by mha

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;
    }
}
Categories:   C# | LINQ
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Using Apple Keyboard on Windows 7 / mapping keys

Friday, 18 March 2011 19:56 by mha

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

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (3) | Comment RSSRSS comment feed

Using LINQPad to test your LINQ to XML queries

Sunday, 6 February 2011 12:55 by mha

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

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

FireShot – capture, draw and add text

Thursday, 20 January 2011 08:15 by mha

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/

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Looking at ASP.NET MVC 3

Monday, 17 January 2011 09:51 by mha

I’m in the process of re-writing www.aspnethotel.dk to use ASP.NET MVC 3 and are planning to use the new view engine (“Razor”). For more info about this, take a look at http://www.asp.net/mvc/mvc3

Categories:   ASP.NET MVC
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Webshop launched

Thursday, 21 October 2010 15:21 by mha

The new B2C edition of our games and movies shop, located at http://www.mbc.dk/ is finally online.

The site is built using Visual Studio 2010, ASP.NET 4.0, Webform Routing, LINQtoSQL, jQuery and various other technologies.

The system uses LINQtoSQL as ORM and a custom build Repository on-top to handle all data access/business logic. A quick look at the DBML reveals a rather complex database schema as we exchange a lot of data with our ERP system (Axapta).

dbmlGW

The Solutions currently consists of 9 projects in total: 7 class library and 2 websites.

vsgw

The frontend website (webshop) uses Webform Routing to achieve SEO friendly URLs

frontgw

The backend website controls the all the frontend webshop’s (it’s possible to run multiple webshops on the same backend), data exchange with Axapta, CMS, CRM etc.

backendgw

.. it’s been lot’s of fun to build the system from the ground up (I started with a completely ‘clean plate’), and are now working on the B2B website.

Categories:   ASP.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (2) | Comment RSSRSS comment feed

301 Redirects on IIS7 – come again Microsoft!!

Friday, 10 September 2010 14:15 by mha

Creating a 301 Redirect in IIS7 is EVEN MORE CRAPPY than on IIS6 – I was going “nuts” trying to find out why my 301 Redirect didn’t work.

What I wanted to do (a pretty common scenario) was to redirect traffic from my URL without www to the www.somethinggoeshere.dk version of my domain name – however this (one should think!) simple task is not easily done!! Here’s how to do it:

You have to create a new website (one could wonder why it’s not possible simply to add e.g. 301 Permanent headers to a host name and in this way quickly be able to add a list of URLs which would be 301 redirected) – when creating the website you HAVE to enter a Physical Path when creating the site. The wizard forces you to pick a path even if you plan to redirect the site to a URL.

The most obvious would be to pick the root folder of the site you plan on redirecting to, however this (why, Microsoft?) caused an error for both sites due to a continuous redirection. You have to create an empty directory for the site you want to redirect, which makes no sense at all (why does the directory matter when all I want to do is make a 301 permanent redirect).

This ought to be MUCH SIMPLER if you ask me!

Transfer files from HTC Desire to PC using WiFi

Saturday, 28 August 2010 16:03 by mha
wifitransfer

You gotta love the HTC Desire :-) .. Transferring files to / from the device to Vista or Windows 7 is as easy as:

  1. Connect your Desire to your WiFi network
  2. Download EStrongs File Explorer from Marked
  3. Create a share on your PC, for easy access give “everyone” modify access
  4. Launch EStrongs File Explorer on phone and choose “LAN” and enter your username and password – your Desire is now connected to the share on the PC
  5. On the phone (in EStrongs File Explorer), choose “Local”, select some files and choose copy. Change the view to “LAN” and choose paste.


The files from your HTC Desire is now copied to your share on the PC using WiFi – of course you can also transfer from PC to Phone :-)

Categories:   Mobile | Tools
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Off topic: Making of the Korean Actress "Song Hye Kyo"

Thursday, 26 August 2010 19:00 by mha

As some of you may know I have a past making/teaching 3D computer graphics – so I just had to mention this, and show how far 3D has come in its pursuit of creating realistic 3D imagery:

3d_final_large

100% 3D computer generated using Zbrush and 3DSMAX– WOW!! – See the image in hi-res here: http://www.cgarena.com/freestuff/tutorials/max/songhyekyo/final_large.jpg

You can read the “making of” story here: http://www.cgarena.com/freestuff/tutorials/max/songhyekyo/

Categories:   Misc.
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed