Click here to Skip to main content
15,897,371 members
Articles / Desktop Programming / Windows Forms

Windows Services Made Simple

Rate me:
Please Sign up or sign in to vote.
4.62/5 (10 votes)
27 Jun 2007CPOL10 min read 94.6K   6.9K   69  
Describes how to build a Windows Service using the Pegasus Library.
using System;
using System.IO;

namespace Pegasus.Diagnostics.Telnet
{
	/// <summary>
	/// Implements the Quit command for the telnet service
	/// </summary>
	internal class CommandQuit : ITelnetCommand
	{
		// Local Instanc Values
		private TelnetProcessor m_processor;

		/// <summary>
		/// Default Constructor
		/// </summary>
		/// <param name="processor">The telnet process handing this session</param>
		public CommandQuit( TelnetProcessor processor )
		{
			m_processor = processor;
		}

		/// <summary>
		/// The names of the command that the user types in.
		/// </summary>
		public string Command
		{
			get
			{
				return "quit";
			}
		}

		/// <summary>
		/// Any short cut commands or key (i.e. quit uses q and exit)
		/// </summary>
		public string[] CommandShortCuts
		{
			get
			{
				return new string[] { "q", "exit" };
			}
		}

		/// <summary>
		/// Execute the command.
		/// </summary>
		/// <param name="args">Additional parameters that the user typed in.</param>
		/// <param name="writer">Text stream to write to</param>
		public void ExecCommand( TextWriter writer, string[] args )
		{
			m_processor.Stop();
		}

		/// <summary>
		/// Show a single line of help about the command
		/// </summary>
		/// <returns>Single line brief description of command</returns>
		public string GetHelp()
		{
			return "End the telnet session.";
		}

		/// <summary>
		/// Show a the full usage help about the command
		/// </summary>
		/// <param name="writer">Text stream to write to</param>
		public void ShowDetailedHelp( TextWriter writer )
		{
			writer.WriteLine( "Command: quit | q | exit" );
			writer.WriteLine( "Usage: quit" );
			writer.WriteLine();
			writer.WriteLine( "Description:  This end the current telnet session." );
		}
	}
}

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
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions