Class documentation is included in the download. Usage documentation is below:

The system only requires a couple of classes to be created (along with the tasks themselves). The first of which is the config classes. The system uses Gestalt.Net for configuration, the documentation for which can be found here: http://gestaltnet.codeplex.com/Thread/View.aspx?ThreadId=212599. The first item to configure is the logging system. Internally the system uses Blammo.Net for logging (you can easily swap this out for log4net or something or simply remove the logging code without too much difficulty). In order to get the logging system working, please read the documentation here: http://blammonet.codeplex.com/documentation.

Once the logging system is set up, the next bit of code is the config class for the task manager itself. This requires a simple class that inherits from Configuration class:

    public class TaskSchedulerConfig:EchoNet.Configuration.Configuration
    {
    }


Note that there is only one property to override that really matters (besides the default Gestalt.Net properties), NumberOfThreads. This actually determines the number of threads to create for the tasks (more than one task can occupy a thread if you desire). By default this is set to 4. Once that class is set up, the next thing to do is actually create your task and the configuration class for it. As an example:

    public class Task1:EchoNet.Task
    {
        public override void DoWork()
        {
            try
            {
                Utilities.FileManager.SaveFile("This is a test", @"C:\MyFiles\File1.txt");
            }
            catch { throw; }
        }
    }


Each individual task inherits from the Task class in the code base. It exposes one function that must be overridden, DoWork. The DoWork function is where your task actually does its function (delete items from a database, system backup, basic maintenance, etc.). The only other thing that is exposed is the class's config object. The config object would look something like this:

    [Gestalt.Attributes.Config(Name = "Task1")]
    public class Task1Config : EchoNet.Configuration.TaskConfiguration
    {
        public Task1Config()
        {
            NextRunTime = new DateTime(2010, 5, 20, 11, 11, 0);
            Start = new DateTime(1900, 1, 1);
            End = DateTime.MaxValue;
            Frequency = EchoNet.Enum.RunTime.Hourly;
        }

        protected override string ConfigFileLocation { get { return @"C:\MyApp\Data\Task.config"; } }
    }


This uses the TaskConfiguration class as the base, which creates a couple properties that the system needs to know (mainly when to run the system). This config class first sets the config objects name to Task1 using the Config attribute from Gestalt.Net. This associates this config class with the Task1 task that we defined before. It then sets the defaults for the task (when to start running the task, when to stop running the task, the next time to run it, and the frequency in which to run it). Lastly it overrides the config file location so that the system saves the config file (thus allowing us to modify the configuration in the XML file if we want. However we could store extra information for us in the config class as well. For instance we could do the following:

    [Gestalt.Attributes.Config(Name = "Task1")]
    public class Task1Config : EchoNet.Configuration.TaskConfiguration
    {
        public Task1Config()
        {
            NextRunTime = new DateTime(2010, 5, 20, 11, 11, 0);
            Start = new DateTime(1900, 1, 1);
            End = DateTime.MaxValue;
            Frequency = EchoNet.Enum.RunTime.Hourly;
        }

        protected override string ConfigFileLocation { get { return @"C:\MyApp\Data\Task.config"; } }
        public string MyFileLocation{get;set;}
    }


the MyFileLocation property would be saved along with the other information, and thus we could use it to set the location that Task1 was saving the "This is a test" text. You will have to convert the Config property to Task1Config from the default TaskConfiguration, but it can easily be done. Once the configuration and the task itself are created, all that needs to be done is start up and shut down. In a web app it would look something like this:

    public class Global : System.Web.HttpApplication
    {
        protected static BlammoNet.Manager LogManager = null;

        protected void Application_Start(object sender, EventArgs e)
        {
            Gestalt.Manager.Instance.RegisterConfigFile(typeof(Default).Assembly);
            LogManager = BlammoNet.Manager.Instance;
            EchoNet.Manager.Instance.Start(typeof(Default).Assembly);
        }

        protected void Application_End(object sender, EventArgs e)
        {
            EchoNet.Manager.Instance.Stop();
            if (LogManager != null)
            {
                LogManager.Dispose();
                LogManager = null;
            }
        }
    }


The code above, in the ApplicationStart function, sets up the config manager, starts logging, and then starts the task manager. In the ApplicationEnd function, it stops the task manager and then stops logging. That's all there is to it, the system handles the rest.

Last edited Jun 1, 2010 at 5:36 PM by JaCraig, version 1

Comments

kishanhathiwala Sep 20, 2010 at 6:10 AM 
Very nice. thank you