Click here to Skip to main content
Click here to Skip to main content
Go to top

MyAlerts Notification Application

, 19 Nov 2003
Rate this:
Please Sign up or sign in to vote.
A sample application to create Alert Notifications on your desktop (i.e. Instant Messenger "toast")

Introduction

The purpose of this application is to create a simple Notification application (ala Instant Messenger). Upon receiving an alert, the application will display some "toast" in the lower right-hand corner of your desktop. The alert will display a message and will execute an action when clicked on.

Background

The idea for this application came as a result of trying to come up with something "cool" for sale's demos. Customers love demos that illustrate "real-time" notification of business events. While this functionality does exists via several Microsoft products (i.e. SQL Server Notification, MSN Alerts and Real-Time Communication Server), the infrastructure/cost to configure/support/program these applications can be quite overwhelming. Often, sales demos are done on standalone laptop machines that are not always connected to a network. This simple application demonstrates the value of real-time communication without having to be a technology guru to get it up and running.

The use case scenario described above is also the reason MyAlerts is written completely in script code. It makes it easy to do modifications without having to recompile/redeploy code. Also, I am a strong advocate of keeping things as simple as possible so that semi-technical people can understand how the application works and make improvements and/or modifications.

I have included two versions of Alert Controllers:

  1. AlertController.hta is based on creating alerts using pop-up "toast" similar to that used in popular Instant Messenging products.
  2. AgentAlertController.hta uses Microsoft Agent Technology combined with a Speech Engine to create a more interactive alert.

Using the code

To install this application,

  1. Extract the contents of the zip file to c:\MyAlerts
  2. Execute AlertController.hta or AgentAlertController.hta (app will be minimized on startup)
  3. Execute one of the samples in the samples subdirectory (i.e. CreateAlert.hta)

An optional step that I usually perform is to add a shortcut to [Agent]AlertController.hta to my Window's Startup Group so that the application restarts on a reboot.

Alerts are triggered when a file is written to the \MyAlerts\queue subdirectory. The structure of the file is quite simple. It is a text file containing a text string in the following format:

Text To Display|URL to Execute|Voice to announce alert in

Basically, 3 text strings delimited by the |(pipe) character. For example, a file with the following contents ...

Hello Microsoft|http://www.microsoft.com|en-UK_female

will display an alert announced in a female voice with a UK accent with the text message "Hello Microsoft". Note that the "voice" parameter is only relevant to AlertController.hta. The voice for AgentAlertController.hta is dependant on which speech engine you have installed. When clicked upon the alert will take you to the Microsoft Web Site.

Voice Options include

  • en-US_female
  • en-US_male
  • en-UK_female
  • en-UK_male
  • en-AUS_female
  • en-AUS_male

To trigger an alert, all your application has to do is write a text file with the above structure to the \MyAlerts\queue subdirectory. For example, from your C# .NET app, you can do something like:

TextWriter output = File.AppendText("c:\\MyAlerts\\queue\\" + 
                                    System.Guid.NewGuid()+".txt");
output.Write("Hello Microsoft|http://www.microsoft.com|en-UK_female");
output.Close();

The file MyAlertsWS.asmx in the samples subdirectory contains a .Net WebService that triggers notifications. Simply copy this file to c:\inetpub\wwwroot and execute it via

http://localhost/MyAlertsWS.asmx

Or from a Window's VBScript file, you can do something like

Set myTypeLib = CreateObject("Scriptlet.Typelib")
GUID = left(trim(myTypeLib.guid),38)
szFileName="c:\MyAlerts\queue\" & GUID & ".txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile(szFileName, True)
tf.WriteLine("Hello Microsoft|http://www.microsoft.com|en-UK_female") 
tf.Close

Or if you prefer JScript, you can do something like

var myTypeLib = new ActiveXObject("Scriptlet.Typelib");
var GUID = new String(myTypeLib.guid).substr(0,38);
var szFileName="c:\\MyAlerts\\queue\\" + GUID + ".txt"
var fso = new ActiveXObject("Scripting.FileSystemObject")
var tf = fso.CreateTextFile(szFileName, true);
tf.WriteLine("Hello Microsoft|http://www.microsoft.com|en-UK_female");
tf.Close();

You can even Trigger Alerts directly from SQL Server by using a SQL Trigger to execute the stored procedure located in samples\CreateAlert.sql. For example, assuming you have created the sp_CreateAlert stored procedure in the NorthWind Database, you can do something like the following:

--Create Trigger on Customers Table in Northwind Database
CREATE TRIGGER DataChanged ON Customers
FOR INSERT, UPDATE, DELETE
AS EXEC sp_CreateAlert 'Customer Changed','http://www.microsoft.com',
                       'en-UK_male'

GO

Points of Interest

MyAlerts supports skinning (i.e. themes) and by default shows a different skin whenever an alert occurs. To change this behavior, simply edit the file ShowAlert.hta in notepad and modify the following lines of code:

//Set this to false if you want to use the default skin
var enableRandomSkin = true;

//Change default skin here
var defaultSkin="skins/msn_default.jpg";

//Change default voice here ... choices include 
//    en-US_female.wav
//    en-US_male.wav
//    en-UK_female.wav
//    en-UK_male.wav
//    en-AUS_female.wav
//    en-AUS_male.wav
var defaultVoice="en-US_female.wav";

For example, the following screenshot shows an alternative skin:

NOTE: AgentAlertController.hta makes use of Microsoft Agent ActiveX Controls as well as Speech Engines. If AgentAlertController.hta does not work or generates errors, you may have to download the required components at Microsoft Agent Downloads

NOTE: All images uses for skinning were obtained via Wincustomize.com and are copyright via their respective owners.

History

  • Modified October 30, 2003
    • Added AgentAlertController.hta to demonstrate use of Microsoft Agent Technology
    • Added StockAlertController.hta to demonstrate how to trigger an alert based on a Web Service call.

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

Share

About the Author

Mike Parsons
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralWhen I invoke a message through asmx page XML code shows up on my browser PinmemberMember 349710922-Oct-08 13:05 
Questionhow to run HTA in system tray Pinmembermravi_prakash1-Apr-06 22:42 
AnswerRe: how to run HTA in system tray PinmemberBrad Baumann18-Jun-06 13:39 
QuestionHow to Use MyAlerts Pinmembergaurav2ks@yahoo.com21-Jul-05 1:41 
GeneralA little question Pinmemberc0br414-Dec-04 12:00 
Question.NET? PinmemberTy Moffett15-Apr-04 10:57 
GeneralVisual Studio compiler throws errors Pinmemberp3n6-Feb-04 0:54 
GeneralRe: Visual Studio compiler throws errors Pinmemberp3n25-Feb-04 3:29 
QuestionDoesn't alert? Pinmemberpillbug2221-Oct-03 4:03 
AnswerRe: Doesn't alert? Pinmemberpillbug2221-Oct-03 4:07 
GeneralHide AlertController. PinmemberJustAGhost20-Oct-03 22:03 
GeneralRe: Hide AlertController. PinmemberMike Parsons23-Oct-03 3:02 
GeneralRe: Hide AlertController. PinmemberJustAGhost23-Oct-03 20:50 
GeneralRe: Hide AlertController. Pinmemberpatrickbutterfield4-Nov-04 7:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 20 Nov 2003
Article Copyright 2003 by Mike Parsons
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid