Saturday, October 30, 2010

Free Not For Resale MSDN Subscription up for grabs!!





I have in my possession a Not For Resale Visual Studio 2010 Ultimate with MSDN Subscription, and it's up for grabs. Like all other Microsoft MVPs I had 3 to give away, I have given away 2 already but now I have just 1 left.

So I can't think who to give it to as the two lucky people that received this free subscription were the only ones that I know of who wanted to get into programming or wanted to move to Visual Studio 2010 and the 2010 wave of Microsoft products. Most of the people I know receive Visual Studio 2010 as part of their corporate MSDN licence provided by the company they work for.

I thought about who to give this to and I couldn't really think of anyone that I thought really derserves it. So instead I took an idea from what some other MVPs have been doing and that is to present a challenge to the community and the best or the right answer wins the MSDN subscription! That's fair don't you think...


The Challenge

As I am passionate about Technical Architecture and good clean code and the fact I have done lots of code reviews in my career, I thought the challenge could be around best coding practice or the best example of clean maintainable easy to understand code.

So the challenge is really: write an application for the new Windows Phone 7 Series device using the new free tools (Visual Studio 2010 Express with Windows Phone 7 Series) that promotes good architectural design.

The things I'm looking for and this will greatly increase your chance of winning are as follows:

  1. Good OO, pay attention to the single responsibility principle. No procedural code
  2. Code must be maintainable
  3. Easy to understand
  4. Good system design patterns such as, command, MVVM, MVP, repository etc
  5. Good code coverage (doesn't need to be 100%) but if used will make achieving 1, 2 and 3 on this list a lot more likely
  6. You'll get extra marks if you make use of the IoC container I checked in to codeplex: http://wp7.codeplex.com/ - note that project is targeting the Beta tools of Windows Phone 7, I haven't got round to updating it yet but it should work with the RTM release of Windows phone

So..... the ultimate question you're probably asking is, what application should you write? well it doesn't matter. It could be an application as simple as a calculator to something that makes use of networking or Windows Azure for example. The person that wins this will be win it based on good architecture code design.

You've got until Tue 26th November to get something to me to review. Then I'll announce the winner before the end of November. The subscription does expire soon which is why I'm only giving about 3-4 weeks to do this.

Send submissions to simon (at) simonrhart (dot) com. If you have any questions then leave a comment on this post.

Happy coding!!

Friday, October 22, 2010

TFS 2010 Backup Power Tool - Grant Backup Plan Permission Failed

Now that TFS Power Tools has been released we can take advantage of the Team Foundation Server Backup feature that makes backing up TFS so much easier than it used to be.

The TFS Power Tools contain tools client side too, it's just the backup feature is designed to actually run on the TFS server itself.

It supports backing up not only all your collections but also your Reporting Server database (if using SQL Server Reporting Services integration) and your SharePoint databases if using MOSS for enhanced reporting. It works very much like the standard Windows Server Backup utility that is shipped with Windows Server 2008 R2.

You have an option specify how many copies of the backup to keep. You have to backup to a network location. You can't backup to local disk like you can with Windows Server Backup. This tool is designed to worry about backing up TFS so you don't have to.

The tool integrates with the Team Foundation Server Administration Console. So you create a backup plan from within there. You can specify when the backup should run i.e. daily, weekly, time of day etc. It can run under a domain or local account to.

There are a few articles out there that step you through the process of setting this up so I'm not going to do it here. Instead I came across a nice "issue" with it when setting it up that I thought might save other people time as I burnt quite a bit of time on this. Here is a very good example of this: http://myalmblog.com/2010/09/12/tfs-2010-power-tools-tfs-backup-and-restore-hands-on-lab/

So my issue was when getting to the end the readiness checks were failing with the Grant Backup Plan Permissions step. Which was weird as I had write access to the UNC path to which the backup was writing. The other strange thing was I discovered a file in the UNC path after running this readiness check.

After investigating further and looking at the log file (snip copied here) I figured out what was wrong:
Error  @15:35:29.014] System.UnauthorizedAccessException: Access to the path '\\server\backup\TFSBackups\Tfs_Configuration_20101022163528.bak' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at Microsoft.TeamFoundation.PowerTools.Admin.Helpers.BackupFactory.TestBackupCreation(String path)
[Error @15:35:29.060] !Verify Error!: Account DOMAIN\user failed to create backups using path \\server\backup\TFSBackups
[Info @15:35:29.060] "Verify: Grant Backup Plan Permissions\Root\VerifyDummyBackupCreation(VerifyTestBackupCreatedSuccessfully): Exiting Verification with state Completed and result Error"
[Info @15:35:29.060] !Verify Result!: 5 Completed, 0 Skipped: 4 Success, 1 Errors, 0 Warnings
Notice what it is doing yet!? It basically writes a file to the UNC path to check for write permissions - BUT not as the service account, it uses the current logged on user account (this is a bug I'm sure). But what is failing is actually the deletion of the file.

Because of this the readiness checks fail and you can't continue. After looking at the permissions (or should I say IT looking at the permissions) it turns out I didn't have Delete permission for the current logged on user for that UNC path. Once setting the Delete permission to true, the problem went away and now I have a successful backup plan in place!

Tuesday, October 19, 2010

Power up failed (vrc=VERR_VMX_MSR_LOCKED_OR_DISABLED, rc=E_FAIL (0X80004005))

I recently tried to use VirtualBox to run a Virtual Machine on my new laptop which is a HP EliteBook 8530w. But after attempting to start the VM I encountered the following error: Power up failed (vrc=VERR_VMX_MSR_LOCKED_OR_DISABLED, rc=E_FAIL (0X80004005))

So as per the return code, this is telling me that VT-x is either locked or not enabled. It can't be locked as this is running on Windows 7 which does not have any other virtualizer running, i.e. VirtualPC or Hyper-V. It is enabled as I explicitly set virtualization in the BIOS. It turns out that I needed to also enable Txt Technology. Once Txt Technology was enabled, the VM fire-up! nice

I am not normally a VM person, but my new laptop is a beast. 8Gb of RAM so I can allocate 4Gb to the VM and it runs like a host OS.

Monday, October 18, 2010

The File AssemblyInfo.Cs could not be found within the project templates. Continuing to run, but the resulting project may not build properly.

Today after installing Visual Studio 2010 on a fresh copy of Windows 7 Enterprise, I encountered the following error message whenever I tried to create a new project using any project template: The File AssemblyInfo.Cs could not be found within the project templates. Continuing to run, but the resulting project may not build properly.

I think this may be due to the fact I accidentally installed a pre-release version of ReSharper 5.1 (I was meant to install the RTM version). Even after uninstalling ReSharper the problem did not go away.

To fix the issue, I simply ran this trusty old command: devenv.exe /InstallVSTemplates

Job done.

Saturday, October 16, 2010

Arrow and Enter keys stop working in Visual Studio 2010

I found this issue with the RTM of Visual Studio 2010 recently where the arrow keys and the Enter key do not work as expected. This is a show-stopper as you can't write any code, or rather you can, you just have to write everything on 1 line!

I have 3 machines with VS 2010 installed. Each machine is fairly similar in configuration. I have only encountered this issue with 1 of those 3 machines - which makes it very hard to diagnose.

In my scenario I found the some of the arrow keys - the up key for example was acting like a tab within the code window. It would when pressed allow me to set focus on the combo box that contains classes the the current namespace.

Other people have received this issue, but the work around for them is to simply close and reload VS. In my case this didn't work. I even uninstalled all of the VS 2010 bits including the framework to no avail. This problem affected all SKU's of Visual Studio 2010 (only 2010, 2008 worked fine for me).

I should mention VS 2010 RTM used to work on this troubled machine. It must of been something I installed or configuration I changed later. I tried rolling my machine back to when I think it was working, again to no avail.

There is a bug report on Microsoft Connect here: https://connect.microsoft.com/VisualStudio/feedback/details/534869/arrow-keys-stop-working-in-editor?wa=wsignin1.0#tabs

So if you have experienced this, make sure you vote on the link above, or if you found a work around please leave a comment.

This may of been due to the fact I installed RC and beta copies of VS - as I installed pre-release copies of Windows Phone 7 developer tools. Then I installed the RM version of VS 2010 after uninstalled the pre-release versions as per the release notes.

Conclusion.....

I failed to figure out what was causing this. If I had the source code of course I could debug VS but as I don't, it was down to trial and error. I had no logging written to the event log. VS never crashed as a result of this, it is just a very annoying bug that I could not figure out what caused it.

So in the end, I had to reinstall Windows, and now.....I have VS 2010 working again!

Thursday, October 14, 2010

DiscoverServices : Failure in find service API calls : Can't find PInvoke DLL 'BTInterface.dll'.

I have been coding against the new Motorola MC65 and the Motorola ES400 - devices that will port onto the new Windows Embedded Handheld when released later this year.

I was attempting to pair with an embedded bluetooth device using the EMDK v2.3 - an EMDK that has worked on previous Motorola devices such as the MC75.

When attempting to pair using the Symbol.WPAN.Bluetooth.Bluetooth class, the device receives the pair message but then the EMDK throws ab Exception with message "DiscoverServices : Failure in find service API calls : Can't find PInvoke DLL 'BTInterface.dll'."

The stack trace looks like this:
   at ag.l(RemoteDevice A_0)
at ag.n(RemoteDevice A_0)
at ag.j(RemoteDevice A_0)
at Symbol.WPAN.Bluetooth.RemoteDevice.Pair(String AuthenticationPIN)

I can confirm, once upgrading to the latest version of the EMDK v2.4 fixes this issue (v2.04 of the Symbol.WPAN.dll assembly).

You can download the EMDK v2.4 for .NET here: http://support.symbol.com/support/search.do?cmd=displayKC&docType=kc&externalId=12874&sliceId=&dialogID=196190455&stateId=1%200%20196186434

Friday, October 01, 2010

Microsoft MVP Award 4th year in a row!

I have just received the 2010 Microsoft MVP Award in Device Application Development. This is my 4th MVP award in a row and it's an honour to be in the programme for another year.

Thanks Microsoft!

Cheers

Thursday, September 23, 2010

StyleCop for ReSharper

Last night the UK ALM user group was fantastic. I really enjoyed it and we had good discussions going. So thanks to Stuart Preston for setting it up and thanks to the speakers, Karel Deman from Avanade for a great talk and Howard van Rooijen.

Which leads me to why I started to write this post. Howard demoed a tool he built called StyleCop for Resharper.

Now if you've never heard of ReSharper - shame on you, then you can search my blog or the web for info on it. If you've never heard of StyleCop then again search the web or read this post that should give you a quick overview of what StyleCop is designed to address: http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx

Just quickly; StyleCop is a code style analysis tool. It at compile time will inspect your code against a pre-determined set of rules to determine whether your code complies with your companies coding style implicitly. The problem with it is it only tells you what is wrong with your code when you compile. And in order to get a list of "failures" you have to look at the warning tab in the 'Errors' window in Visual Studio.

When you install StyleCop: http://code.msdn.microsoft.com/sourceanalysis you get the option to install MSBuild targets that you can call during your automated build process. I haven't yet tried this but I will. As what you can do is fail the build if a developer has not complied to your companies codeing style.

Don't confuse StyleCop with FxCop or (Code Analysis) they are very different. Code Analysis inspects your assemblies post compilation for good practices in terms of how you have built your solution, i.e. implementing IDisposable when consumed types support it. Proper use of localization and best practice use of the .NET class libraries.

StyleCop for ReSharper is a ReSharper plugin (yes ReSharper supports plugins even though ReSharper is itself a VS plugin). What it does is it works like ReSharper, so as you type, it will inspect your code and tell you whether you are breaching StyleCop rules for that project. And as per ReSharper style, of hitting Alt+Enter, it gives you corrective options to fix your code for you!

I like it alot. I think it really is a great tool. Combined with the StyleCop build targets I think this can work well in a team environment. As to configuring your projects for StyleCop use, StyleCop creates a file in each project directory that it reads. It doesn't work like Code Analysis, where the settings are baked into the .proj file. So I'm thinking maybe include that file in Source Control so each dev machine doesn't have to configure their machine everytime a new environment is spun up or a new project is added to the solution.

Check it out here: http://stylecop.forresharper.org/

Tuesday, September 21, 2010

UK ALM User group

We Hitachi Consulting are hosting the next UK ALM user group at 2 More London (London Bridge) tomorrow night 22nd September.

Now I'm not sure if it is too late to register at this time, but the event brite registration page can be found here: http://ukalmug-september2010.eventbrite.com/

Thursday, September 02, 2010

No need for server side clientaccesspolicy.xml when using Silverlight for Windows phone 7 Series

If you're a seasoned Silverlight developer you'll be well aware of having to incorporate the clientaccesspolicy.xml file in the root of your service domain with a method that returns the file as a Stream object. MSDN documentation that describes that and the documentation can be found here: http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx

Then you would typically define a method that looks like the following that is accessible via a RESful call (if using WCF) - note: the UriTemplate here is what is important:
[OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
Stream GetClientAccessPolicy();
Executing any method from within a desktop Silverlight app whether in-browser or out-of-browser (SL 3 feature) will call that method above implicitly by the SL HTTP stack.

When calling any web method from a Windows phone Silverlight application, the 'GetClientAccessPolicy' is not called so there is (currently no need for it if your clients are from WP7 apps).

I'm not sure if this will change when the WP7 tools RTM on the 16th September - I will be the first to try!

My colleague Anthony Cooper found this out, so thanks to him.

Windows Phone 7 Series released to RTM

Just in case you haven't heard the news yet, yesterday Windows Phone 7 Series was released to RTM: http://windowsteamblog.com/windows_phone/b/windowsphone/archive/2010/09/01/windows-phone-7-released-to-manufacturing.aspx

Excellent work to the Windows Phone team!

So now we wait for OEMs to produce some hardware...not long I'm sure.

The tools RTM on 16th September: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/08/23/a-developer-s-roadmap-to-windows-phone-7-launch-timing.aspx

Wednesday, July 28, 2010

Building your Windows Phone 7 Series apps using Team Foundation Server 2010

UPDATE: There is a workaround to what I have said here. See this post - a really cool way to build WP7 targeting different WP7 builds: http://justinangel.net/WindowsPhone7EmulatorAutomation#BlogPost=TFS2010WP7ContinuousIntegration

So the ultimate question is, how do I build my Windows Phone 7 Series apps on TFS and perhaps run unit tests against a Windows phone 7 series emulator. The short answer is you can't, well that's not entirely true. You can build your Windows phone 7 series apps on TFS so long as you install the developer tools on your build server.

Bear in mind when you install the developer tools you will not only get all the required build targets and Silverlight framework for Windows phone 7 series but also a VS2010 IDE as well. This will either be VS2010 Express edition if you don't already have VS2010 RTM installed on your server, or the tools will integrate into VS2010 RTM (if installed). Either way, you are going to get an IDE on your build server.

This might sound rather ugly and I have asked Microsoft for separation of the tools/framework etc from the IDE so ISVs/consultancies can be more flexible how they build their apps. But this is really not high on Microsofts priority list right now. The reason is simple. These tools are targeted toward consumers, so the majority or at least what Microsoft would like is the majority of people building apps/games for Windows phone 7 series are individual programmers whether professional or ameteur and not big companies. Long term this will change.

Instead, the priority is to deliver a really quick and easy way to get up and running building Silverlight or XNA apps for Windows phone. And Microsoft has done this. Simply go to http://developer.windowsphone.com/ and you can download a single package, run it and this will set your machine up ready to build and ship apps on the Windows phone platform. No other downloads are required.

The cool thing about this is, unlike Windows Mobile development, the tools are free. A great step forward.

So to recap, in order for more professional programmers to build Windows phone apps using a sophisticated continuous integration yada yada solution, you need to install the tools on your build server, but you will get the IDE as well.

I also mentioned unit testing. Currently the latest beta tools do not support unit testing on the emulator. Of course you can still write unit tests that execute on the desktop against your Silverlight for Windows phone apps. I have a sample of this over at http://wp7.codeplex.com/

Happy coding!

Monday, July 26, 2010

Username and password format for TFS on codeplex

When you first setup a project on codeplex there is a popup that tells you what domain\username and password to use to connect to the TFS server.

But I found after setting up a project I couldn't remember what the format should be.

So this post is really for my benefit if nothing else, here it is:

Username: snd\<username>_cp
Password: <Codeplex password>

Sunday, July 25, 2010

I'm TestDriven.Net

Thanks to the chaps over at http://testdriven.net/ I got the opportunity to test their product.

So, one of the real problems with Visual Studio when it comes to unit testing your code is it is really slow and unproductive.

If I write a test method in C#, I often want to quickly run it and run it often as this is the whole point of TDD isn't it. If you use MSTest you'll probably find this is the slowest testing tool available but its great integration with TFS often makes it a desirable choice.

To quickly test our method we normally right click the method in code, and select "Run Tests". This will (if a MSTest) switch to the Test Results window and show you the result of the test, great. But...you'll find this quite slow. Then what if you want to debug a test. First you have to run the individual test as said above, then check the check box and hit Debug Test.


This is fine but all very time consuming, why can't I just say Debug this test without having to run it first, check the check box, then hit Debug test.

This is where TestDriven.Net comes into play. Now after installing the tool, I have a new menu item when right clicking my test "CanResolveTransientComponent":



So here I can hit "Run Test(s)" and it will execute the test in a fraction of the time that Visual Studio will do it. When doing this, TestDriven.Net will switch to the output window and show the test output:



So 0.36 seconds is pretty fast. When running via Visual Studio it is much longer, perhaps around 2 seconds for the same test.

The reason for this is when you execute via TestDriven.Net, it omits MSTest code coverage. This greatly speeds up the testing process. If and when you're interested in code coverage you can ask TestDriven.Net to give it to you.

There is a submenu when you right click your test method:



I like this submenu alot. It gives great flexibility in how you run your tests. If you want to simply debug your test without have to go through the lengthy steps mentioned earlier, simply select "Debugger". Sweet.

As mentioned earlier regarding code coverage. When quickly executing a test the MSTest code coverage is omitted in order to speed up the test greatly. But if you want MSTest code coverage then you can select "Coverage" from this handy submenu. This will give you pretty much the same results as if you ran the test via Visual Studio itself.

As you can probably see, if you use another test tool other than MSTest, there is integration for NCover. In fact NCover works for MSTest too. Selecting NCover from the submenu fires up the NCover Explorer tool that gives you a code coverage for the test(s) you have selected to run:



This is a great feature, I do like this.

Another really cool feature that I'd like to mention is support for performance testing. Selecting "Performance" from the TestDriven.Net submenu gives you a nice breakdown of performance data for your test:



There are many more features to checkout with TestDriven.Net and I recommend you check them out.

Sunday, July 18, 2010

Windows Phone 7 Extension Tools

I started porting some code from the Compact Framework over to Silverlight for Windows Phone.

I have created a project on codeplex: http://wp7.codeplex.com/. The solution so far contains an IoC with support for implicit dependency injection - in fact this is a port from the Compact Container on the CF. It also contains a port of the Common Service Locator for the desktop by the p&p team at Microsoft.

The project is designed to be a work in progress and I'll add stuff to it if I think it might be useful to others.

I do plan over the next couple of days to add an event aggregator to the solution that will integrate with the container nicely to promote nice loosely coupled multicast event model in your Silverlight applications.

I am also working on an API that allows communication with the Microsoft Azure Service Bus - much like you get on the desktop. I will checkin as soon as it is available.

The current solution that is checked in is designed to be used with the latest release of Windows Phone developer tools beta.

Friday, July 16, 2010

Windows phone virtual live class - July 20th and July 22nd

Jump start your development of Windows Phone 7 applications by attending Windows Phone 7 JumpStart. This free virtual live class, comprised of four instructor-led 3 hour sessions, will guide you in developing applications for the Windows Phone 7 platform using Silverlight and XNA. Register today by visiting: https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032455932&EventCategory=2&culture=en-US&CountryCode=US.


Course sessions:

July 20 – 8am: Session One: Getting Started with Microsoft Windows Phone and Silverlight
July 20 – 1pm: Session Two: Programming Game Applications with XNA
July 22 – 8am: Session Three: Programming Applications with Silverlight
July 22 – 1pm: Session Four: Review and Wrap Up

Wednesday, July 14, 2010

Pivot and Panorama support in Windows phone 7 beta






The title of this blog post is a little confusing (it was meant to be!) in that there is no support for the Pivot and Panorama controls in the latest bits of Windows phone dev tools. The controls pictured above are courtesy of Stephane Crozatier.

Those controls are freely available on codeplex to download but were designed for the CTP bits of Windows phone. So as there were some breaking changes between the CTP and the recently released beta they won't work out of the box. But it very easy to fix.

Firstly you need to do delete the Microsoft.Phone.* references and add the Microsoft.Phone.dll to the project. All those additional dlls have been merged into Windows.Phone.dll.


Then you'll need to clean up the XAML namespaces. Luckily for me I have ReSharper 5.0 installed and all I have to do is press Alt+Enter and it fixes all my problems! nice



Now if you want the sample WeatherForecast app to run you need to do 1 last thing. That is the ApplicationBarIconButton class now has a mandatory Text property so you need to set this property for each of the buttons in the MainPage.xaml file.

Now once I clean up all that XAML, I rebuild and run and I get...



Sweeet....

Another nice cool thing with this emulator over the older Windows Mobile emulators is that you can do a ALT+Prnt Scrn to get a copy of the current focused window. You can't do this on Windows Mobile emulators.


Windows phone UK User group






I just learn't there has recently been a Windows phone 7 UK user group setup. The first meeting is 28th July at Conchangos offices in London. http://wpug.net/.

Microsofts Paul Foster and Rob Fonseca-Ensor will be speaking. There is now a wait list on the event but worth a try right!

Monday, July 12, 2010

First impressions Windows Phone Developer Tools beta

I just installed the beta bits released this evening and as per the CTP the install experience is brilliant. Except with the beta the greatest thing is support for Visual Studio RTM. So unlike the CTP, even if you had VS RTM installed, then you installed the WP7 dev tools, the installer would install the CTP of VS express and not integrate with VS RTM. Actually I found a whole bunch of errors when attempting this with the CTP.
New project in VS 2010 RTM (no support for VB.NET though):


However this build is good. I'm running VS 2010 Ultimate and VS 2008 Team Suite and this build integrated with VS 2010 RTM nicely.

It is also worth noting in this release of WP7 dev tools, you get Expression Blend 4 for Windows Phone beta. In the CTP you had to download this separately.
So experience so far is great, well done Windows Phone 7 team.

Emulator running bing:



I'll post my experiences of actually writing WP7 code using these bits in later posts. In the mean time you can download and try for yourself.

Windows Phone Developer Tools Beta is here

Announced today at WPC. Get it from: http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&displaylang=en

Check out this post on breaking changes from CTP to Beta: http://blogs.msdn.com/b/jaimer/archive/2010/06/28/migrating-apps-from-windows-phone-ctps-to-the-beta-build.aspx?wa=wsignin1.0

I'll post my feedback once I've installed it and tried it out.

Notice this under "System Requirements:"

This Beta of the Windows Phone Developer Tools is compatible with the final version of Visual Studio 2010


This has made my day :)

Friday, July 02, 2010

Testing Motorola EMDK WLAN implementation on the desktop

I've been writing about testing recently and whether or not to use device test projects or desktop test projects. You can read my view on this in a previous blog post.

No doubt if you have written code for any of the Motorola rugged devices (or other rugged OEM devices) you might have encountered the EMDK WLAN class (or similar if not coding against the EMDK) - which wraps the low-level mobile specific Motorola Fusion API. This is a prime example of why you should use a desktop test project rather than device project. Hang on, you just said the Fusion API can only execute on the device, so don't we need a device test project? No. The reason is simple, again if you have a continuous integration, automated build process setup, your tests will be executing on the build server so you won't be able to execute those tests against a real Motorola device. If you have a device test project, the best you can do is execute those tests on the Windows Mobile emulator - but what will this prove? In this case this is really no different in terms of a test problem than executing them on the desktop.

So this is a reason to write your WLAN tests within a desktop test project. Let me demonstrate...

The WLAN class that comes with the EMDK (Symbol.Fusion.WLAN.WLAN) is a prime example, to make things worst, it doesn't implement an interface, take a look:



So this makes it almost impossible to test. Instead how I have overcome this problem is to write an adapter that wraps the WLAN class, then mock out the adapter using Rhino Mocks. Observe the following WLAN implementation, the interface isn't important:
public class MotorolaMC75WLAN : IWLANService
{
private readonly IMotorolaWLANAdapter _adapter;
private bool _disposed;

public MotorolaMC75WLAN(IMotorolaWLANAdapter adapter)
{
_adapter = adapter;
}


public void Enable()
{
if (!_adapter.IsEnabled)
{
_adapter.Enable();
_adapter.PowerStatusChanged += OnPowerStatusChanged;
}
}

private void OnPowerStatusChanged(object sender, PowerStatusChangedEventArgs e)
{
//raise events to interested parties....perhaps using some sort of event aggregator
}

public void Disable()
{
if (_adapter.IsEnabled)
{
_adapter.Disable();
_adapter.PowerStatusChanged -= OnPowerStatusChanged;
}
}

public bool IsEnabled
{
get { return _adapter.IsEnabled; }
}

public void RenewDHCP()
{
_adapter.RenewDHCP();
}

public void Connect()
{
_adapter.Connect();
}


#region IDisposable Members

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

#endregion

private void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
Disable();
_adapter.Dispose();
}
_disposed = true;
}
}
}
So that is our high level implementation that can be easily extended and contains no low-level mobile code. The adapter in this case is injected and can be anything we want it to be which allows us to test this class easily on the desktop.

The next thing is our actual adapter. The interface for the adapter looks like this
public interface IMotorolaWLANAdapter : IDisposable
{
void Enable();

void Disable();

bool IsEnabled { get; }

void RenewDHCP();

event EventHandler PowerStatusChanged;

void Connect();
}
The implementation is low-level that talks directly to the WLAN class (Fusion API). I'm not going to include a typical implementation for this but an example Enable() method might look like the following:
public void Enable()
{
if (IsEnabled)
return;

Symbol.Fusion.WLAN.WLAN command = null;
try
{
command = new Symbol.Fusion.WLAN.WLAN(FusionAccessType.COMMAND_MODE);
command.Adapters[0].PowerState = Adapter.PowerStates.ON;
}
catch (OperationFailureException ex)
{
//do something...
}
finally
{
if (command != null)
command.Dispose();
}
}
It simply enables the first adapter it can find. Non-of the real adapter is testable.

So if this were a device test project, we'd have to mock out the adapter by hand, then pass it in to the constructor to the MotorolaMC75WLAN class. But as we have decided to use a desktop test project we can use any mocking framework that we choose which enables us free of having to do the laborious hand mocking work.

You can download Rhino Mocks from here if you don't already have it: http://www.ayende.com/projects/rhino-mocks/downloads.aspx. Download the zip and extract it somewhere on your hard disk, then add a reference the Rhino Mocks assembly in your test project - there is only one dll you need to reference.



Add a
using Rhino.Mocks;
to your test class. Now if you wanted to mock out the adapter Enable method, in Rhino Mocks world it could look like the following using the newer triple A syntax:
[TestMethod]
public void ShouldEnableWLAN()
{
IMotorolaWLANAdapter _mockWLANAdapter = MockRepository.GenerateMock<IMotorolaWLANAdapter>();
IWLANService _wlan = new MotorolaMC75WLAN(_mockWLANAdapter);

_mockWLANAdapter
.Expect(x => x.Enable())
.Repeat.Once();

_wlan.Enable();

_mockWLANAdapter.VerifyAllExpectations();
}
So the only actual thing we are testing here is the real MC75 WLAN class and not the adapter. The code is fairly easy to read. We are simply telling Rhino Mocks to expect exactly 1 call to Enable() when _wlan.Enable() is called. The thing to bear in mind here is to ensure your actual adapter doesn't contain bugs as we can't automate those tests on the build server.

There you have it, a true mocking framework put at use in the mobile space.

If you want to learn more about mocking frameworks, use Google, there are millions of articles out there on the subject.

Thursday, July 01, 2010

Automated testing considerations for enterprise Windows Mobile projects - avoid a world of pain

I know in the past I have written blog posts on how to create unit tests that are actually executed on the Windows Mobile emulator which is great if you have mobile specific tests. But to be honest, when you are building large scale enterprise mobile solutions targeting a range of different devices i.e. Motorola, Casio, Intermec etc. Writing device specific platform tests for all these devices becomes quite hard to automate when using an application lifecyle management solution such as Visual Studio and TFS with its continuous integration and automated test execution support.

Even if you only support one type of device, when you do enterprise mobile development, using the tools mentioned above, you're not going to be able to automate those tests as part of a nightly build or even a CI build. As you will no doubt be using the vanilla Windows Mobile Emulators that know nothing about such specifics that you might be testing such as barcode reader, credit card reader, bluetooth stack etc. Instead you would normally write adapters or mock out implementation code when testing your barcode implementation. You'll generally never write an actual test that calls the true native code on that platform, why would you anyway unless it's part of an integration test. Ensuring you do this allows you to write unit tests, integration tests that do run as part of your nightly and CI builds that do improve code quality.

So what type of tests should you write for most of your code base, device or desktop? My advice is desktop even if you think your device project is small, there will come a time when your project becomes large and more complex. The benefit to targeting the desktop is the ability to use mocking frameworks. We tend to use Rhino Mocks and today there are 0 mocking frameworks available on the CF. If you start to go down to road of writing your own mocks, then you're entering a world of pain. When you think of it, most code can be tested on the desktop anyway. For things like data access, if you use SQL CE 3.5, then this can run on the desktop. For the features that require explicit device testing, then create a single device test project for this purpose and exclude it from the build definition.

Wednesday, June 30, 2010

Versioning team builds to match assembly version numbers

Have you ever wanted to version your team builds to match your assembly versions. Stuart Preston shows how to easily achieve this in Team Build 2010 over at: http://stuartpreston.net/blog/2010/05/02/simple-assembly-versioning-with-team-build-2010/

I've just tried this and it works nicely, great stuff!

Monday, June 28, 2010

Automating your Windows Mobile 6.x builds on TFS 2010

If you have recently attempted to build your Windows Mobile 6.x code using the new TFS 2010 recently you might have received this error:

(81): The imported project "C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.CompactFramework.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

It is pretty clear as to what the issue is, so how do you fix this? Well you can install Visual Studio 2008 (Device development is not supported on VS 2010) on your build server - not nice, but then this won't fix my issue here. Notice the path above. The smart device project is looking in the 64-bit location for the Compact Framework build targets files: C:\Windows\Microsoft.NET\Framework64. As my build server is running on Windows Server 2008 R2 - which only comes in 64-bit edition, it makes sense to use 64-bit tools.

The easy fix for this type of configuration is to install the .NET Compact Framework 3.5 Redistributable which can be found here: http://www.microsoft.com/downloads/details.aspx?FamilyID=e3821449-3c6b-42f1-9fd9-0041345b3385&displaylang=en. Install that package on the build server which will allow your code to compile.

Then download the .NET CF 3.5 Power Toys - this will give your the Compact Framework build targets that MSBuild needs. This can be downloaded from here: http://www.microsoft.com/downloads/details.aspx?FamilyID=c8174c14-a27d-4148-bf01-86c2e0953eab&displaylang=en. Again that package needs to be installed on the build server. You may think it is odd that the build targets are included in this package, then so did I. They are also included with VS2008 but installing the Power Toys is a much better solution as it's a lot smaller install.

Now remember with my configuration I mentioned earlier, I am running 64-bit server, as there is no 64-bit edition of .NET CF Power Toys, the build targets get installed to the 32-bit location on the file system: C:\Windows\Microsoft.NET\Framework\v3.5 but by default my build definition is set to "Auto" which will choose the 64-bit edition first, then use the MSBuild path to find the build targets. This will still result in a failed build because the 64-bit edition will be running from: C:\Windows\Microsoft.NET\Framework64\v3.5 and that path doesn't contain the files we need. So a simple change to the build definition to use x86 is needed:

Once you make that change, queue a new build and your build should succeed.
As for getting VS 2008 talking to TFS2010, I'll write a post on getting that to work. There is a lot of content on this in the community but a lot of it didn't work for me.

Thursday, May 27, 2010

Windows Phone 7 Series running on a modified Samsung Omnia



Looks very slick...voice in French.

Installing Windows 7 on a netbook


I recently bought an Asus Eee PC 1001 HA netbook for my wife to use for a really good price as it was an ex demo (end of line). This model has been superseded by a better model that includes a slightly faster CPU Intel Atom 1.66Ghz as the 1001 has a Intel Atom 1.6Ghz N270 processor. The newer model also comes with Windows 7 as oppossed to Windows XP which is what the 1001 model comes with. I have to say, I think it is brilliant.

As mentioned it came with Windows XP Home Premium edition but as this was for my wife she didn't care. But after getting home I relised I couldn't join it to the Windows Server 2008 domain controller because Home Premium doesn't support Windows Domains. So she couldn't print, fax, access family pictures, get an IP address from the DHCP, access TFS..(not really, shes not a coder!) etc etc You can't even access a network UNC path from Home Edition.

So XP clearly had to come off. So we installed Windows 7 Ultimate x86, bearing in mind this little machine only has 1gb of DDR2 RAM and it runs very well indeed.

But the problem I found was installing the Windows 7 OS without a CD drive and no access to a network share? All I have are USB ports. So as I don't have a optical USB CD drive, I simply downloaded Windows 7 USB/DVD Download Tool from codeplex, found here: http://wudt.codeplex.com/ It is actually written in C# under Visual Studio 2008, with full source code available to download.

This tool allows you to create a bootable USB flash card. So all I had to do was create a bootable USB flash card using the Windows 7 ISO, configure the BIOS on the Asus to boot from USB, install Windows 7, then job done.

Windows 7 USB/DVD Download Tool

In fact this tool works with DVD's as well, so it will be useful for future DVD burning.
This blog talks about disabling various Windows 7 services for optimization on a netbook pc, but to be honest I didn't need to disable anything, it just works really nicely.

I did forget to mention that I download Asus's drivers for optimal WLAN, display adapter etc to better performance and to get the machine to behave correctly.

Good job Asus...

Saturday, May 22, 2010

Moving Windows Azure CTP account over to RTM - don't forget to remove any unwanted services!

If like me you recently moved your Windows Azure CTP account over to an RTM account, ensure you delete any services that you don't want as you might be charged. I completely forgot I had 2 services deployed in Staging and 2 services deployed in production when I moved my account over. So a few weeks ago I had a bill for £187.10! I had been viewing my bills regularly and didn't see any charges until 24/04/10. So the charges were from 25/03/10 - 24/04/10.

The important thing to note here is the pricing model in Windows Azure - I'm talking about hosting services which is the deploying of services and running services in the cloud bit of Windows Azure - not the Service Bus or SQL Azure - they have different pricing models.

The charges are based on "compute hours". Although do note there are two types of pricing models within Azure. The first is a pay as you go type model so you only pay for what you use. The other model is a fixed contract where you agree to a fixed discounted monthly fee for a given time frame and any excess usage is charged at the standard rate.

Do be aware, no matter whether your services are being used or not even if your services are not running this still eats into your "compute hours". It sounds unfair from the outset, but I don't think it is unfair as for those charges you get a dedicated VM, CPU, memory etc to your services. So you can be sure you'll have the resources available to serve up requests when needed.

So as I am an MSDN Premium subscriber, I opted for the promotional offer of "free" services. So under this offer you get 750 "compute hours" under Windows Azure, 1,000,000 ACS transaction requests on AppFabric, 3 web edition databases etc. See here for more info on this promotional offer: http://www.microsoft.com/windowsazure/offers/popup.aspx?lang=en&locale=en-US&offer=MS-AZR-0005P

Utilization over the "free" 750 hours will be charged at the standard rate.

Of course that works out to be one service constantly deployed in the cloud for 24 hrs a day for 31 days. So essentially free.

Now regarding my bill I received, the good news is Microsoft refunded me the £187.10 due to the fact I forgot to remove the services and the fact that I didn't realize they were still deployed as I have only been using the Service Bus within Windows Azure lately (now known as the AppFabric). So I am grateful to Microsoft for doing this as they legally didn't have to.

So when I noticed the bill, the first thing I wanted to do was delete the services to prevent further costs mounting up.

So I went to the Windows Azure maintenance portal over at http://windows.azure.com/ clicked on Windows Azure and noticed the services. But the Delete button was disabled:



This is not particularly intuitive, but you have to click "Suspend" which is the same as stop. Then the Delete button becomes enabled that allows you to delete the services!



Wednesday, May 12, 2010

MSTest: Not Executed after aborting a debugged MSTest

If you try to debug a MS Test unit test in VS 2008 but stop the debugger before the test is completed (abort the test) the test status will be marked with "Aborted". Which is fine and expected. But if you then try to execute any other test, whether this is debugging a test or just executing a test, it will fail and the status of all attempted tests will be "Not Executed". And from here in no tests will ever execute again..until you kill process "vsperfmon.exe". If you kill that process, then unit tests will then continue to execute.

This defect seems to be fixed in VS 2010 which is great but it still exists in VS 2008 which is a pain as Windows Mobile developers still require VS 2008 to develop WM apps (this defect applies to both desktop and device tests).

There is a bug report on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/299925/after-debugging-a-unit-test-vsperfmon-exe-must-be-killed-to-be-able-run-further-tests

As always, if you find this defect annoying, then use the site above to vote for a fix.

This bug has been around for sometime and it's only today I learned the workaround!

To inject IServiceLocator or not to inject

I had a discussion the other day about it being a bad idea to inject the IServiceLocator as a dependency into the constructor of consuming types. Now I'm talking about the Common Service Locator by the p&p team at Microsoft (http://commonservicelocator.codeplex.com/) but to be honest this applies to the Service Locator pattern in general.

The argument was based on the fact that it makes testing more difficult as you not only have to mock or provide types to the constructor but you have to add them to a service locator if injecting the service locator interface.

There are valid reasons for not doing this but we don't live in an ivory tower and sometimes we need to pull types from the container at runtime that we simply do not know at design time. In this case it makes perfect sense for using a service locator, right? as the whole point of the pattern is to abstract container from implementation code.

I'm curious of other developers feel for this and their approach as to whether they do this or not, and if so why.

Friday, April 23, 2010

Turning off the context menu scrolling in VS2010

UPDATE (28/03/2011): This has been fixed in VS2010 SP1: http://www.simonrhart.com/2011/03/unnecessary-context-scrolling-in-vs.html

If you have noticed in VS2010 when right clicking something and displaying the context popup menu. You sometimes get a scrollable menu appear in which you have to use the mouse wheel, or press the up or down arrows that are displayed for this type of menu to see all items in the popup menu.

Sadly turning off this "feature" is not possible as it seems to be a bug: https://connect.microsoft.com/VisualStudio/feedback/details/532806/context-menus-open-in-scrolling-mode-while-there-is-place-to-show-the-whole-menu/?wa=wsignin1.0

If you find this bug annoying enough, please vote on the connect site so hopefully we will get a hot fix rather than having to wait for SP1.

[TFS 2010] (1835): Task failed because "resgen.exe" was not found

I recently upgraded my build server from TFS 2010 RC (which worked fairly well I have to say) - although its worth pointing out here that VS 2010 RTM doesn't work with TFS 2010 RC. You get all kinds of build errors.

I recently checked some code in and the build server gives me the following error:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (1835): Task failed because "resgen.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "resgen.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK. 2) Install Visual Studio 2010. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task.

So I have given in and installed Visual Studio on the build server and this seems to fix the problem! - I know this just doesn't sound right.... I could of tried and installed the Windows SDK on the build server but I do want to build Windows phone 7 Series apps on my build server and I know that bits in WP7 are not in the Windows SDK.

Wednesday, April 21, 2010

ServiceLocator.Current - calls the SetServiceLocator delegate everytime!

If like me you were under the impression that calling ServiceLocator.SetLocalProvider result would be cached when using static member ServiceLocator.Current then you'll be wrong.

I was surprised to find out that the ServiceLocator implementation passed to ServiceLocator.SetLocalProvider was created everytime I called ServiceLocator.Current.

I know I should always inject IServiceLocator into the ctor of the consumer types, but there are rare occasions that I need to use ServiceLocator.Current in static classes.

The implementation of ServiceLocator.Current looks like so:
public static IServiceLocator Current
{
get { return currentProvider(); }
}
currentProvider() is a good old fashioned delegate and looks like so:
public delegate IServiceLocator ServiceLocatorProvider();


So instead of doing this:
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(_container));
Do this:
IServiceLocator castle = new WindsorServiceLocator(_container);
ServiceLocator.SetLocatorProvider(() => castle);
You will get a load less garbage collections as a result.

If you have no idea what I am talking about in this post, please see the Common Service Locator by the p&p team at Microsoft here: http://commonservicelocator.codeplex.com/

Monday, March 29, 2010

Making use of the Command Pattern on Windows Mobile/phone

The Command pattern is a great pattern for abstracting business processes from your implementation code. This pattern is becoming very popular throughout different types of systems. Whether this is MVC thin client, fat clients such as MVP, MVVM.

The Command pattern works really nicely in combination with a IoC container and DI framework that I have talked about before on this blog.

Often it is desirable for a command to take a context or state. A command should only have one method and should only have one role (single responsibility). The interface for a command could look like so:
public interface ICommand<T>
{
void Execute(T context);
}
So our context here is a generic and is defined when the command is registered with the container.

So imagine we have a CRM system that when a customer is registered, we want to send that customer an email to confirm he/she has been setup correctly. You might have a domain model in this case that raises an event that is caught on the middle tier. When this occurs, instead of baking that code into the presenter/controller/business class, you abstract it out into a command. This not only makes your system more readable/maintainable but makes it easier to test too.

So in this case you could have a context class that contains the state such as the Customer domain object like so:
public class EmailCustomerConfirmationContext
{

public EmailCustomerConfirmationContext(Customer customer)
{
Customer = customer;
}

public Customer Customer{get; private set;}
}
Our command might look something like the following:
public class EmailCustomerConfirmationCommand : ICommand<EmailCustomerConfirmationContext>
{
private IEmailAdapter _emailAdapter;

public EmailCustomerConfirmationCommand(IEmailAdapter emailAdapter)
{
//inject dependencies here.
_emailAdapter = emailAdapter;
}

public void Execute(EmailCustomerConfirmationContext context)
{
_emailAdapter.Send(context.Customer);
}
}
Registering the command with the container (Compact Container - see previous posts on using this container) would look something like the following:
container.AddComponent<ICommand<EmailCustomerConfirmationContext>, EmailCustomerConfirmationCommand>();


Very clean approach. Of course the more dependencies you add to the command, the more complex it will become which means harder to test. So sometimes commands can become over complex. Bear this in mind when adopting this pattern.

Executing the command could look something like the following(assuming you are using the service locator):
var command = ServiceLocator.Current.GetInstance<ICommand<TContext>>();
if (!command.IsNull())
{
command.Execute(context);
}
In terms of handling errors etc, this could be handled via events using some sort of event aggregator pattern or the context itself to pass back data so the middle tier can act accordingly.

Sunday, March 28, 2010

TFS 2010 - the new build definition window

Jason Prickett has recently written a good article on the new Build definition window in VS 2010 - it's now dockable! It also has a new CI type named Gated-checkin. So developers need to have a green CI before they can checkin. Cool. I have been checking this new Gated-checkin feature out in the RC version recently, and I'm not sure it is working correctly. But will write back soon on my findings.

See here:
http://blogs.msdn.com/jpricket/archive/2010/01/19/tfs-2010-the-new-build-definition-window.aspx

Cool new feature with VS2010 and TFS 2010

I recently installed TFS 2010 RC x64 and only now got round to playing with it. I have to say once I got over the 'gremlins' during the installation everything else is pretty slick. There are many features I like and many that are going to make our lifes better.

One of the really horible things I hated about VS 2008 and TFS 2008 was after a partially succeeded build, opening up the build output in Build Explorer would only tell you something went wrong. In other words, the build partially suceeded. What? what does this mean? we know from experience this generally means a unit test had failed, but which one, and how do I fix it?



The only way to know which unit test had failed would be to troll through the build log - very painful when you have a large build script spanning multiple projects and 1000's of unit tests. I used to search for "FAIL". But some developers name their unit tests with the word "FAIL" in it so this doesn't help matters as it takes forever to find the real error.


So I created a really simple test project and added a test method that throw an exception, after I checked in under a CI build definition, I got the following:






Now, how cool is that! Weldone Microsoft. I think this will make many developers very happy. Look at the options we get at the top, [Open Drop Folder], [Retain Indefinately] etc it just makes our lifes easier. But the best bit, the reason for posting this blog entry, If I click "View Test Results" I get the following:







I'm impressed, this will make us so much more productive, a reason alone to upgrade. Excellent stuff!

Wednesday, March 24, 2010

MVVM - Windows phone 7 series pattern of choice

This post is really for my benefit (although it might help others). Here is a good article on the MVVM (Model-View-ViewModel) pattern that is showing a lot of interest in the WPF communities.

It is very much a different way of thinking when designing UI architecture although very similar to Fowlers relatively new Presentation Model pattern.

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

Implementing an IoC container in Silverlight on Windows phone 7 series

I wrote a while ago about implementing a Service Locator for the CompactContainer on the Compact Framework here: http://www.simonrhart.com/2010/02/implementing-commonservicelocator-on.html

I mentioned in that post that I was using the CompactContainer for the CF freely available here: http://code.google.com/p/compactcontainer/ But now as I'm getting into Silverlight as it's the technology of choice when building applications for the Windows phone 7 series platform (as well as XNA), I needed an IoC container to solve the same problems on Silverlight as they do on the Compact Framework.

So I tried to port the container along with the ServiceLocator as blogged about before. I recieved errors in the ComponentCollection class after I tried to compile under Silverlight. Mainly because the following predicate methods such as:
  1. List.FindAll
  2. List.Find

Are not supported in Silverlight 3 as the documentation suggests. However, they are in XNA. As the generic List class belongs to mscorlib.dll (System.Collections.Generic) I noticed that mscorlib is shared for both XNA and Silverlight applications on WP7. I'm trying to find out why this is, or if there is a way of making those methods work in Silverlight.

Anyway it's not the end of the world that those methods are not in Silverlight, all I had to do was replace the following methods in the ComponentCollection class:


public List<ComponentInfo> GetComponentInfoListFor(Type serviceType)
{
return _list.FindAll(ci => ci.ServiceType == serviceType);
}

public ComponentInfo FindForService(Type serviceType)
{
return _list.Find(ci => ci.ServiceType.Equals(serviceType));
}

public ComponentInfo FindForClass(Type classType)
{
return _list.Find(ci => ci.ClassType.Equals(classType));
}

public ComponentInfo FindKey(string key)
{
return _list.Find(ci => ci.Key.Equals(key));
}
With the following code:
public List GetComponentInfoListFor(Type serviceType)
{
List<ComponentInfo> results = new List<ComponentInfo>();

foreach(ComponentInfo component in _list)
{
if (component.ServiceType == serviceType)
results.Add(component);
}
return results;
}

public ComponentInfo FindForService(Type serviceType)
{
ComponentInfo result = null;
foreach(ComponentInfo component in _list)
{
if (component.ServiceType == serviceType)
{
result = component;
break;
}
}
return result;
}

public ComponentInfo FindForClass(Type classType)
{
ComponentInfo result = null;
foreach (ComponentInfo component in _list)
{
if (component.ClassType.Equals(classType))
{
result = component;
break;
}
}
return result;
}

public ComponentInfo FindKey(string key)
{
ComponentInfo result = null;
foreach (ComponentInfo component in _list)
{
if (component.Key.Equals(key))
{
result = component;
break;
}
}
return result;
}
That was all I had to change everything else just compiled and worked. Full dependency injection worked as per on the Compact Framework. It seems moving to Silverlight is going to be less painful than I originally thought!

Tuesday, March 16, 2010

Windows Phone 7 Series emulator is running slow

When I first downloaded the new Windows Phone 7 Series developer tools CTP package, I found the new emulator to be very slow. This is the opposite of what I was expecting as the new emulator is built for x86, runs within a VM and supports hardware GPU host acceleration (so long as you have a gx capable of DirectX10 and at least support for DDI10) - which my laptop does.

To determin whether you have DirectX10 support and at least DDI10, run DxDiag.exe from the command-prompt and inspect the Display tab.

So what next, ok so I learned that in order for the emulator to make use of the GPU host from the VM I needed to enable HW virtualization. So how do I know if I have this enabled? this is enabled at BIOS level and normally disabled by OEMs by default. You can run the Microsoft Hardware-Assisted Virtualization Tool here: http://go.microsoft.com/fwlink/?LinkId=163321



So after running this tool I got the above. So this confirms that I didn't have hw virtualization enabled. After enabling it in the BIOS my Windows Phone 7 Series emulator is now running much faster!

More details about this process here (not WP7 specific): http://www.microsoft.com/windows/virtual-pc/support/configure-bios.aspx



New Windows phone series 7 forum

Ask your new Windows phone 7 series questions here:
http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/

Monday, March 15, 2010

Friday, March 12, 2010

Pre-order VS 2010 discount

Microsoft Visual Studio 2010 Professional will launch on April 12 but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of £484.99.

If you use a previous version of Visual Studio or any other development tool then you are eligible for this upgrade. Along with all the great new features in Visual Studio 2010 (see www.microsoft.com/visualstudio) Visual Studio 2010 Professional includes a 12-month MSDN Essentials subscription which gives you access to core Microsoft platforms: Windows 7 Ultimate, Windows Server 2008 R2 Enterprise, and Microsoft SQL Server 2008 R2 Datacenter.

So visit http://www.microsoft.com/visualstudio/en-gb/pre-order-visual-studio-2010 to check out all the new features and sign up for this great offer.

Sunday, February 28, 2010

[ Application Tier ] TF255437: An error occured while querying the Windows Management Instrumentation (WMI) interface on the following computer:

You may have received the following error messsage while processing the Readiness checks during the installation of TFS 2010 CTP recently: [Application Tier] TF255437: An error occured while querying the Windows Management Instrumentation (WMI) interface on the following computer:. The following error message was received: Invalid Namespace.

So I though I'd check that WMI Service is running, and it was. After searching around it turns out I needed to enable WMI Compatibility for IIS 6 under IIS. You can enable this under Server Manager in Server 2008 and change the IIS role.

I think this 'feature' has been fixed for RTM of TFS 2010.

Friday, February 19, 2010

How to find out when your pre-release version of Windows 7 will expire

If you are still running pre-release Windows 7 OS like I am, it will expire soon. So how do you find out when it expires? Simple run winver.exe on the run menu and you'll get this. My copy expires on 1st March 2010.



Zune HD software for x64 platforms

Don't make the same mistake as I did in downloading the x86 version of Zune if you run x64 version of Windows.

Get the x64 version here: http://www.microsoft.com/downloads/details.aspx?FamilyID=9d25c2a6-cae3-49b0-a474-124fe79628a8&displaylang=en

Note: The x64 version is ~400mb where as the x86 is ~50mb !

Preview of Windows phone 7 Series

Thursday, February 18, 2010

It's Windows phone 7 Series time at MIX this year

It's no secret that MIX will be covering a lot of the Windows phone 7 Series content this year in Las Vegas (March 15th - 17th).

I just wish I was going, perhaps if I can find a cheap flight.....

Note: Windows phone sessions to be confirmed...

http://live.visitmix.com/

Wednesday, February 17, 2010

Implementing the CommonServiceLocator on the Compact Framework

You may have come across or used the CommonServiceLocator API as developed by the p&p team at Microsoft for your desktop applications in the past.

Before we go any further, it is worth explaining what a Service Locator is. The Service Locator is a pattern that abstracts your retriveal of components or services from the underlying container model that is used to house them.

So no matter what container you use, i.e. Castle Windsor, Spring, StructureMap etc pulling anything from the container in code will always be the same and consistent across layers.

Martin Fowler explains it better than I can here: http://www.martinfowler.com/articles/injection.html

All you have to do is write an implementor for the Service Locator to use. You'll note all the famous ones on the site above have already been implemented. But of course these don't work on the CF, so what do we do?

Firstly, you need to download the source code for the CommonServiceLocator as the project needs to be modified slightly. Simply remove all references to the ActivationException.Desktop class as the constructors in that class are not supported on the CF. That is it! - for the service locator project. Now all that remains is the implementor. This depends on what container you are using. We have been using a container called CompactContainer written by Germán Schuager that works well (uses reflection as it supports true dependency injection).

CompactContainer can be downloaded from here: http://code.google.com/p/compactcontainer/ it is freely available under the Apache Licence.

In order to write an implementor for the CommonServiceLocator, all you need to do is write a class that derives from abstract class ServiceLocatorImplBase, then tell the service locator where the instance of the container is and a reference to itself. This class implements IServiceLocator too, so itself can be injected into classes - for whatever reason.

The class is really simple, it could look something like this, here we have named it CompactServiceLocator:

public class CompactServiceLocator : ServiceLocatorImplBase
{
private readonly IContainer _compactContainer;
private bool _disposed;
public CompactServiceLocator(IContainer compactContainer)
{
_compactContainer = compactContainer;
}


protected override object DoGetInstance(Type serviceType, string key)
{
object resolvedObject = null;

// Resolve using a key if we have a key
if (!key.IsNull())
{
resolvedObject = _compactContainer.Resolve(key);
}

// Resolve using type if the object has not been resolved
if(resolvedObject == null && !serviceType.IsNull())
{
resolvedObject = _compactContainer.Resolve(serviceType);
}

return resolvedObject;
}

protected override IEnumerable<object>
DoGetAllInstances(Type serviceType)
{
return _compactContainer.GetServices(serviceType);
}

private void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_compactContainer.Dispose();
}
_disposed = true;
}
}

public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

}
So essentially the above code is fairly simple in that all it is doing is it allows the service locator to call your specific container method. i.e. the implementation of method DoGetInstance() calls the specific container method to get an instance from the container. In this case it is method Resolve(). It is just implementation specific code which will look different from container to container.

So now you have written an implementor to go along side the Castle Windsor etc adapters, how do you use it? Well first you have to tell the Service Locator the container instance it should use, then set a reference to the service locator interface that maps to itself, like so:
Container container = new Container();
ServiceLocator.SetLocatorProvider(() => new CompactServiceLocator(container));
container.AddComponentInstance<IServiceLocator>(ServiceLocator.Current);
Container in this case is the CompactContainer freely available as mentioned above.

Asking for services is done as follows:
ServiceLocator.Current.GetInstance<IFooBar>();
Where IFooBar is your registered interface on the container.

That is it - as easy as that. If anyone would like me to put together a complete solution demoing this, please let me know. I didn't do it as the code is all available on line apart from the CompactContainer ServiceLocator implementor.

Windows Mobile 6.5.3 Developer Toolkit Released

You may have noticed that the Windows Mobile 6.5.3 SDK was released two weeks ago for 1 day then pulled from MSDN. I don't think Microsoft has made a public announcement why this was, but it is back under a new name. The 6.5.3 Developer Toolkit was uploaded today and can be downloaded from here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=c0213f68-2e01-4e5c-a8b2-35e081dcf1ca&displaylang=en

Of course be sure to change your target project type within Visual Studio to make use of the new emulators.

Tuesday, February 16, 2010

Windows Phone 7 Series Announced at MWC



You've probably heard by now that Microsoft has announced Windows Phone 7 Series to the community on 15 Feb at the Mobile World Congress conference in Barcelona by Steve Ballmer. The Microsoft official press release can be found here.

I have to say the platform looks awesome. It looks very Zune HD like which is partly to do with the fact that Joe Belfiore is on the design team.

The best publicly available video to date that shows the platform UX is over on channel9 here:
http://channel9.msdn.com/posts/LauraFoy/First-Look-Windows-Phone-7-Series-Hands-on-Demo/

Dev Story:
If you're expecting to hear about the developer story or anything to do with the application platform then you'll be disappointed. Microsoft has not made any thing public regarding tools, frameworks etc for the new wave of Windows Phone 7 Series products. Microsoft is gearing up to tell the community about the developer story at MIX in Las Vegas on March 15-17. For sessions on Windows Phone 7 Series at this event see here.

For developer story announcements keep an eye on Charlie Kindels' blog as he is responsible for the Windows Phone 7 Series application platform.

The Windows team blog has a post on the announcement here.

The Windows Phone twitter hashtag is: #wm7

In Seattle at Summit



So it's that time of year again, I'm at the MVP Summit 2010 this year and looking forward to it as there are many new and exciting technologies being released out of Redmond.

I will post the stuff I can here.

Friday, October 30, 2009

Writing designer friendly controls for Windows Mobile

One thing that you sometimes need when writing Visual Studio designer friendly controls for Windows Mobile, is knowing if your code is running in design time - which is essentially running on the desktop or not. You need to know this because if you are running on the desktop (design time) you don't want to call device specific dlls.

The following code can be used to determine this:
public static class DesignMode
{
private static byte _mode = 255;

public static bool IsTrue
{
get
{
if (_mode == 255)
_mode = AppDomain.CurrentDomain.FriendlyName.Contains("DefaultDomain")
? (byte)1 : (byte) 0;
return _mode == 1;
}
}
}
So essentially you can then code in your application:
if (DesignMode.IsTrue)
{
//don't call coredll.dll
}
else
{
//call coredll.dll
}