internal static void ParseMonthly(string setting)
{
MonthlyEnabled = IsNever(setting);
if (!MonthlyEnabled)
return;
if (setting == null)
{
MonthlyEvery = true;
MonthlyLast = false;
MonthlyDay = 1;
MonthlyHour = 1;
MonthlyMinute = 0;
return;
}
var sa = setting.Split(' ');
if (sa.Length != 3)
throw ConfigurationExceptionHelper("Monthly", @"Invalid format. Expected: 'Number. Weekday Hour:Minute' (e.g. '1. Sunday 23:00'),
or 'Last Weekday Hour:Minute' (e.g. 'Last Sunday 23:00'), or 'Every Day. Hour:Minute' (e.g. 'Every 10. 23:10')");
var firstWord = sa[0].ToLower();
if (firstWord == "every")
{
// Every 10, 23:10
Configuration.MonthlyEvery = true;
Configuration.MonthlyLast = false;
if (sa[1][sa[1].Length - 1] != ',')
throw ConfigurationExceptionHelper("Monthly", @"Missing ',' after the day number. Valid format is: 'Every Day. Hour:Minute' (e.g. 'Every 10, 23:10')");
if (!Int32.TryParse(sa[1].TrimEnd(','), out _monthlyDay))
throw ConfigurationExceptionHelper("Monthly", @"Invalid day number. Expected: 'Every Day, Hour:Minute' (e.g. 'Every 10, 23:10')");
if (MonthlyDay < 1 || MonthlyDay > 31)
throw ConfigurationExceptionHelper("Monthly", "Day is out of range: 1-31.");
}
else if (firstWord == "last")
{
// Last Sunday 23:10
Configuration.MonthlyEvery = false;
Configuration.MonthlyLast = true;
ParseWeekday(sa[1], "Monthly", out _monthlyWeekDay);
}
else
{
// 3th Sunday 23:10
Configuration.MonthlyEvery = false;
Configuration.MonthlyLast = false;
//if (sa[0][sa[0].Length - 1] != '.')
// throw ConfigurationExceptionHelper("Monthly", @"Missing '.' after the week number. Valid format is: 'Number. Weekday Hour:Minute' (e.g. ' 3. Sunday 23:10')");
//if (!Int32.TryParse(sa[0].TrimEnd('.'), out _monthlyWeek))
// throw ConfigurationExceptionHelper("Monthly", @"Invalid week number. Valid format is: 'Number. Weekday Hour:Minute' (e.g. ' 3. Sunday 23:10')");
//if (MonthlyWeek < 1 || MonthlyWeek > 4)
// throw ConfigurationExceptionHelper("Monthly", "Week number is out of range: 1-4.");
switch (sa[0])
{
case "1st": _monthlyWeek = 1; break;
case "2nd": _monthlyWeek = 2; break;
case "3rd": _monthlyWeek = 3; break;
case "4th": _monthlyWeek = 4; break;
default: throw ConfigurationExceptionHelper("Monthly", "Week number is out of range. Available values: 1st, 2nd, 3rd, 4th");
}
ParseWeekday(sa[1], "Monthly", out _monthlyWeekDay);
}
ParseTime(sa[2], "Monthly", out _monthlyHour, out _monthlyMinute);
}
private static bool IsNever(string setting)