Wednesday, March 25, 2009

Missing IEnumerable<T>.ForEach(Action<T> action)

Have you ever wanted to code something like this in .NET 3.5:
var repository = new CustomerRepository();
repository.Customers.ForEach(customer => Console.WriteLine(string.Format("Customer: {0} {1}",
customer.FirstName, customer.LastName)));
Console.Read();
Where Customers is of type Collection. Well you can't out of the box as the framework doesn't provide an extension for IEnumerable foreach (which is what Collection implements).

The Repository and domain object in the above case looks like this:
public class CustomerRepository
{
public CustomerRepository()
{
Customers = new Collection<Customer>()
{
new Customer()
{
FirstName = "Simon",
LastName = "Hart"
},
new Customer()
{
FirstName = "Joe",
LastName = "Bloggs"
}
};
}

public ICollection<Customer> Customers
{
get; set;
}
}

public class Customer
{
public string FirstName
{
get; set;
}

public string LastName
{
get; set;
}
}
You can make the above call work with this simple extension for IEnumerable:
public static class GenericIEnumerableExtensions
{
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
{
foreach (var item in collection)
{
action(item);
}
}
}
It's quite simple in that it accepts one parameter, an Action delegate with one parameter - this could be extended to do whatever you want. Although the above is in line with the List.ForEach extension method.

The benefit of this is it simply reads better with less code.

You might find this library found on codeplex useful: http://extensionmethodsyay.codeplex.com/

Wednesday, March 18, 2009

Mobile Application Architecture Guide

The p&p team at Microsoft has put together this document on Mobile Application Architecture best practice. You can find it here on codeplex: http://www.codeplex.com/AppArch/Release/ProjectReleases.aspx?ReleaseId=19798

I am currently putting together a solution that I plan to write an MSDN document detailing many of these technologies referenced in the document - some of which do not exist for mobile devices. This solution contains all the cool new stuff like, object relational mapping, Inversion of control, dependency injection, crosscutting inteceptors, domain driven design and how to achieve this in a mobile application. The latest UI controls in the market place. The repository data pattern. .NET CF 3.5, LINQ and lambdas - when to use them. Test driven development using MSTEST for devices.

I will post the link here when done.

Monday, March 09, 2009

Microsoft Recite Technology Preview



There is a lot of cool stuff coming out of Redmond lately and Microsoft Recite is no exception.

Microsoft Recite is a tool that allows you to verbally record your thoughts to aid you to remember things, then retrieve them by asking (voice recognition) Recite for the content using any of the phrases in the recorded message.

Recite is supported on these devices:

AT&T BlackJack II
AT&T Pantech Duo
HTC Diamond
Moto Q9m
Palm Treo 800w
Palm Treo Pro
SMT 5800
T-Mobile Dash
T-Mobile Shadow
T-Mobile Wing
Motorola Q9C


Checkout a video of Recite in action here: http://recite.microsoft.com/Pages/ReciteVideo.aspx
Get it here: http://recite.microsoft.com/Pages/download.aspx

I am unaware of any Recite managed SDK at this point.

Microsoft TechDays Developer 2009 - 24hr Virtual Event



On April 1st 2009, be part of Microsoft history and join developers all over the world for the first ever 24-hour day of technology learning.

Participate in 95 live sessions anywhere, at anytime or on-demand at your convenience.

It is a free event.

To register for this event, click here: http://www.msfttechdays.com/public/home.aspx

To view the sessions, click here: http://www.msfttechdays.com/public/sessionlist.aspx

Microsoft are still calling for content so not all sessions are visible. Also you will be able to build you're own schedule in due course.

I'm not aware of any mobility tracks as yet, but my best guess is there will be some.

I'm a PC and I'm an MVP!

The MVP version of the "I'm a PC" video (from the MVP summit 2009):


Wednesday, March 04, 2009

Broadband Speed test - South East England

I recently changed ISPs for my home network. I now use O2 (in UK) O2 bought Be Un Limited a while back. I was on Sky - Sky bough Easynet a few years ago. Sky was very slow and unreliable.

The upload bandwidth was almost no-existent. Experience playing on-line games was not much fun due to the lag. You need good upload bandwidth for playing on-line games successfully otherwise you just get slaughtered.

I used http://www.speedtest.net to measure the speed of both networks. As you can see, it is a big difference between the two networks. Also notice the ping response differences.

Anyone else in my area, Guildford, South East England who is on Sky should consider O2.

Here are the results:


Sky Easynet (before)


O2 (Be Un Limited)

I am around 5 miles from the BT exchange.

Tuesday, March 03, 2009

IoC framework for the Compact Framework

Andy Wigley mentioned the other day the p&p team has released a series of blocks for the Compact Framework including a dependency injection framework called ContainerModel. So I decided to have a look.

You can get the code from codeplex here: http://www.codeplex.com/Mobile

It is based on the MCSF but for .NET CF 3.5.

I have had a look at the IoC framework and it is pretty good but would be even better if it had support for configuration files (XML). So currently you have to code something like this:
builder
.Register<IEditCustomersView>(
c => new EditCustomersView())
.InitializedBy(
(c, v) => v.Presenter = c.Resolve<EditCustomersPresenter>());
Then you can code this:
var view = ApplicationRoot.Container.Resolve<IEditCustomersView>();
This is a first cut so maybe we will see support for configuration files in the future. If I get time I'll add support for it.

It's quite cool as you can pass in an Action delegate at the time of register to instantiate the class.