/// <summary> /// 생성자 /// </summary> /// <param name="min"></param> /// <param name="max"></param> /// <param name="type"></param> public Interval(T min, T max, IntervalKind type = IntervalKind.ClosedOpen) { if (min.CompareTo(max) < 0) { Min = min; Max = max; } else { Min = max; Max = min; } Kind = type; }
public int IntervalToSeconds(double interval, IntervalKind intervalKind) { if (interval <= 0) { if (!debug) { SysUtils.ReportErrorToEventLog($"Invalid interval of {interval} {intervalKind} used for background job. Using 10 Minute interval instead."); } return(600); } int seconds; switch (intervalKind) { case IntervalKind.Seconds: seconds = (int)TimeSpan.FromSeconds(interval).TotalSeconds; break; case IntervalKind.Minutes: seconds = (int)TimeSpan.FromMinutes(interval).TotalSeconds; break; case IntervalKind.Hours: seconds = (int)TimeSpan.FromHours(interval).TotalSeconds; break; case IntervalKind.Days: seconds = (int)TimeSpan.FromDays(interval).TotalSeconds; break; default: // Default to minutes seconds = (int)TimeSpan.FromMinutes(interval).TotalSeconds; break; } if (seconds < 30.0) { if (!debug) { SysUtils.ReportErrorToEventLog($"Too low interval seconds of {seconds} calculated from interval of {interval} {intervalKind} for background job. Using 10 Minute interval instead."); } return(600); } return(seconds); }
private static char GetRangeChar(IntervalKind type, bool min) { switch (type) { case IntervalKind.Open: return((min) ? OpenedChars[0] : OpenedChars[1]); case IntervalKind.Closed: return((min) ? ClosedChars[0] : ClosedChars[1]); case IntervalKind.ClosedOpen: return((min) ? ClosedChars[0] : OpenedChars[1]); case IntervalKind.OpenClosed: return((min) ? OpenedChars[0] : ClosedChars[1]); default: throw new ArgumentException("Unknown IntervalKind"); } }
public void AssertThat_RecurringAttribute_ValidInterval_ReturnsInterval(double interval, IntervalKind intervalKind, int expected) { var attr = new RecurringAttribute(1); attr.debug = true; var actual = attr.IntervalToSeconds(interval, intervalKind); Assert.AreEqual(expected, actual); }
/// <summary> /// <see cref="Interval{TOther}"/>를 생성합니다. /// </summary> /// <typeparam name="TOther"></typeparam> /// <param name="min"></param> /// <param name="max"></param> /// <param name="kind"></param> /// <returns></returns> public static Interval <TOther> Create <TOther>(TOther min, TOther max, IntervalKind kind = IntervalKind.ClosedOpen) where TOther : struct, IComparable <TOther> { return(new Interval <TOther>(min, max, kind)); }
/// <summary> /// Sets the interval of the background operation using the interval and interval kind. /// Setting it to 1.5 days for instance will set the interval to 129600 seconds (Equal to the seconds in 1.5 days) /// NOTE: There is a minimum interval currently set to 30 seconds. Any intervals below this will default to a 10 minute interval. /// </summary> /// <param name="interval">The interval number</param> /// <param name="intervalKind">The kind of interval (seconds, minutes, hours, days)</param> public RecurringAttribute(double interval, IntervalKind intervalKind) { IntervalInSeconds = IntervalToSeconds(interval, intervalKind); }