Command Pattern Tutorial: Part Two


This is part two of a tutorial to create a Home Automation Program, using the Command Pattern.  It assumes you have already read  part one

I have used NUnit to unit test my  classes,  and I have provided the test script I created in my subversion repository

Now that I have created the classes I need, I have coded an ASP.NET web project using those classes.

You can demo the Remote Control Application here (UPDATED: This is now hosted on the Azure cloud)

This version is implemented without using AJAX, and uses traditional postbacks instead. Look and feel is very basic, as an AJAX version of the site will posted in a future blog post.

The source code for this site is available

The left hand panel displays the remote control for the home automation system, and contains seven slots Command Slots. Initially there are no commands set in these slots, so the on and off buttons are disabled. To add a Command to a slot, the user may click the Edit button to select a list of available commands. Once a command is selected, it may be turned on or off by clicking the on or off button for that slot.

To the right hand of the page, the status panel displays the state of the appliances for the house, which are by default, turned off. Once an on or off button is clicked, the status of the appliances will be updated.

The list of available commands is kept in the database, when a new House object is created, it’s list of commands is retrieved and then instantiated.

The Drop Down List is populated as thus:

private void LoadCommandsDropDownMenu(House h)
{
ArrayList array = h.CommandList;
ArrayList DDarray = new ArrayList();
DDarray.Add("Select Command");
foreach (House.command_pair cmds in array)
{
DDarray.Add(cmds.Name.ToString());
}
DDCommandList.DataSource = DDarray;
DDCommandList.DataBind();
}

If we update the Command Objects table in the database we can add new commands. We can even update the list of valid commands without changing existing code. By using the pattern we can change the commands of each command slot at runtime.

My next post will show how to use implement some nice AJAX features using JQuery.

,

  1. No comments yet.
(will not be published)


Page optimized by WP Minify WordPress Plugin