Skip to content

A simple WPF control for editing crontab expressions

License

Notifications You must be signed in to change notification settings

tarockx/CrontabBuilder

Repository files navigation

CrontabBuilder

CrontabBuilder is a simple WPF control that allows users to visually edit a CRONTAB string in the Qaurtz format.

preview of the control

Changelog

v1.3.1

  • Fixed a bug in the regular expression that failed to recognize some "every X seconds" crontab strings

Older changes

See the full changelog

Installation

The package is available on NuGet:

https://www.nuget.org/packages/MasterT.WPF.CrontabBuilder

Usage

To use the control, first add the following namespace to your XAML:

xmlns:ctb="clr-namespace:MasterT.WPF.CrontabBuilder;assembly=MasterT.WPF.CrontabBuilder"

then, just add the control:

<Grid>
    <ctb:CrontabEditorControl></ctb:CrontabEditorControl>
</Grid>

The user will be able to select a schduling thanks to a series of dedicated visual controls.

Setting an initial Crontab string

If you want, you can assign a value to the CrontabString dependency property of CrontabEditorControl in code (or via XAML) to update the current scheduling configuration. The control will update accordingly. However, note that this will only work for strings in the formats supported by the CrontabEditorControl. Equivalent strings but with a different format will instead activate the "Custom Crontab string" mode.

Obtaining the current Crontab string

You have three ways to obtain the CRONTAB expression for the currently selected scheduling:

Option 1

Simply read the CrontabString property of CrontabEditorControl. This will always hold the updated CRONTAB string, or null if the user has selected some invalid settings

Option 2

You can also bind to the CrontabString property (it's a dependency property), so another option is to use data binding, like this:

<Grid>
    <ctb:CrontabEditorControl CrontabString="{Binding MyCrontabProperty}"></ctb:CrontabEditorControl>
</Grid>

Option 3:

Lastly, the CrontabEditorControl exposes a CrontabStringChanged event, so you can subscribe to it to receive an update every time the user changes the scheduling. Example:

crontabEditorControl.CrontabStringChanged += (s, crontabString) => {
    Console.WriteLine("New crontab string: " + crontabString);
};

Further configuration

The CrontabEditorControl exposes the following dependency properties that can be used for further customization:

  • ShowCurrentCrontab - shows or hides the bottom panel that shows the currently selected Crontab string
  • ShowCurrentCrontabDescription - shows or hides the bottom panel that shows a human-readable description the currently selected Crontab string
  • ShowInfoOutsideMainScroller - if set to true, this will move the description panels outside the main ScrollViewer that contains all the crontab editing controls. This means the description panel will always be visible even if the editing controls are partially hidden due to lack of vertical space.
  • ShowSecondsMode - shows or hides the "every X seconds" panel
  • ShowMinutesMode - shows or hides the "every X minutes" panel
  • ShowHoursMode - shows or hides the "every X hours" panel
  • ShowDayMode - shows or hides the "every day" panel
  • ShowWeekMode - shows or hides the "every week" panel
  • ShowNthDayOfWeekMode - shows or hides the "every nth week day" panel
  • ShowMonthMode - shows or hides the "every month" panel
  • ShowLastDayOfMonthMode - shows or hides the "last day of the month" panel
  • ShowCustomExpressionMode - shows or hides the "custom Cron expression" panel

Building

NuGet package can be built by using the dotnet command line:

dotnet pack MasterT.WPF.CrontabBuilder.csproj -c Release

Credits

This project uses Cron Expression Descriptor by Brady Holt

Thanks to Christoffer Pedersen for: localization support, danish translation
Thanks to joaquinsosamartin for: implementation of "every X seconds" mode

About

A simple WPF control for editing crontab expressions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages