/// <summary> /// Constructor - validates that all mandatory schedule. /// </summary> /// <param name="unitValues">are the values for each minute, hour, day, month etc.</param> /// <param name="optionalTimeZone">The optional time zone.</param> /// <param name="optionalDayOfMonthOperator">The optional day of month operator.</param> /// <param name="optionalDayOfWeekOperator">The optional day of week operator.</param> /// <throws>ArgumentException - if validation of value set per unit fails</throws> public ScheduleSpec(IDictionary <ScheduleUnit, SortedSet <int> > unitValues, String optionalTimeZone, CronParameter optionalDayOfMonthOperator, CronParameter optionalDayOfWeekOperator) { Validate(unitValues); // Reduce to wildcards any unit's values set, if possible Compress(unitValues); _unitValues = unitValues; _optionalTimeZone = optionalTimeZone; _optionalDayOfMonthOperator = optionalDayOfMonthOperator; _optionalDayOfWeekOperator = optionalDayOfWeekOperator; }
/// <summary>Compute from parameters a crontab schedule. </summary> /// <param name="args">parameters</param> /// <returns>crontab schedule</returns> /// <throws>ScheduleParameterException if the parameters are invalid</throws> public static ScheduleSpec ComputeValues(Object[] args) { if (args.Length <= 4 || args.Length >= 8) { throw new ScheduleParameterException("Invalid number of crontab parameters, expecting between 5 and 7 parameters, received " + args.Length); } var unitMap = new Dictionary <ScheduleUnit, SortedSet <int> >(); var minutes = args[0]; var hours = args[1]; var daysOfMonth = args[2]; var months = args[3]; var daysOfWeek = args[4]; unitMap.Put(ScheduleUnit.MINUTES, ComputeValues(minutes, ScheduleUnit.MINUTES)); unitMap.Put(ScheduleUnit.HOURS, ComputeValues(hours, ScheduleUnit.HOURS)); var resultMonths = ComputeValues(months, ScheduleUnit.MONTHS); if (daysOfWeek is CronParameter && daysOfMonth is CronParameter) { throw new ScheduleParameterException("Invalid combination between days of week and days of month fields for timer:at"); } if (resultMonths != null && resultMonths.Count == 1 && (resultMonths.First().IsInt())) { // If other arguments are cronParameters, use it for later computations CronParameter parameter = null; if (daysOfMonth is CronParameter) { parameter = ((CronParameter)daysOfMonth); } else if (daysOfWeek is CronParameter) { parameter = ((CronParameter)daysOfWeek); } if (parameter != null) { parameter.Month = resultMonths.First(); } } var resultDaysOfWeek = ComputeValues(daysOfWeek, ScheduleUnit.DAYS_OF_WEEK); var resultDaysOfMonth = ComputeValues(daysOfMonth, ScheduleUnit.DAYS_OF_MONTH); if (resultDaysOfWeek != null && resultDaysOfWeek.Count == 1 && (resultDaysOfWeek.First().IsInt())) { // The result is in the form "last xx of the month // Days of week is replaced by a wildcard and days of month is updated with // the computation of "last xx day of month". // In this case "days of month" parameter has to be a wildcard. if (resultDaysOfWeek.First() > 6) { if (resultDaysOfMonth != null) { throw new ScheduleParameterException("Invalid combination between days of week and days of month fields for timer:at"); } resultDaysOfMonth = resultDaysOfWeek; resultDaysOfWeek = null; } } if (resultDaysOfMonth != null && resultDaysOfMonth.Count == 1 && (resultDaysOfMonth.First().IsInt())) { if (resultDaysOfWeek != null) { throw new ScheduleParameterException("Invalid combination between days of week and days of month fields for timer:at"); } } unitMap.Put(ScheduleUnit.DAYS_OF_WEEK, resultDaysOfWeek); unitMap.Put(ScheduleUnit.DAYS_OF_MONTH, resultDaysOfMonth); unitMap.Put(ScheduleUnit.MONTHS, resultMonths); if (args.Length > 5) { unitMap.Put(ScheduleUnit.SECONDS, ComputeValues(args[5], ScheduleUnit.SECONDS)); } String timezone = null; if (args.Length > 6) { if (!(args[6] is WildcardParameter)) { if (!(args[6] is String)) { throw new ScheduleParameterException("Invalid timezone parameter '" + args[6] + "' for timer:at, expected a string-type value"); } timezone = (String)args[6]; } } CronParameter optionalDayOfMonthOp = GetOptionalSpecialOp(daysOfMonth); CronParameter optionalDayOfWeekOp = GetOptionalSpecialOp(daysOfWeek); return(new ScheduleSpec(unitMap, timezone, optionalDayOfMonthOp, optionalDayOfWeekOp)); }