/// <summary> /// Remove <see cref="CronTimeSections" /> with a specified value. /// </summary> /// <param name="time">The type of time section such as seconds, minutes, etc. See <see cref="CronTimeSections" />.</param> /// <param name="minValue">Starting value for the specified time section.</param> /// <param name="maxValue">Ending value for the specified time section.</param> /// <returns>ICron.</returns> /// Remove Multiple value entry. /// <code> /// cron.Remove(CronTimeSections.Seconds, 5, 6); /// </code><inheritdoc cref="ICron" /> public ICron Remove(CronTimeSections time, int minValue, int maxValue) { GetProperty(time) .Remove(minValue, maxValue); return(this); }
/// <summary> /// Create an <see cref="ISection" /> based on the specified expression. /// </summary> /// <param name="time">Specific <see cref="CronTimeSections" />.</param> /// <param name="expression">Cron Expression</param> /// <remarks>Experimental.</remarks> protected Section(CronTimeSections time, string expression) : this(time) { Any = expression == ANY_CHAR; // Should only allow every on times Every = expression.Length > 1 && (expression.StartsWith("/") || expression.StartsWith("*")); expression = expression.StartsWith("*") ? expression.Substring(1) : expression; expression = expression.StartsWith("/") ? expression.Substring(1) : expression; if (expression.Length <= 0) { return; } Enabled = true; expression.Split(',') .ToList() .ForEach(x => { var vals = x.Split('-') .ToList(); var val1 = int.Parse(vals[0]); ISectionValues sectionValues = new SectionValues <T>(time, val1, vals.Count == 1 ? val1 : int.Parse(vals[1])); values.Add(sectionValues); }); }
/// <summary> /// Remove <see cref="CronTimeSections" /> with a specified value. /// </summary> /// <param name="time">The type of time section such as seconds, minutes, etc. See <see cref="CronTimeSections" />.</param> /// <param name="value">Value for the specified time section.</param> /// <returns>ICron.</returns> /// Remove single value entry. /// <code> /// cron.Remove(CronTimeSections.Seconds, 5); /// </code><inheritdoc cref="ICron" /> public ICron Remove(CronTimeSections time, int value) { GetProperty(time) .Remove(value); return(this); }
/// <summary> /// Add time value for the specified time section. /// </summary> /// <param name="time">The type of time section such as seconds, minutes, etc. See <see cref="CronTimeSections" />.</param> /// <param name="minValue">Starting value for the specified time section.</param> /// <param name="maxValue">Ending value for the specified time section.</param> /// <returns><see cref="ICron" /></returns> /// <example> /// Add Cron sections by section. /// <code> /// schedule.Add(CronTimeSections.Hours, 3, 5); /// schedule.Add(CronTimeSections.Years, 2020, 2022); /// </code></example> /// <inheritdoc cref="ICron" /> public ICron Add(CronTimeSections time, int minValue, int maxValue) { var prop = GetProperty(time) .Add(minValue, maxValue); prop.Every = false; return(this); }
/// <summary> /// Add time value for the specified time section. /// </summary> /// <param name="time">The type of time section such as seconds, minutes, etc. See <see cref="CronTimeSections" />.</param> /// <param name="value">Value for the specified time section.</param> /// <param name="repeatEvery">Indicates if the value is a repeating time or specific time.</param> /// <returns><see cref="ICron" /></returns> /// <exception cref="System.ArgumentOutOfRangeException">repeatEvery</exception> /// <exception cref="ArgumentOutOfRangeException">repeatEvery</exception> /// <example> /// Add Cron sections by section. /// <code> /// schedule.Add(time: CronTimeSections.Seconds, value: seconds, repeatEvery: true) /// schedule.Add(CronTimeSections.Minutes, 4) /// </code></example> /// <inheritdoc cref="ICron" /> public ICron Add(CronTimeSections time, int value, bool repeatEvery = false) { var section = GetProperty(time); if (repeatEvery && section.SectionType != CronSectionType.Time) { throw new ArgumentOutOfRangeException(nameof(repeatEvery)); } section.Add(value) .Every = repeatEvery && section.SectionType == CronSectionType.Time; return(this); }
/// <summary> /// Determines whether [is time cron section] [the specified time]. /// </summary> /// <param name="time">The time.</param> /// <returns><c>true</c> if [is time cron section] [the specified time]; otherwise, <c>false</c>.</returns> private static bool IsTimeCronSection(CronTimeSections time) { switch (time) { case CronTimeSections.Seconds: case CronTimeSections.Minutes: case CronTimeSections.Hours: return(true); case CronTimeSections.DayMonth: case CronTimeSections.Months: case CronTimeSections.DayWeek: return(false); default: return(false); } }
private string Get(CronTimeSections time) => GetProperty(time).ToString();
/// <summary> /// Clear the specific time element of the Cron object to defaults without any numerical cron representations. /// </summary> /// <param name="time">The type of time section such as seconds, minutes, etc. See <see cref="CronTimeSections" />.</param> /// <returns><see cref="ICron" /></returns> /// <inheritdoc cref="ICron" /> public ICron Reset(CronTimeSections time) { GetProperty(time).Clear(); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="SectionValues{T}" /> class. /// </summary> /// <param name="time">The time.</param> /// <param name="minVal">The minimum value.</param> /// <param name="maxVal">The maximum value.</param> internal SectionValues(CronTimeSections time, int minVal, int maxVal) : this(time, minVal) { maxValue = maxVal; }
/// <inheritdoc /> protected internal DateSection(CronTimeSections time) : base(time) { Every = false; }
/// <inheritdoc /> protected internal DateSection(CronTimeSections time, string expression) : base(time, expression) { Every = false; }
/// <inheritdoc /> protected internal TimeSection(CronTimeSections time) : base(time) { }
/// <inheritdoc /> protected internal TimeSection(CronTimeSections time, string expression) : base(time, expression) { }
/// <summary> /// Create <see cref="ISection" /> for a specific <see cref="CronTimeSections" />. /// </summary> /// <param name="time">The type of time section such as seconds, minutes, etc. See <see cref="CronTimeSections" />.</param> protected internal Section(CronTimeSections time) { Time = time; }
private PropertyInfo GetFieldInfo(CronTimeSections time) => GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == time.ToString());
/// <summary> /// Initializes a new instance of the <see cref="TimeSection" /> class. /// </summary> /// <param name="time">The time.</param> /// <param name="enabled">if set to <c>true</c> [enabled].</param> protected internal DateSection(CronTimeSections time, bool enabled) : this(time) { Enabled = enabled; }
private ISection GetProperty(CronTimeSections time) => GetFieldInfo(time).GetValue(this) as ISection;
/// <summary> /// Initializes a new instance of the <see cref="SectionValues{T}" /> class. /// </summary> /// <param name="time">The time.</param> /// <param name="val">The value.</param> internal SectionValues(CronTimeSections time, int val) { this.time = time; MinValue = val; }