コード例 #1
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
        /// <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);
        }
コード例 #2
0
        /// <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);
            });
        }
コード例 #3
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
        /// <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);
        }
コード例 #4
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
        /// <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);
        }
コード例 #5
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
        /// <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);
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
 private string Get(CronTimeSections time) => GetProperty(time).ToString();
コード例 #8
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
        /// <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);
        }
コード例 #9
0
ファイル: SectionValues.cs プロジェクト: cwinland/Cron.Core
 /// <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;
 }
コード例 #10
0
ファイル: DateSection.cs プロジェクト: cwinland/Cron.Core
 /// <inheritdoc />
 protected internal DateSection(CronTimeSections time) : base(time)
 {
     Every = false;
 }
コード例 #11
0
ファイル: DateSection.cs プロジェクト: cwinland/Cron.Core
 /// <inheritdoc />
 protected internal DateSection(CronTimeSections time, string expression) : base(time, expression)
 {
     Every = false;
 }
コード例 #12
0
ファイル: TimeSection.cs プロジェクト: cwinland/Cron.Core
 /// <inheritdoc />
 protected internal TimeSection(CronTimeSections time) : base(time)
 {
 }
コード例 #13
0
ファイル: TimeSection.cs プロジェクト: cwinland/Cron.Core
 /// <inheritdoc />
 protected internal TimeSection(CronTimeSections time, string expression) : base(time, expression)
 {
 }
コード例 #14
0
 /// <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;
 }
コード例 #15
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
 private PropertyInfo GetFieldInfo(CronTimeSections time) =>
 GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == time.ToString());
コード例 #16
0
ファイル: DateSection.cs プロジェクト: cwinland/Cron.Core
 /// <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;
 }
コード例 #17
0
ファイル: CronBuilder.cs プロジェクト: Magicianred/Cron.Core
 private ISection GetProperty(CronTimeSections time) => GetFieldInfo(time).GetValue(this) as ISection;
コード例 #18
0
ファイル: SectionValues.cs プロジェクト: cwinland/Cron.Core
 /// <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;
 }