Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code
more resources

Create a .NET Agent
Save time with a dynamically configurable job scheduler and notification service using the .NET Framework.
by Luther Miller

March 14, 2005

Technology Toolbox: VB.NET, C#, XML, .NET Framework 1.1

You’ve probably thought about creating a Windows service if you’ve ever needed to create a continuously running job. Maybe you’ve also considered ways to monitor critical systems and alert someone if anything is not as it should be. Imagine receiving a message on your cell phone if your Exchange server is running out of free space, or an e-mail if last night’s batch job hasn’t finished yet. Or perhaps you have several tasks that need to be scheduled, but you would like more control than what Windows Task Scheduler provides. Setting up an agent that combines a job scheduler and a notification service offers a wide range of useful applications.

ADVERTISEMENT

I’ll show you how to create an extensible framework for a .NET agent, as well as implementations and examples for key components. My agent framework contains several base classes that work together (see Figure 1). The manager oversees a collection of jobs. Each job has schedulers, notifiers, and a worker. The manager is responsible for checking each of the jobs’ schedulers periodically. When a job is scheduled, an event kicks off the job’s worker. The worker comes back with a result, and notifications may be sent out based on that result.

To illustrate, let’s say you want to create a job that transmits an updated file via FTP every hour of every weeknight. You want to send an e-mail notification only if a transmission fails. First, you create a worker class that can transmit a file via FTP. You can use the scheduler and notification classes I’ve included in the code samples to do the rest. Add a new job to the agent configuration file, specifying a scheduler, the worker, and a notifier. You may supply multiple schedulers and notifiers for a single job, but only one worker.

I’ll also show you how to create a class loader that reads jobs from an XML configuration file. In order to do this, you process an XML document and instantiate objects dynamically. This means you can add new worker classes, for example, simply by providing their assembly DLLs and adding references to them in the configuration file. The loader uses reflection to load the properties and fields of the classes from the configuration file. The loader is mainly generic and may be reused in a wide variety of other applications.

This article requires registration. Please login below or click here to register.
 
E-mail Address:
Password:
Remember me:
 



Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home