Jump to content

Cron - Windows Service in C#


Recommended Posts

I have been working on a Cron implementation for Windows using C# and the .NET 3.5 framework.  It will offer similar functionality to the Unix Cron daemon, but for Windows.  A unique part of my implementation of Cron is the XML configuration file which is XML rather than plaintext.  Below is an example CronTab.xml.

<?xml version="1.0" encoding="UTF-8"?>

<CronTab>
    <!-- Run SomeExecutable.exe every quarter past the hour -->
    <CronJob>
        <Schedule>
            <Minute>15</Minute>
            <Hour>*</Hour>
            <DayOfMonth>*</DayOfMonth>
            <Month>*</Month>
            <DayOfWeek>*</DayOfWeek>
        </Schedule>
        <Task arguments="--some-argument">C:Program FilesSomeAppSomeExecutable.exe</Task>
    </CronJob>

    <!-- Run SomeBatchFile.bat every 5 minutes on Sunday -->
    <CronJob>
        <Schedule>
            <Minute>*/5</Minute>
            <Hour>*</Hour>
            <DayOfMonth>*</DayOfMonth>
            <Month>*</Month>
            <DayOfWeek>7</DayOfWeek>
        </Schedule>
        <Task arguments="">C:SomeBatchFile.bat</Task>
    </CronJob>
</CronTab>

I use LINQ to XML to parse this, and further string parsing for the schedule elements.  The first release will have some limitations which will be outlined when it is released, but should be sorted out before the second release.  Below is a screenshot of the class diagram for the Cron service.

width=500 height=313http://farm3.static.flickr.com/2354/2378370591_7f1591947e.jpg[/img]

The first beta of my Cron service should be available before the end of the week.  I am also going to be adding such functionality as recoverability and email notification in the release after the beta, after any bugs that have been found are fixed.  If you have any other sensible suggestions for features, please contact me.

Link to comment
Share on other sites

An alpha testing version is out:

http://tombell.org.uk/~tomb/binaries/cron/CronService.msi

Install this, it requires the .NET 3.5 Framework, and then download and copy this file:

http://tombell.org.uk/~tomb/binaries/cron/Cron.exe

Over the top of Program FilesTom BellCronCron.exe as it is an update and I haven't made the new installer.

The configuration file is CronTab.xml, and you can start the service like any other windows service.

Link to comment
Share on other sites

Unix Cron has email notification.  I was wonder which of these configuration people would prefer.

<CronTab>
    <!-- Ping 'google.com' every 5 minutes of every day -->
    <CronJob>
        <Schedule>
            <Minute>*/5</Minute>
            <Hour>*</Hour>
            <DayOfMonth>*</DayOfMonth>
            <Month>*</Month>
            <DayOfWeek>*</DayOfWeek>
        </Schedule>

        <Task arguments="google.com">ping</Task>

        <EmailSettings>
            <SmtpHostname>smtp.gmail.com</SmtpHostname>
            <SmtpPort>587</SmtpPort>
            <SmtpUsername>funkygmailaccount@gmail.com</SmtpUsername>
            <SmtpPassword>lamepassword</SmtpPassword>
            <UseSsl>true</UseSsl>
        </EmailSettings>
    </CronJob>
</CronTab>

One email settings per Cron job, or

<?xml version="1.0" encoding="UTF-8"?>

<CronConfig>
    <EmailSettings>
        <SmtpHostname>smtp.gmail.com</SmtpHostname>
        <SmtpPort>587</SmtpPort>
        <SmtpUsername>funkygmailaccount@gmail.com</SmtpUsername>
        <SmtpPassword>lamepassword</SmtpPassword>
        <UseSsl>true</UseSsl>
    </EmailSettings>
</CronConfig>

A separate single configuration.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...