Wednesday, May 9, 2012

Advanced Distributed Systems Design with SOA

I recently attended the course "Advanced Distributed Systems Design with Service Oriented Architecture" with Udi Dahan. I found this course to have a profound impact on the way that I think about software design. This course was the most intense 5 days of my professional life and I would highly recommend attending it if you get a chance.

I found Udi to be a unique presenter in the way that he was incredibly balanced, and reasonably unbiased in the way he presented the topics at hand, and while he has a vested interest in his own product NServiceBus it is not spouted as the only way to do Enterprise Service Buses (ESB), nor that ESBs are the only way to build a system architecture.

I am writing this series of posts as a way to internalize what I have learned, and so I will follow closely the Topics of the course (however I wouldn't recommend substituting this resource for Udi's course):

  1. Distributed Systems Theory
  2. Coupling in Distributed Systems
  3. Messaging Patterns
  4. Architectural Styles, Bus and Broker
  5. Service Oriented Architecture Building Blocks
  6. Service Structure
  7. Scalability and Flexibility Monitoring and Management
  8. Long Running Processes
  9. Service Layer - Domain Model Interactions
  10. Web Services and User Interfaces
Many thanks to Udi and all those that made it possible for me to attend such a mind opening course.

Tuesday, March 15, 2011

Pandora's Box

About 3 years ago, I worked in Sydney and commuted to work by train. I spent many hours on the train due to the 2.5hr commute and got home late every night. I found that I didn't have much of an opportunity to wind down at the end of the day and catching up with friends was hard because it was late by the time I got home.

So I decided to take up a hobby.

Watching the TV one morning before heading off to the train station I saw an ad for one of those build an <insert crafty thing here> magazine subscription. This one in particular was a model of an aircraft carrier and I was inspired. I bought the first magazine for $2.95 or whatever the reduced first magazine hook price it was and then proceeded to read up about it. I soon discovered that the price of the next edition was obscenely more ($15 or so) and that the number of magazines in the subscription was around 100........... i.e. $1500 to get all the parts of the ship!!!!!!

This price did not include tools, glue, paints, etc. but rather just the parts that made up the ship. Not exactly the investment I was looking for. So a quick trip down to the local hobby shop one weekend and I found that they supplied a whole stack of model boats/ships/etc. of different skill levels, complexity and quality.

The attendant at the shop advised me to take on one of the smaller, less complicated boats as my first attempt into the world of model ship building but I wasn't listening to that.

Now being the technical Genius (ahem cough splutter) type of person I figured that I had some sort of a clue to how things are made. This was also fueled by the fact that I took Design and Technology (Workshop for those of you who are not in the Australian school system) at School and I decided that I had a fighting chance at building one of the slightly more adventurous ships on display.

Ultimately my intent was not so much of buying a kit that I could quickly put together, rather I was more focused on the process of building the model as a pass time. So I selected a ship that looked pretty and was in my budget rather then trying to match one to my perceived skill level.

The kit I ended up buying was produced by a company called Constructo and it is a model of the HMS Pandora which I later discovered played a minor role in Australian history.

And so I began.

Now for the first little while I went really well, I put in an hour or two every night after work and the ship took shape. I discovered that one of the parts from the magazine subscription came in really handy (a part of the deck laser cut into a piece of plywood) and keeping this piece in its original state it made a great surface for steaming the planks of wood on with my mums clothes iron.

But there were changes on the horizon.

Not too long after buying this kit I decided to leave my job in Sydney after finding about an opening with where I work now. And soon after fell in love with my beautiful wife, and the time I dedicated to my project dwindled to nothing.

After a while I packed up my incomplete ship into a box and stored it away hoping to return to it when things settled down after my wedding. The house we moved into as newlyweds was rather small and we never fully unpacked there. Then after a year our circumstances changed and we were able to afford to live in our own home.

A few months passed since moving in and I remembered my ship and decided to work on it again. So I cleared some room in my study and set up a card table and unpacked my ship.

Since then I have completed the the hull, and started to add the detail to it. I have a long way to go to complete it as I have to cut out all the little bits, paint the various metal parts, sew the sails and tie all the rigging, but it is slowly taking shape, and I am having a ball working on it once again.

So here is the progress of my ship so far

Hope you enjoyed.

Cheers

Monday, January 17, 2011

Uninstalling Web Applications using WiX

I have recently been playing around with windows installers at work for our projects. I have never before had much success with this as I never put much effort into learning about creating installation files. So when a colleague turned up a Visual Studio project type called WiX i had a look.

Now using WiX is much the same as using MSBuild as it is all written in XML. I have never really liked XML based scripting as it is very verbose but WiX seems ok.

At work I we create installers for all of our web applications and have always had the problem of not being able to specify a custom name for the app in the installer as we were not able to uninstall it. So I reciently set about finding a solution.

After a few hours of googling I found this post on the WiX message board. The post was basically states that you store the custom name in a registry entry and call it back on uninstall. The example was a little bit unformatted for my liking but I managed to get the general idea of it.

After a bit of hacking I came up with this solution:


<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="new guid here" Name="Product Name" >

<Property id="WEBAPPNAME">
<RegistrySearch id="WebAppName" root="HKLM" key="Software\[Manufacturer]\[ProductName]" name="WebAppName" type="raw"></RegistrySearch>
</Property>
<SetProperty id="WEBAPPNAME" value="WebAppName" after="AppSearch">WEBAPPNAME=""</SetProperty>

... Any extra properties and conditions here ...

<Media id="1" cabinet="media1.cab" embedcab="yes"></Media>
<Directory id="TARGETDIR" name="SourceDir">
<Directory id="ProgramFilesFolder">
<Directory id="INSTALLLOCATION" name="[ProductName]">
.... Add Files using components here ...

<Component id="WebAppNameComponent" guid="new guid here">
<RegistryValue id="WebAppName" root="HKLM" key="Software\[Manufacturer]\[ProductName]" name="WebAppName" type="string" value="[WEBAPPNAME]"></RegistryValue>
</Component>
<Component id="WebAppSetupIIS" guid="new guild here" keypath="yes">
<iis:WebVirtualDir id="WebApplicationDirectory" alias="[WEBAPPNAME]" Directory="[ProductName]" website="DefaultWebSite">
<iis:WebApplication id="WebApplication" name="[WEBAPPNAME]">
... IIS Settings here ...
</iis:WebApplication>
</iis:WebVirtualDir>
</Component>
</Directory>
</Directory>
</Directory>

<iis:WebSite id="DefaultWebSite" description="Default Web Site">
<iis:WebAddress id="AllUnassigned" port="80"></iis:WebAddress>
</iis:WebSite>

<Feature id="Complete">
<ComponentRef id="WebAppSetupIIS"></ComponentRef>
<ComponentRef id="WebAppNameComponent"></ComponentRef>
</Feature>

... Any UI stuff here ...
</Product>
</Wix>


So Basically I start a new WiX file and add a Product as you normally would in WiX.

I added a new Property called WEBAPPNAME (All in caps for some reason in WiX I have yet to research). And in this Property I do a RegistrySearch (search in the Windows Registry) for a key that is defaulted to the product name with a value for the WebAppName.

And since this has not been set in the initial installation of this product I perform a SetProperty and give it a default value. However this will overwrite any value that may exist so I put a condition on it that specifies that WEBAPPNAME has no value. And tell it to execute after an event called AppSearch which is when the registry is searched.

I then set up the directory structure of the install and add some Components to the directory.

The first Component is the WebAppNameComponent and this creates a value in the registry to the value of WEBAPPNAME. This registry value will also be removed on uninstall but exists solely to provide the name of the application at uninstall time.

The next Component is the WebAppSetupIIS component and this creates the entry in IIS providing the current directory as a virtual directory in IIS and sets the name of the virtual directory to the value of WEBAPPNAME.

Next I specified the WebSite that the web application would reside in and finally added the two components above into the feature by using the ComponentRef tags.

The rest of the file was just setting up the user interface and other things.

The final thing worth mentioning is that I added an entry in the UI to be able to change the name of the Virtual Directory in the installer.

All I needed to do was add these lines of code to the Dialog file in my project:


<Control Id="WebAppNameLabel" Type="Text" Text="Web Application Name:" />
<Control Id="WebAppNameEdit" Type="Edit" Text="[WEBAPPNAME]" Property="WEBAPPNAME" />

NOTE: Positioning and Size information removed for brevity from these tags

Well that is about it for uninstalling web applications with custom names.

Cheers.

Wednesday, October 13, 2010

MVC on IIS6 Blues

I have recently been working on a project where I have just converted an old ASP.NET WebForms app to use MVC 2. I developed it on my local machine which is running Windows 7 and hence IIS7 which has been great.

I got it all working properly and now I have just been working on getting it deployed onto a test server. This is when I realised that Production is running IIS6.

So I fire up Google and search for running MVC 2 apps on IIS6 and found a lot of great advice, in particular Phil Haack's great walk through on ASP.NET MCV on IIS 6 which was most helpful on getting the routing working MVC style.

However I ran into a problem when I started to try and navigate through my Partial Views, of which I had a few all working on a single page using Ajax. I found that the ActionLink's didn't work how I had anticipated as I had set them to replace the contents of a particular div. Instead they rendered as a new page.

I tried Googling this issue and nothing seemed to come up anywhere, so I looked a little closer in my application. I opened up the Internet Explorer 8 Developer Tools and found that I was getting a Javascript Error:

Line: 90
Error: 'Sys' is undefined
A quick Google bought up a whole bunch of results talking about Script Managers and not having the latest version of ASP.NET AJAX Extensions, but checking through these wielded no success.

Again to IE8 Developer Tools. I opened up the Script tab in the Developer Tools and found the drop down list of all the Scripts on the page.



What I noticed was this:
The first set of entries (above the divider) was for the address of the page. http://localhost/<site name>/Home.

And the second set of entries (below the divider) was the address of the list of scripts that were referenced by the page. http://localhost/Scripts.

This reveled the problem immediately as the scripts address was missing the <site name> in the URL.

My problems lay in the head tag of my MasterPage and the way that IIS6 performs the
routing.

The standard markup that comes out of the box is:
<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.4.1.min-vsdoc.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script>
Whereas to get it working I needed to remove the first ../ from the src property in each of the script tags:
<script src="../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="../Scripts/jquery-1.4.1.min-vsdoc.js" type="text/javascript"></script>
<script src="../Scripts/jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script>
This resulted in the script files being properly referenced and everything just worked as if by magic.

I hope that this can be a help for anyone else that has experienced the same problem.

Wednesday, June 23, 2010

Compile-safe MemberInfo Selection

I have been playing around with Windows Forms in .NET and in particular the ComboBox control.

I decided to initialise the combo box like so:

private void SetComboData(IList<SupporterRecord> supporters)
{
var bindingSource = new BindingSource { DataSource = supporters };
comboBox1.DisplayMember = "OpportunityName";
comboBox1.ValueMember = "SupporterId";
comboBox1.DataSource = bindingSource;
}



Notice how the DisplayMember and ValueMember variables are being set by hardcoding the string name of the property that exists on the SupporterRecord class.

This is horrible because I get no compile-time checking of the Property names.

I want to be able to use a Lambda expression to do something like this:


// get the Property item via reflection
MemberInfo member = SupporterNumber.GetMemberinfo(s &eq;> s.OpportunityName);

// and get the name of the property
string name = member.Name;


I found a code snippet on the StackOverflow site to almost do this.

Thinking about this further I also want to be able to do this in the general case for all object types. In comes Extension Methods.


public static class ClassExtensions
{
public static MemberInfo GetMemberInfo<TSupporterRecord>(this TSupporterRecord r, Expression<func<TSupporterRecord, object>> expression)
{
var member = expression.Body as MemberExpression;
if (member == null)
throw new ArgumentException("expression returns no member.", "expression");

return member.Member;
}
}


Usage is as follows:


private void SetComboData(IList<SupporterRecord> supporters){
var bindingSource = new BindingSource { DataSource = supporters };
comboBox1.DisplayMember = ((SupporterRecord)null).GetMemberInfo(s => s.OpportunityName).Name;
comboBox1.ValueMember = ((SupporterRecord)null).GetMemberInfo(s => s.SupporterId).Name;
comboBox1.DataSource = bindingSource;
}



Now it is not entirely the way I want it but it is getting close as I want:


MemberInfo member = SupporterNumber.GetMemberinfo(s => s.OpportunityName);


which is a static method on the class so I started Googling for static extension methods but there is currently no implementation of this, but a number of people saying how cool it would be to have it.

Maybe in later releases of .NET we will see this and I'll be able to perfect my API.

Cheers

Wednesday, September 16, 2009

New Project: Idea: FreeSummit

I have decided that I am going to start on a new project. I have been trying to think up ideas of what I am going to base my project on and have come up with an enterprise application based on where I currently work and how I would like the current software to run. I am wanting to base it on Microsofts ASP.MVC and see if I can use JQuery.

I intend this to be a learning excercise and a chance to cement much of my current learnings.

Tuesday, March 31, 2009

Future Learnings

I am a big advocate of self continuous improvement, and I am constantly looking for new resources for learning my trade.

This morning in my daily web trawl I came across this link talking about how to become a hacker.

And it inspired me to use some of my spare time to learn a few more programming languages.

In the article Eric gives his recommendations on what languages to learn:
So far the programming languages under my belt are (I have left out scripting languages such as HTML):
  • C# .NET (this is my current language of choice)
  • Java (My University had a bend towards teaching Java as a first language then really didn't touch on other languages too much).
  • BASIC
  • Javascript
I started programming at the command prompt of an old Apple IIe then progressed to QBASIC then Visual Basic before going to uni and learning Java and seeing the light ahem... discovering new more powerful languages.

I'm also wanting to delve deeper into multi threaded and parallel programming as I can see that the future is in spanning across multiple CPU cores.

Well that's about all for today.