Friday, September 10, 2010
 
   
 
Welcome to my site

First let me say thanks for stopping by my site. My name is David Hanson-Graville and I am a IT consultant working in the UK. Let me make it clear, I am passionate about technology and specifically .net and its various forms. I've programmed in a range of langages, but I can say, I am now at my happiest when coding with c#. I hope my blog is an enjoyable & educational read and please feel free to email me at David.Hanson@OnTheBlog.net if you have any questions. 

OnTheBlog Minimize
Author: David Hanson Created: Wed, 02 Jan 2008 20:28:49 GMT
All things .net, wpf, XAML, C#, Workflow Foundation and many more.

Windows Phone 7 Emulator standalone installer (July bits)
By David Hanson on Sat, 24 Jul 2010 05:27:22 GMT

Hello out there.

Well I haven't updated this site for about 6 months and I thought I would try and be a little more active. The reason for my lack of posts is that I am currently in Australia travelling in a campervan and connectivity has been a bit of issue. The distraction of sunshine and beautiful sights doesn't help either.

Anyways I have just started getting to grips with the July Windows Phone 7 Beta tools and came across annoying issue with the installer. Basically it makes you download 300mb of data as part of the install. As I only wanted to download the Emulator (specifically the x64 version) I hunted around the installed settings file (located in a temp directory) an eventually stumbled upon the following two links which allow you to download it seperately. Hope this helps someone else who had this problem.

http://go.microsoft.com/fwlink/?LinkId=194975

http://go.microsoft.com/fwlink/?LinkId=194976

PS. Word to MS. Stop using online installers.... they are driving me mental on a flakey 3g connection in the bush!

Comments (0)

Introducing #Fellows
By David Hanson on Fri, 19 Mar 2010 20:58:27 GMT

Just a quick note to make readers aware of a new blogging site called #Fellows. This community site aggregates the blogs of a number of smart .Netters from the UK. Enjoy.

Comments (0)

Rx, Reactive Extensions and Observable T
By David Hanson on Tue, 26 Jan 2010 10:31:57 GMT

I have been seeing quite a lot of talk on the tweet feeds and blog posts recently about the new Reactive Extensions that are being released. Now I was struggling to get my head around it at first but read this simple blog post which really helped clarify what Rx actually offers. It seems very powerful, and could be a game changer for event processing in the same way Linq was for list data. Really like the drag and drop example in this  post as it becomes very clear the intention of the code shown below. 

Define the events you wish to monitor

var mouseDown = from evt in Observable.FromEvent<MouseButtonEventArgs>(image, "MouseDown"
                
select evt.EventArgs.GetPosition(image);
var mouseUp = Observable.FromEvent<MouseButtonEventArgs>(image, "MouseUp");
var mouseMove = from evt in Observable.FromEvent<MouseEventArgs>(image, "MouseMove") 
                
select evt.EventArgs.GetPosition(this);

Then define your query which will tie these events together into a logical form for your requirement (In this case drag and drop)

var q = & ...
Comments (1) More...

Calling a generic method with Expression.Call
By David Hanson on Sun, 17 Jan 2010 09:05:54 GMT

The other day I came across a comment in the code base of the application I'm currently working on that said the following.

// Having to loop through the GetMethods() array is pretty rubbish, even if we are using LINQ. If someone knows how to use GetMethod to get the generic method definition, then correct the code, email me and I'll buy you a pint.

Now looking into this issue it turns out that the author is correct, you cannot actually use Type.GetMethod() to invoke a Generic Method. As a result the approach the dev used was to call Type.GetMethods() which returns all methods on the type and then apply some linq filtering to identify the generic method they wish to invoke. Once filtered a quick call to MakeGenericMethod then you can invoke it. This is shown below.

typeof(FrameworkHelper)
    .GetMethods()
    .Where(method => method.IsGenericMethod && method.Name == "DeleteEntity")
    .Select(method => method.MakeGenericMethod(actualEntityType))
    .First()
    .Invoke(null, new object[] { entity });

So having a think about this for a bit and then recalling some great blog posts I had read from Bart De Smet's blog about expression tree's I wondered if we could use the Expression.Call method to achieve the same results. After some tinkering with the overloads for this method I eventually figured it out and result is shown below.

ParameterExpression param = Expression.Parameter(typeof(Entity), "param");
var method = Expression.Call(typeof(FrameworkHelper), "DeleteEntity", new[] { typeof(Entity) }, param).Method;
method.Invoke(null, new object[] { entity });

In the code above we create an instance of a Parameter expression which requires the Type of the parameter we are going to pass to the method. Then in order to invoke the method we need to build the call expression on line 2. Here we use the Expression.Call static method which has a number of overloads.

The first param is the type which holds the static method we wish to invoke, the next paramter is the method name which is passed as string. The third paramter is the types that the method signature defines. This is passed as an array of objects. Finally is the ParamExpression we constructed on the previous line. The final part once we have the methodInfo is to invoke it by pa ...

Comments (0) More...

Raising binding exceptions in WPF & Silverlight with .net 4.0 Dynamics
By David Hanson on Mon, 14 Dec 2009 14:00:19 GMT
It’s been a while since I’ve posted anything. Sorry about that. This has mainly been due to a busy social and work schedule which has not given me the time I’ve needed to create the content that’s been floating around my desk as post it notes. In this post I would like to revisit dynamic typing support in .NET 4.0 and apply it to a real world scenario.
 
Proxying and Interception with Dynamics
 
If you’re like me then I imagine you have been playing with .NET 4.0 for quite a while now. There is a wealth of new language features to play with in this release and I’m excited about the RTM come march. One of the features I have discussed previously is the support for dynamic typing. Dynamics brings with it some new approaches to problems that static languages have often found difficult to solve. In this post we will be looking at the topic of dynamic proxying, interception and AOP.
 
The common goal of these techniques is to allow a programmer to be able to inject code transparently before and after a method has been invoked. This is illustrated below in the diagram below.
 

 
If you have not come across this concept before you may ask what is the point of intercepting a method before and after execution. A layer of indirection is particularly useful when trying to inject code between a client and our objects. The reason we do this as it allows us to implement secondary support functions such as logging, transaction management, code contracts and other utility code outside the body of our method. What we find when we implement an proxy pattern is that once we have removed this secondary code the readability of our code improves tremendously and we have also increased our separation of concerns.
 
Now you can see the benefits of this approach, let’s turn our attention to how we go about implementing this in our code. Luckily for us there has been a lot of smart people working hard to help make this process easier. If you do a search for proxy pattern’s or aspect orientated programming you will find a heap of information. When it comes to AOP there are a number of frameworks which have already been developed. These are listed below. 
 
Aspect#
Encase AOP
Spring.NET
Aspect.NET
AspectDNG
Dynamic Proxy
Compose*
Loom.NET
PostSharp
 
Each of these frameworks make use of a number techniques to the injection of code both before and after execution of a method. These generally fall into 4 categories.
 
MSIL injection – Here we inject MSIL code into the body of the method being executed. (Post sharp)
 
Runtime dynamic injection – Using techniques such as reflection we invoke methods dynamically.
 
Type builder injection – R ...
Comments (0) More...

Defensive coding source available.
By David Hanson on Sun, 13 Dec 2009 09:57:57 GMT

I had a request to make the defensive coding source code available.  So here you go.

Download

Comments (1)

Extension method to find the nearest common ancestor of a given type.
By David Hanson on Thu, 10 Sep 2009 14:51:25 GMT

I had a problem recently where I had an inheritance hierarchy of which I needed to find a common ancestor type between two objects. Below shows a quick mock up of the situation I faced.

As you can see the Person type is the common ancestor for both Student and Teacher. In order to solve this issue I decided to write the following extension method for the Type type to be able to locate it easily in the future. Code below for anyone interested. Hope it helps.

    ///
    /// Extension methods for the Type
    ///
    public static class TypeExtensions
    {
        ///
        /// Finds the nearest common ancestor for a given type.
        ///
        /// The type.
        /// Type of the target.
        ///
        public static Type FindCommonAncestor (this Type type, Type targetType)
        {
            if (targetType.IsAssignableF ...
Comments (0) More...

RDL Parameter Reader
By David Hanson on Fri, 28 Aug 2009 08:17:58 GMT

I currently working on retro fitting some SQL server reports into the application we are building. I needed a quick way to view all the parameters each report uses. The code below is a quick snippet to do just that. Just point it at a directory with the RDL files in an away you go.  Note: This code does the bare minimum and is used for SQL Server 2005 RDL. I haven't checked to see if it works on SQL 2008 RDL. Thought it might help someone.

       public Report()
            {
                Parameters = new List<Parameter>();
            }
 
            public string ReportName { get; set; }
            public List<Parameter> Parameters{ get; set;}
        }
 
        ///
        /// Represents a report parameter.
        ///
        public class Parameter
        {
            public
Comments (0) More...

NDC 2009 Videos
By David Hanson on Fri, 03 Jul 2009 10:25:54 GMT
·         Scott Hanselman - Deep Tour of .NET 4
·         Ted Neward - Why the Next Five Years Will Be About Languages
·         Michael Feathers - Seven Blind Alleys in Software Design
·         Jonas Follesø - MVVM Patterns for Silverlight and WPF applications
·         Luca Bolognese - The Future of C#
·         Tim Huckaby -
Comments (0) More...

Defensive Coding
By David Hanson on Fri, 05 Jun 2009 06:33:18 GMT
How often have you seen code like this?
 
private void AllocateRoles(RoleChangeInfo roleChangeInfo)
{
            foreach (Role role in roleChangeInfo.Roles)
            {
                if (roleChangeInfo.Person.Age > 21 && roleChangeInfo.Person is Senior)
                    RoleChangeService.AddRole(rolechangeInfo.Person, role);
            }
      }
 
 
If we deconstruct this code we can see that the method AllocateRoles should received an instance of a RoleChangeInfo which is a container for all the information that is required to add the roles to the appropriate person. If we take a look at the implementation of this type we can see that it’s fairly simplistic.  It holds the ID of the Role and a RoleTaken DateTime.
 
public class Role
{
    public int ID { get; set; }
    public DateTime? RoleTaken { get; set; }
}
 
The body of the AllocateRoles method consists of a simple ForEach iteration around the Roles collection and with each role we check to make sure the person is older than 21 and they are of type senior. If both of these conditions are true then we call the RoleChangeService.AddRole method which will perform the work and update the RoleTaken.
 
I have come across this kind of code many times in the past and it is a good example of where a developer has made a number ...
Comments (2) More...

Microsoft® Silverlight™ 3 Tools Beta 1
By David Hanson on Wed, 18 Mar 2009 15:02:54 GMT

Want to start developing for Silverlight 3.0? Well you can now download the tools you need for Visual Studio from Microsoft.

Download here

Comments (0)

Silverlight 3: Some info!
By David Hanson on Wed, 18 Mar 2009 10:46:11 GMT

Today see's the start of MIX09. As a result I decided to look on the agenda for the sessions that are taking place over the next few days and I came across this little nugget if information on Silverlight 3. The session is titled "What's new in Silverlight 3" The brief synopsis gives us a sneak peak as to what to expect from Scotts Keynote.

"Take a tour of the new features in Silverlight 3 including a dive into some of the new experience oriented features like pixel shaders, perspective 3D, animation enhancements, bitmap APIs and improvements to the media stack. Also hear about new Silverlight base framework additions including updates to the style model, data binding improvements, improved resource handling and improvements to the web services stack."

Looking forward to those 3D demo's already!

Comments (0)

Next SLUG Meeting: Thursday 26th March 2009
By David Hanson on Tue, 17 Mar 2009 13:51:00 GMT

So it s been a while since I have blogged. I wont bore you with the details but what with moving home, project commitments and lots going on in my personal life I've just not had time to focus. This post is to get me started again .

The next SLUG meeting has been announced. You can find details of it here . Its going to follow a GROK TALK format, this means that anyone can have 15 mins talking to the group about experiences they have had with Silverlight. Mark is also looking for MIX attendees to come along and share their thoughts on this years announcements etc.

 

Comments (0)

Is BizTalk Dead - Part 2
By David Hanson on Wed, 26 Nov 2008 21:18:25 GMT

Back at the beginning of the year I wrote a blog post about the awkward conflict that BizTalk faced now that WF was on the scene.  Although at the time of writing there was an obvious cross over between the products, BizTalk still offered a number of key advantages over bog standard workflow. Due to some emails I received I decided to look around Microsoft's code projects and see what I could find. It was way back in Feb that I came across OSLO.

9 Months later and with PDC out of the way, OSLO and Microsofts strategy for WF is far more clear. OSLO seemed to evolve over the last few months into the codename primarily used for the modelling language and toolset announced. Microsoft also showed off a whole new version of WF for .NET 4.0. This new version of WF comes with some major improvements.

  • WF has been rewritten from the ground up.
  • Performance has been dramatically increased
  • Services and Workflow can be written purely with XAML
  • A new customisable designer surface
  • Large number of new activities for developing workflows
  • Seamless integration with WCF

So with WF being upgraded to a spanky new version which offers a wealth of new features please bare in mind that BizTalk'ers are still waiting for their orchestration engine to be updated to use the new WF engine. Given the new version of WF being announced I would be wondering how long its going to take before I see that in BizTalk?

Back to the original OSLO article I found way back in Februrary, the article talked of a new WF hosting engine. This part of the puzzle we now know has been codenamed "Dublin". If you haven't heard of Dublin yet and your into BizTalk then hold your breath as the diagram below (taken from MSDN) may look familiar.

 

 Dublin is the application server that has long been missing from the Microsoft product set. Announced to be a part of Windows Server , Dublin provides a runtime which hosts WF workflows and provides services for persistence, tracking, management, message forwarding and much more. The Dublin runtime is implemented on SQL Server server which allows WF developers to create long running workflows. Prior to Dublin this was only possible by either rolling your own or implementing BizTalk.

Is this sounding familiar to you? Well it doesn't stop there I'm afraid. Dublin can also run as part of farm of servers whereby each instance  can use a single shared persistence store. Dublin also provides automatic workflow activation as part of its message routing architecture.

As you can see Dublin is the future. Even Microsoft recognise the awkward overlap of features as evidenced by this MSDN article.


For anybody familiar with BizTalk Server, looking at “Dublin” might cause a slight sense of déjà vu. Supporting workflow-based logic, providing a monitoring and management infrastructure: These are things that BizTalk Server does today. What’s the future of BizTalk Server in a “Dublin” world?

The key thing to understand is that “Dublin” doesn’t directly target traditional BizTalk scenarios. For example, enterprise application integration and business-to-business connections via EDI will still use BizTalk Server. Similarly, bringing existing applications into the service-oriented world by exposing their functions and/or data through BizTalk Server will continue to make sense. While the reach of “Dublin” may grow over time, BizTalk Server r ...

Comments (1) More...

Silverlight 3D confirmed!
By David Hanson on Mon, 17 Nov 2008 14:16:48 GMT

Scott Gu has a post today highlighting a couple of features that we can expect to see in Silverlight 3. Good to hear on the list are the following

• Increased databinding support (Lets hope we get element binding)
• 3D graphics support (With GPU Acceleration)
• H.264 Codecs for high quality video streams.

His full post can be found here

Comments (0)

Print  
Tweets Minimize
Twitter / LordHanson
  1. LordHanson: Experienced .net dev in sydney for next 5 months if anyone needs me. CV on request just tweet me.

    Published Sun, 29 Aug 2010 05:41:05 +0000 by
  2. LordHanson: Flash on iPad....nice. http://www.tipb.com/2010/07/04/frash-android-flash-ported-ipad/

    Published Sun, 04 Jul 2010 22:07:55 +0000 by
  3. LordHanson: Anyone noticed that when typing on your iPhone it sounds like your holding a gieger counter?

    Published Sun, 04 Jul 2010 22:05:28 +0000 by
  4. LordHanson: Missing wacko's music... What's happened to the album he was working on before he died?

    Published Fri, 25 Jun 2010 23:01:45 +0000 by
  5. LordHanson: New version of Connectify cannot recognise my active Internet connection! Had to roll back to previous version! #fail

    Published Fri, 25 Jun 2010 22:54:54 +0000 by
  6. LordHanson: vuvuzela blowing spoils the world cup! Fact!

    Published Mon, 14 Jun 2010 05:08:43 +0000 by
  7. LordHanson: About http://www.theaustralian.com.au/business/news/us-competition-regulators-to-investigate-apple/story-e6frg90x-1225878779986

    Published Mon, 14 Jun 2010 00:04:45 +0000 by
  8. LordHanson: In the camper van and a storm is coming.....How exciting.

    Published Sun, 25 Apr 2010 04:39:48 +0000 by
  9. LordHanson: My vaio p is doing well while travelling. 3g Internet, HD movies, digital tv, photo editing, wifi router for iPods and much more. Love it

    Published Wed, 10 Mar 2010 10:29:19 +0000 by
  10. LordHanson: Ok so I need to stay techie while away from a computer for a year. Anyone got any ideas.

    Published Mon, 22 Feb 2010 12:31:09 +0000 by
  11. LordHanson: Sitting in YHA Glebe Sydney waiting for the movie night to start

    Published Thu, 18 Feb 2010 08:13:10 +0000 by
  12. LordHanson: Madness today. We only booked our return tickets to bangkok on the wrong day! Luckily we managed to change them!

    Published Wed, 10 Feb 2010 15:54:37 +0000 by
  13. LordHanson: HTML5 the future? http://bit.ly/6yf9Bu

    Published Tue, 09 Feb 2010 13:43:48 +0000 by
  14. LordHanson: Last night in Bangkok! Good fun!

    Published Thu, 04 Feb 2010 18:09:38 +0000 by
  15. LordHanson: @trampussandal Dad? lol

    Published Thu, 04 Feb 2010 05:26:39 +0000 by
  16. LordHanson: Im sitting in a coffee shop in my home town of epsom thinking... Man the day has finally arrived. I can feel the stress lifting.

    Published Mon, 01 Feb 2010 09:05:13 +0000 by
  17. LordHanson: So what excuse will apple use to not allow flash or silverlight to run on the ipad this time I wonder.

    Published Fri, 29 Jan 2010 19:07:46 +0000 by
  18. LordHanson: Yay just manage to upgrade from vista ultimate to windows 7 enterprise by using the registry hack trick. No reinstalls.

    Published Wed, 27 Jan 2010 07:18:07 +0000 by
  19. LordHanson: @swhelband Sure am...http://bit.ly/aZ6Xvd

    Published Tue, 26 Jan 2010 19:05:18 +0000 by
  20. LordHanson: I finished work today in prep for travelling. I must admit as i left the office i felt a little emotional. Sign of a good job with great ...

    Published Tue, 26 Jan 2010 17:48:49 +0000 by
Print  
Archive Minimize
Print  
Contact me Minimize
Print  
Microsoft Certs Minimize







Print  
Silverlight News Minimize
Silverlight - Google News
Print