Click here to Skip to main content
15,891,905 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.5K   6.9K   69  
Describes how to build a Windows Service using the Pegasus Library.
using Pegasus.Diagnostics;
using System;
using System.Collections;

namespace Pegasus.Configuration
{
	/// <summary>
	/// Used to parse the command line parameters and provide simple access methods to the elements
	/// </summary>
	public class CommandLine
	{
		// Local Instance Values
		private Hashtable m_optionsTable = new Hashtable();
		private ArrayList m_valueList = new ArrayList();

		/// <summary>
		/// Default Constructor
		/// </summary>
		/// <param name="args">The command line arguments</param>
		public CommandLine( string[] args )
		{
			// Check params
			ParamCode.AssertNotNull( args, "args" );

			int count = args.Length;
			for( int x = 0; x < count; x++ )
			{
				string option = args[ x ];

				if( option.Length > 2 && ( option.StartsWith( "/" ) || option.StartsWith( "-" ) ) )
				{
					option = option.Substring( 1 ).ToLower();

					if( x + 1 < count )
					{
						string val = args[ x + 1 ];
						if( val.Length > 2 && ( val.StartsWith( "/" ) || val.StartsWith( "-" ) ) )
						{
							m_optionsTable[ option ] = string.Empty;
						}
						else
						{
							m_optionsTable[ option ] = val;
							x++;
						}
					}
					else
					{
						m_optionsTable[ option ] = string.Empty;
					}
				}
				else
				{
					m_valueList.Add( option );
				}
			}
		}

		/// <summary>
		/// Will check to see if an option exist on the command line
		/// </summary>
		/// <param name="option">The name of the option without a / or -.</param>
		/// <returns></returns>
		public bool Exist( string option )
		{
			return m_optionsTable.ContainsKey( option.ToLower() );
		}
	}
}

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