Click here to Skip to main content
15,879,239 members
Articles / Programming Languages / C#

The Favalias Application

Rate me:
Please Sign up or sign in to vote.
4.92/5 (27 votes)
30 Sep 20037 min read 70.7K   2.6K   52  
Favalias application enables you to manage your favorites web sites in an XML file and to launch your favorites application using aliases. You can also make your own addins (in any .NET language) to call your own code.
// Jean-Christophe Magnon
// jcmag@yahoo.com
#region Copyright � 2003 The Favalias Group
/*
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not claim
 * that you wrote the original software. If you use this software in a product,
 * an acknowledgment in the product documentation is required, as shown here:
 *
 * Portions Copyright � 2003 The Favalias Group (http://sourceforge.net/projects/favalias).
 *
 * 2. Altered source versions must be plainly marked as such, and must not be 
 * misrepresented as being the original software.
 * 
 * 3. This notice may not be removed or altered from any source distribution.
*/
#endregion

using Favalias.Common;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Genghis;
using clp = Genghis.CommandLineParser;
using myTimer = System.Timers.Timer;
using System.Timers;

namespace Favalias.Addins
{
	/// <summary>
	/// Summary description for Alarm.
	/// </summary>
	public class Alarm : Favalias.Interfaces.IFavaliasAddin
	{
		public string message;
		private string _skin;
		
		#region CLP
		[clp.ParserUsage("Alarm", AllowArgumentFile=false)]
			private class argsParser : CommandLineParser
		{
			[clp.ValueUsage("Message to display", Optional=false, MatchPosition = true)]
			public StringCollection message = new StringCollection();

			[clp.ValueUsage("The alarm timespan (format : 0h0m0s ; you can specify only one argument : 2m for exemple)",
				 LegalValues=@"^(\d+[hms]){1,3}$", Optional=false, Name="ts")]
			public string timespan; // @"^(\d+h)?(\d+m)?(\d+s)?$"
		}
		#endregion

		public Alarm()
		{}

		#region IFavaliasAddin Members

		public void Execute(string[] args, Hashtable parameters)
		{
			_skin = (string)parameters["skin"];
			argsParser parser = new argsParser();
			if(!parser.ParseAndContinue(args, (string)parameters["alias"], Assembly.GetExecutingAssembly()))
				return;

			Regex myRegex = new Regex(@"^((?'hour'\d+)h)?((?'minute'\d+)m)?((?'second'\d+)s)?$");
			Match m = myRegex.Match(parser.timespan);
			int hour = 0;
			int minute = 0;
			int second = 0;
			if(m.Groups["hour"].Value.Length != 0)
				hour = Convert.ToInt32(m.Groups["hour"].Value);
			if(m.Groups["minute"].Value.Length != 0)
				minute = Convert.ToInt32(m.Groups["minute"].Value);
			if(m.Groups["second"].Value.Length != 0)
				second = Convert.ToInt32(m.Groups["second"].Value);
			Debug.WriteLine(hour + "-" + minute + "-" + second);
			TimeSpan ts = new TimeSpan(hour, minute, second);
			myTimer t = new myTimer(ts.TotalMilliseconds);
			
			message = Utilities.StringCollectionToString(parser.message);
			
			t.Elapsed += new ElapsedEventHandler(t_Elapsed);
			t.AutoReset = false;
			t.Enabled = true;
		}

		#endregion

		public void t_Elapsed(object sender, ElapsedEventArgs e)
		{
			Utilities.ShowAnimateMessage(message, Genghis.Windows.Forms.FormPlacement.Tray, _skin);
			
		}

				
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
France France
I am an MCSD.NET and MCT. I give a lot of Microsoft Trainings (www.bdcworld.com) in France.

Comments and Discussions