Click here to Skip to main content
15,883,623 members
Articles / Programming Languages / C#

Distributed Command Pattern - an extension of command pattern for connected systems

Rate me:
Please Sign up or sign in to vote.
4.87/5 (74 votes)
25 Jan 2005CPOL16 min read 262.5K   2.7K   252  
Distributed Command Pattern is a pattern for connected systems which implements command pattern. It frees designers from thinking about the communication and helps them concentrate on implementing commands as if it is a regular desktop application. The framework takes care of the communication.
using System;

using DistributedCommand.Framework;

namespace DistributedCommand.Chat
{
	/// <summary>
	/// Client has been left and conversation
	/// </summary>
	[Serializable]
	public class ClientLeftCommand : UICommand, ICommand
	{
		public ConnectedClient Client;
		public ClientLeftCommand( ConnectedClient client )
		{
			this.Client = client;
		}

		void ICommand.Execute()
		{
			object itemToRemove = null;
			// Remove the client from the client list
			foreach( ConnectedClient client in base.UI.ClientListBox.Items )
			{
				if( client.ID == this.Client.ID )
				{
					base.UI.ChatHistoryTextBox.AppendText( 
						client.Name + " has left the room" + Environment.NewLine );
					itemToRemove = client; 
					break;
				}
			}

			if( null != itemToRemove )
			{
				base.UI.ClientListBox.Items.Remove( itemToRemove );
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions