Thursday, November 05, 2009

I've had a few questions regarding uninstalling Windows PowerShell 1.0 on XP to make way for PowerShell 20. It's actually quiet simple although not immediately obvious. PowerShell doesn't show up under Add/Remove programs as it's counted as a Windows update so follow these steps it you want to uninstall it.

    1. Click Start -> Run
    2. Type appwiz.cpl and press enter
    3. Windows PowerShell will not show up in the list of programs as it is counted as a windows update, you must click the tick box "Show updates"
    4. Scroll down and look for "Windows XP - Software Updates"
    5. Underneath the Windows XP -Software updates entry is a list of all updates that have been applied to you machine scroll through the list and you will find an entry call "Windows PowerShell(TM) 1.0"
    6. Click the "Remove" button to begin uninstalling PowerShell 1.0

 Screen showing Add Remove PowerShell

 

You can find more details on this in the Microsoft knowledgebase at:  http://support.microsoft.com/kb/926139

posted on Thursday, November 05, 2009 8:33:13 PM (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [2]
 Wednesday, November 04, 2009

Getting a string value for an enum value is a common problem and there's a few solutions knocking around the Internet, however a few of these that I've seen end up having a utility class that handles mapping the enum value to the relevant string value, this is fine but I think this is an operation that should be callable on the enum value without having to go off and use another class. The solution I have here provides this functionality using extension methods that are available in .Net 3.5.

The first thing I did was to create a new attribute that will be applied to the enum values when they are declared so a string value can be specified for each enum value such as is shown in the code snippet below:

 

public enum 
{
    [StringValue("Red")]
    Red = 0,
    [StringValue("Blue")]
    Blue = 1,
    [StringValue("Green")]
    Green = 2
} 


The code for the attribute class is:

public class StringValueAttribute : Attribute 
{ 
    public string StringValue { get; private set; }

    public StringValueAttribute(string value) 
    { 
         this.StringValue = value; 
     } 
}

When writing the extension method we can take advantage of the fact that all enums have Enum as their base class. This allows the following extension to be defined.

public static stringGetStringValue(this Enum enumValue) 
{ 
   . . . 
}

This method is now available to be called as follows: 

Colors myColor = Colors.Red; 
Console.WriteLine(myColor.GetStringValue());

 

As the 'GetStringValue' extension method is available on all enums it leaves the possibility that GetStringValue could be called on enums that have not used the 'StringValue' attribute. To protect against this there are two options, option one would be to return an empty string and option two is to use reflection and return the name of the enum value. This was the option I choose, firstly I look for the 'StringValue' attribute if that is present the method returns that as this is the mechanism that allows the developer to take finer control of the string value. So the previous enum could be defined as follows:

 

public enum Colors 
{ 
        [StringValue("#FF0000")] 
        Red = 0, 

        [StringValue("#0000FF")] 
        Blue = 1, 

        [StringValue("#00FF00")] 
        Green = 2 
}

Likewise the enum could be defined as shown below and we would get the values 'Red', 'Green' and 'Blue' when using the 'GetStringValue' method.

public enum Colors 
{ 
        Red = 0, 
        Blue = 1, 
        Green = 2 
}

Here is my implementation of the extension method: 

public static string GetStringValue(this Enum enumValue) 
{ 
    Typetype = enumValue.GetType(); 
    FieldInfo fieldInfo = type.GetField(enumValue.ToString()); 

    StringValueAttribute[] attribs = fieldInfo.GetCustomAttributes( 
        typeof(StringValueAttribute), false) as StringValueAttribute[]; 

    if(attribs.Length > 0) 
    { 
        return attribs[0].StringValue; 
    } 
    else 
    { 
        return fieldInfo.Name;  
     }  
}


I've a prebuilt DLL so all you need to do is download this and reference it in your projects making sure to include the namespace 'Gangleri.Enums' when you wish to use the extension method or the StringValue attribute.

DLL: http://enumstringvalue.googlecode.com/files/Gangleri.Enums.dll.zip
Source Code: http://code.google.com/p/enumstringvalue/source/checkout

posted on Wednesday, November 04, 2009 9:13:16 PM (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [1]

If you've got an account that uses Google mail you have got to try out the Gmail Notifier Plus app as it looks so good on Windows 7. Just look at the Jump Menu for the app. At a glance you can see how many new items are in your inbox and gmailNotifierPlusJumpMenu most recent 10 have their subjects listed on the Jump menu so that you can go directly to any of them with a single click. Also from the tasks section you have the option to compose a new mail or go to your inbox, both of these options will open a browser with the selected page displayed.

Another very nice feature of the app occurs when you mouse over the icon on the Windows 7 task bar. You get a small preview window that allows you to step through your mail and read the first few lines from each and for convenience you have the ability to open the full email in your browser.gmailNotifierPlusMouseOver Trust me if you have a Google mail account you want to check this little app out as it makes it so easy to work with your gmail.

posted on Wednesday, November 04, 2009 1:52:55 AM (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [1]
 Friday, October 30, 2009

windowsDiscImageBurner ImgBurn has always been a great solution for burning iso images on the Windows platform but with the final release of Windows 7 we now have "Windows Disc Image Burner". This allows you to simply right click on an iso file and select "Burn disc Image". This is a very simple program that does one thing and one thing only, burn your iso to a CD or DVD. ImgBurn still has the advantage of providing more features but if all your looking to do is burn an iso image to disc the built in functionality is more that sufficient.

posted on Friday, October 30, 2009 8:37:57 PM (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [0]
 Thursday, October 29, 2009

I've been doing some work with the Unity IoC container recently and had to configure some generic types so I thought I'd post some of the examples here so that I'd have some to refer back to more than anything else a blog post tends to be less likely to get lost that an old post-it note.

Xml config to configure mapping for a specific generic type, note the use of [[]] to define the generic type. Inside the square brackets you specify type name and the assembly containing the type. In both example `1 signifies the generic parameter:

<type type="Data.Repository.IRepository`1[[Poco.Address, Poco]], Data.Repository"
      mapTo="Data.Repository.LinqRepository`1[[Poco.Address, Poco]], Data.Repository">
  <lifetime type="singleton"></lifetime>
</type>

Xml config to configure open generic type mapping:

<typeAlias alias="IRepository`1"            
           type="Questern.ActiveOrderManagementSystem.Data.Repository.IRepository`1, 
Questern.ActiveOrderManagementSystem.Data.Repository
" /> <type type="IRepository`1" mapTo="Questern.ActiveOrderManagementSystem.Data.Repository.LinqRepository`1,
Questern.ActiveOrderManagementSystem.Data.Repository
"> <lifetime type="singleton" /> </type>

 

Thanks to Marceli for helping out with this!!

posted on Thursday, October 29, 2009 7:52:26 PM (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [1]