This weekend I had some fun messing around with the idea of monitoring one of my sites via sounds. All of the sites I run are .Net 2.0 or .Net 3.5, with that it allowed me to create a .Net solution that would work with any of my sites.
The idea started with a single thought of "boy it would be kinda neat to hear a sound when someone viewed a page in my site." So I spent all of 30 mins figuring out what i wanted to do create. I built a simple library for playing sounds based on a file or a path to a file. I then took the new lib and built a simple HttpModule for attaching to a site and tapping into begin request event.
This could be used for monitoring a few different sites along with a few different request types, not to mention that you could also include a different sound for events like, app start, begin request, end request, a request for .* file types (ie: if you wanted to know when someone downloaded one of your .rar files, you could just play a different sound file.) I'm sure that you could prob add a hundred more options to this list if you really wanted to.
Anyway I enjoyed hearing all the hits to my different sites this weekend and thought that you might like to as well.
sound playing lib.
namespace YetAnotherDeveloper.Common.SoundUtility
{
public sealed class Player
{
private Player() { }
public static void PlaySound(string filePath)
{
SoundPlayer player = new SoundPlayer();
player.SoundLocation = filePath;
player.Play();
}
}
}
simple http module example.
namespace YetAnotherDeveloper.HttpModules
{
public class PlaySoundModule : IHttpModule
{
public void Dispose() { }
//Tap into the events.
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
YetAnotherDeveloper.Common.SoundUtility.Player.PlaySound(@"C:\Sounds\PageLoad.wav");
}
}
}
Modified webconfig to include this module in its pipeline.
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
< add name="PlaySoundModule" type="YetAnotherDeveloper.HttpModules.PlaySoundModule, YetAnotherDeveloper.HttpModules"/>
</httpModules>