public RecurringTimeFrequency(int interval, IntervalUnit unit, TimeSpan startTime, TimeSpan endTime) { this.Interval = interval; this.Unit = unit; this.StartTime = startTime; this.EndTime = endTime; }
/// <summary> /// Return the correct implementation of IRangeCalculationStrategy . /// </summary> /// <param name="unit">The interval unit.</param> /// <returns> /// A calculation stragtegy appropriate to the unit type. /// </returns> public IRangeCalculationStrategy GetRangeCalculationStrategy(IntervalUnit unit) { switch (unit) { case IntervalUnit.Day: return(DailyStrategy); case IntervalUnit.Week: return(WeeklyStrategy); case IntervalUnit.Month: return(MonthlyStrategy); case IntervalUnit.Year: return(YearlyStrategy); default: return(NullStrategy); } }
public static string ToTelnetString(this IntervalUnit unit) { switch (unit) { case IntervalUnit.Minutes: return("m"); case IntervalUnit.Hours: return("h"); case IntervalUnit.Days: return("d"); case IntervalUnit.Months: return("mo"); case IntervalUnit.Years: return("u"); default: throw new NotImplementedException(); } }
public static string GetScheduleDescription(int repeatInterval, IntervalUnit repeatIntervalUnit, int repeatCount = 0) { string result = "Repeat "; if (repeatCount > 0) { result += repeatCount + " times "; } result += "every "; string unitStr = repeatIntervalUnit.ToString().ToLower(); if (repeatInterval == 1) { result += unitStr; } else { result += repeatInterval + " " + unitStr + "s"; } return(result); }
/// <summary> /// Create a <see cref="ICalendarIntervalTrigger" /> that will occur at the given time, /// and repeat at the the given interval until the given end time. /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to fire.</param> /// <param name="endTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to quit repeat firing.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, DateTimeOffset startTimeUtc, DateTimeOffset? endTimeUtc, IntervalUnit intervalUnit, int repeatInterval) : this(name, null, startTimeUtc, endTimeUtc, intervalUnit, repeatInterval) { }
/// <summary> /// Returns the next time at which the <see cref="IDailyTimeIntervalTrigger" /> will /// fire, after the given time. If the trigger will not fire after the given /// time, <see langword="null" /> will be returned. /// </summary> /// <param name="afterTime"></param> /// <returns></returns> public override DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTime) { // Check if trigger has completed or not. if (complete) { return(null); } // Check repeatCount limit if (repeatCount != RepeatIndefinitely && timesTriggered > repeatCount) { return(null); } // a. Increment afterTime by a second, so that we are comparing against a time after it! if (afterTime == null) { afterTime = SystemTime.UtcNow().AddSeconds(1); } else { afterTime = afterTime.Value.AddSeconds(1); } // make sure afterTime is at least startTime if (afterTime < startTimeUtc) { afterTime = startTimeUtc; } // now change to local time zone afterTime = TimeZoneUtil.ConvertTime(afterTime.Value, TimeZone); // b.Check to see if afterTime is after endTimeOfDay or not. // If yes, then we need to advance to next day as well. bool afterTimePastEndTimeOfDay = false; if (endTimeOfDay != null) { afterTimePastEndTimeOfDay = afterTime.Value > endTimeOfDay.GetTimeOfDayForDate(afterTime).Value; } // c. now we need to move to the next valid day of week if either: // the given time is past the end time of day, or given time is not on a valid day of week DateTimeOffset?fireTime = AdvanceToNextDayOfWeekIfNecessary(afterTime.Value, afterTimePastEndTimeOfDay); if (fireTime == null) { return(null); } // apply timezone for this date & time fireTime = new DateTimeOffset(fireTime.Value.DateTime, TimeZoneUtil.GetUtcOffset(fireTime.Value, TimeZone)); // d. Calculate and save fireTimeEndDate variable for later use DateTimeOffset fireTimeEndDate; if (endTimeOfDay == null) { fireTimeEndDate = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTime).Value; } else { fireTimeEndDate = endTimeOfDay.GetTimeOfDayForDate(fireTime).Value; } // apply the proper offset for the end date fireTimeEndDate = new DateTimeOffset(fireTimeEndDate.DateTime, TimeZone.GetUtcOffset(fireTimeEndDate.DateTime)); // e. Check fireTime against startTime or startTimeOfDay to see which go first. DateTimeOffset fireTimeStartDate = startTimeOfDay.GetTimeOfDayForDate(fireTime).Value; // apply the proper offset for the start date fireTimeStartDate = new DateTimeOffset(fireTimeStartDate.DateTime, TimeZone.GetUtcOffset(fireTimeStartDate.DateTime)); if (fireTime < fireTimeStartDate) { return(fireTimeStartDate.ToUniversalTime()); } // f. Continue to calculate the fireTime by incremental unit of intervals. // recall that if fireTime was less that fireTimeStartDate, we didn't get this far startTimeUtc = TimeZoneUtil.ConvertTime(fireTimeStartDate, TimeZone); long secondsAfterStart = (long)(fireTime.Value - startTimeUtc).TotalSeconds; long repeatLong = RepeatInterval; DateTimeOffset sTime = fireTimeStartDate; IntervalUnit repeatUnit = RepeatIntervalUnit; if (repeatUnit == IntervalUnit.Second) { long jumpCount = secondsAfterStart / repeatLong; if (secondsAfterStart % repeatLong != 0) { jumpCount++; } sTime = sTime.AddSeconds(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Minute) { long jumpCount = secondsAfterStart / (repeatLong * 60L); if (secondsAfterStart % (repeatLong * 60L) != 0) { jumpCount++; } sTime = sTime.AddMinutes(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Hour) { long jumpCount = secondsAfterStart / (repeatLong * 60L * 60L); if (secondsAfterStart % (repeatLong * 60L * 60L) != 0) { jumpCount++; } sTime = sTime.AddHours(RepeatInterval * (int)jumpCount); fireTime = sTime; } // g. Ensure this new fireTime is within the day, or else we need to advance to next day. if (fireTime > fireTimeEndDate) { fireTime = AdvanceToNextDayOfWeekIfNecessary(fireTime.Value, IsSameDay(fireTime.Value, fireTimeEndDate)); // make sure we hit the startTimeOfDay on the new day fireTime = startTimeOfDay.GetTimeOfDayForDate(fireTime); } // i. Return calculated fireTime. if (fireTime == null) { return(null); } // apply proper offset var d = fireTime.Value; d = new DateTimeOffset(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, TimeZone.GetUtcOffset(d.DateTime)); return(d.ToUniversalTime()); }
/// <summary> /// Create a <see cref="IDailyTimeIntervalTrigger" /> that will occur immediately, and /// repeat at the given interval. /// </summary> /// <param name="name"></param> /// <param name="group"></param> /// <param name="startTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should begin occurring.</param> /// <param name="endTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should stop occurring.</param> /// <param name="intervalUnit">The repeat interval unit. The only intervals that are valid for this type of trigger are /// <see cref="IntervalUnit.Second"/>, <see cref="IntervalUnit.Minute"/>, and <see cref="IntervalUnit.Hour"/>.</param> /// <param name="repeatInterval"></param> public DailyTimeIntervalTriggerImpl(string name, string group, TimeOfDay startTimeOfDayUtc, TimeOfDay endTimeOfDayUtc, IntervalUnit intervalUnit, int repeatInterval) : this(name, group, SystemTime.UtcNow(), null, startTimeOfDayUtc, endTimeOfDayUtc, intervalUnit, repeatInterval) { }
public void GetRangeCalculationStrategy_ForUnit_ReturnCorrectStrategy(IntervalUnit unit, Type strategyType) { Assert.IsAssignableFrom(strategyType, new RangeCalculationStrategyFactory().GetRangeCalculationStrategy(unit)); }
/// <summary> /// Constructs a interval given an value in milliseconds /// </summary> public Interval(int value) { _value = value; _mode = IntervalUnit.Millisecond; AsTimeSpan = TimeSpan.FromMilliseconds(value); }
public static DateTimeOffset FutureDate(int interval, IntervalUnit unit) { return(TranslatedAdd(SystemTime.UtcNow(), unit, interval)); }
public Job Milliseconds() { _intervalUnit = IntervalUnit.Millisecond; return(this); }
public static void AddUnit(FlatBufferBuilder builder, IntervalUnit unit) { builder.AddShort(0, (short)unit, 0); }
public IList <TableEntry> GetEntires(BodyId bodyId, double longitude, double latitude, double altitude, DateTime startTime, DateTime endTime, int intervalSize, IntervalUnit intervalUnit) { using (var client = new TcpClient("horizons.jpl.nasa.gov", 6775)) { var stream = client.GetStream(); var inputStream = new StreamReader(stream); var outputStream = new StreamWriter(stream); inputStream.ReadStartText(); outputStream.SelectBody(inputStream, bodyId); outputStream.SelectEphemeris(inputStream); outputStream.SelectObserver(inputStream); outputStream.SelectCoordinateCenter(inputStream); outputStream.SelectGeodeticCoordinateSystem(inputStream); outputStream.SelectGeodeticPosition(inputStream, longitude, latitude, altitude); outputStream.SelectStartTime(inputStream, startTime); outputStream.SelectEndTime(inputStream, endTime); outputStream.SelectInterval(inputStream, intervalSize, intervalUnit); outputStream.SelectDefault(inputStream); var result = outputStream.SelectObserverTable(inputStream, TableQuantities.LocalApparentSiderealTime, TableQuantities.ObserverEclipticLongitudeLatitude); return(TableResultParser.Parse(result)); } }
public static DateTimeOffset DateAdd(DateTimeOffset timestamp, int interval, IntervalUnit intervalUnit) { throw Invalid(); }
public IProduct CreateProduct(int ProductFamilyID, string Name, string Handle, int PriceInCents, int Interval, IntervalUnit IntervalUnit, string AccountingCode, string Description) { throw new NotImplementedException(); }
/// <summary> /// 添加计划 /// </summary> /// <param name="scheduleName"></param> /// <param name="intervalValue"></param> /// <param name="intervalUnit"></param> /// <param name="action"></param> public void AddSchedule(string scheduleName, int intervalValue, IntervalUnit intervalUnit, Action action) { if (intervalValue < 1) { intervalValue = 1; } if (!GlobalConfig.RUNNIGN_SCHEDULE_GROUP_LIST.Contains(scheduleName)) { ScheduleAdding(Level.Warning, string.Format("任务[{0}]已被暂停", scheduleName)); return; } RemoveSchedule(scheduleName); try { JobManager.AddJob(() => { try { action(); } catch (Exception ex) { var message = string.Format("执行任务[{0}]时出错,原因:{1}", scheduleName, ex); AddingScheduleError(message); new DbLogger().Write(message); } }, t => { var schedule = t.WithName(scheduleName).NonReentrant().ToRunNow(); switch (intervalUnit) { case IntervalUnit.Second: schedule.AndEvery(intervalValue).Seconds(); break; case IntervalUnit.Minute: schedule.AndEvery(intervalValue).Minutes(); break; case IntervalUnit.Hour: schedule.AndEvery(intervalValue).Hours(); break; case IntervalUnit.Day: schedule.AndEvery(intervalValue).Days(); break; case IntervalUnit.Month: schedule.AndEvery(intervalValue).Months(); break; case IntervalUnit.Year: schedule.AndEvery(intervalValue).Years(); break; default: throw new ArgumentOutOfRangeException("IntervalUnit", "该任务没有匹配的任务执行周期单位"); } }); ScheduleAddedCompleted(new JobberEvent { ScheduleCount = GetAllScheduleCount }); } catch (Exception ex) { AddingScheduleError(string.Format("添加任务[{0}]时失败,原因:{1}", scheduleName, ex)); } }
public Interval(long factor, IntervalUnit unit) { this.Factor = factor; this.Unit = unit; SetSeconds(this.Factor, unit); }
/// <summary> /// Create a <see cref="CalendarIntervalTriggerImpl" /> that will occur immediately, and /// repeat at the the given interval. /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, IntervalUnit intervalUnit, int repeatInterval) : this(name, null, intervalUnit, repeatInterval) { }
/// <summary> /// Create a <see cref="ICalendarIntervalTrigger" /> that will occur at the given time, /// and repeat at the given interval until the given end time. /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to fire.</param> /// <param name="endTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to quit repeat firing.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, DateTimeOffset startTimeUtc, DateTimeOffset?endTimeUtc, IntervalUnit intervalUnit, int repeatInterval) : this(name, null, startTimeUtc, endTimeUtc, intervalUnit, repeatInterval) { }
public static void SelectInterval(this StreamWriter streamWriter, StreamReader streamReader, int size, IntervalUnit unit) { streamWriter.WriteWithNewLine($"{size} {unit.ToTelnetString()}"); streamReader.TerminatedRead(TelnetConstants.SelectionTerminationString); }
public static string ConvertDateToStringByUnit(IntervalUnit unit, DateTime dateTime) { return(dateTime.ToString(GetDateFormat(unit))); }
public static DateTimeOffset FutureDate(int interval, IntervalUnit unit) { return TranslatedAdd(SystemTime.Now(), unit, interval); }
public IntervalType(IntervalUnit unit = IntervalUnit.YearMonth) { Unit = unit; }
protected override TriggerPropertyBundle GetTriggerPropertyBundle(SimplePropertiesTriggerProperties props) { int repeatCount = (int)props.Long1; int interval = props.Int1; string intervalUnitStr = props.String1; string daysOfWeekStr = props.String2; string timeOfDayStr = props.String3; IntervalUnit intervalUnit = (IntervalUnit)Enum.Parse(typeof(IntervalUnit), intervalUnitStr, true); DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder.Create() .WithInterval(interval, intervalUnit) .WithRepeatCount(repeatCount); if (daysOfWeekStr != null) { ISet <DayOfWeek> daysOfWeek = new HashSet <DayOfWeek>(); string[] nums = daysOfWeekStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (nums.Length > 0) { foreach (String num in nums) { daysOfWeek.Add((DayOfWeek)Int32.Parse(num)); } scheduleBuilder.OnDaysOfTheWeek(daysOfWeek); } } else { scheduleBuilder.OnDaysOfTheWeek(DailyTimeIntervalScheduleBuilder.AllDaysOfTheWeek); } if (timeOfDayStr != null) { string[] nums = timeOfDayStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); TimeOfDay startTimeOfDay; if (nums.Length >= 3) { int hour = Int32.Parse(nums[0]); int min = Int32.Parse(nums[1]); int sec = Int32.Parse(nums[2]); startTimeOfDay = new TimeOfDay(hour, min, sec); } else { startTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0); } scheduleBuilder.StartingDailyAt(startTimeOfDay); TimeOfDay endTimeOfDay; if (nums.Length >= 6) { int hour = Int32.Parse(nums[3]); int min = Int32.Parse(nums[4]); int sec = Int32.Parse(nums[5]); endTimeOfDay = new TimeOfDay(hour, min, sec); } else { endTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59); } scheduleBuilder.EndingDailyAt(endTimeOfDay); } else { scheduleBuilder.StartingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0)); scheduleBuilder.EndingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59)); } int timesTriggered = props.Int2; string[] statePropertyNames = { "timesTriggered" }; object[] statePropertyValues = { timesTriggered }; return(new TriggerPropertyBundle(scheduleBuilder, statePropertyNames, statePropertyValues)); }
/// <summary> /// Constructs a interval given an amount in milliseconds /// </summary> public Interval(int amount) { _amount = amount; _mode = IntervalUnit.Millisecond; AsTimeSpan = TimeSpan.FromMilliseconds(amount); }
private static DateTimeOffset TranslatedAdd(DateTimeOffset date, IntervalUnit unit, int amountToAdd) { switch (unit) { case IntervalUnit.Day: return date.AddDays(amountToAdd); case IntervalUnit.Hour: return date.AddHours(amountToAdd); case IntervalUnit.Minute: return date.AddMinutes(amountToAdd); case IntervalUnit.Month: return date.AddMonths(amountToAdd); case IntervalUnit.Second: return date.AddSeconds(amountToAdd); case IntervalUnit.Millisecond: return date.AddMilliseconds(amountToAdd); case IntervalUnit.Week: return date.AddDays(amountToAdd*7); case IntervalUnit.Year: return date.AddYears(amountToAdd); default: throw new ArgumentException("Unknown IntervalUnit"); } }
/// <summary> /// Crea la expresión (quantity * interval '1 [unit]') /// </summary> public static TimeSpan Interval <T>(T quantity, IntervalUnit unit) => throw new SqlFunctionException();
/// <summary> /// Initializes a new instance of the <see cref="Interval" /> class. /// </summary> /// <param name="value">value (required).</param> /// <param name="unit">unit (required).</param> public Interval(Operand value = default(Operand), IntervalUnit unit = default(IntervalUnit)) { // to ensure "value" is required (not null) this.Value = value ?? throw new ArgumentNullException("value is a required property for Interval and cannot be null"); this.Unit = unit; }
/// <summary> /// Returns the next time at which the <see cref="IDailyTimeIntervalTrigger" /> will /// fire, after the given time. If the trigger will not fire after the given /// time, <see langword="null" /> will be returned. /// </summary> /// <param name="afterTime"></param> /// <returns></returns> public override DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTime) { // Check if trigger has completed or not. if (complete) { return(null); } // Check repeatCount limit if (repeatCount != RepeatIndefinitely && timesTriggered > repeatCount) { return(null); } // a. Increment afterTime by a second, so that we are comparing against a time after it! if (afterTime == null) { afterTime = SystemTime.UtcNow().AddSeconds(1); } else { afterTime = afterTime.Value.AddSeconds(1); } // if afterTime is before startTime, then return startTime directly. if (afterTime <= startTimeUtc) { return(startTimeUtc); } // now change to local time zone afterTime = TimeZoneUtil.ConvertTime(afterTime.Value, TimeZone); // b.Check to see if afterTime is after endTimeOfDay or not. // If yes, then we need to advance to next day as well. bool afterTimePassEndTimeOfDay = false; if (endTimeOfDay != null) { afterTimePassEndTimeOfDay = afterTime.Value > endTimeOfDay.GetTimeOfDayForDate(afterTime).Value; } DateTimeOffset?fireTime = AdvanceToNextDayOfWeek(afterTime.Value, afterTimePassEndTimeOfDay); if (fireTime == null) { return(null); } // apply timezone for this date & time fireTime = new DateTimeOffset(fireTime.Value.DateTime, TimeZone.GetUtcOffset(fireTime.Value)); // c. Calculate and save fireTimeEndDate variable for later use DateTimeOffset fireTimeEndDate; if (endTimeOfDay == null) { fireTimeEndDate = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTime).Value; } else { fireTimeEndDate = endTimeOfDay.GetTimeOfDayForDate(fireTime).Value; } // apply the proper offset for the end date fireTimeEndDate = new DateTimeOffset(fireTimeEndDate.DateTime, this.TimeZone.GetUtcOffset(fireTimeEndDate.DateTime)); // e. Check fireTime against startTime or startTimeOfDay to see which go first. DateTimeOffset fireTimeStartDate = startTimeOfDay.GetTimeOfDayForDate(fireTime).Value; // apply the proper offset for the start date fireTimeStartDate = new DateTimeOffset(fireTimeStartDate.DateTime, this.TimeZone.GetUtcOffset(fireTimeStartDate.DateTime)); if (fireTime < startTimeUtc && startTimeUtc < fireTimeStartDate) { return(fireTimeStartDate); } if (fireTime < startTimeUtc && startTimeUtc > fireTimeStartDate) { return(startTimeUtc); } if (fireTime > startTimeUtc && fireTime < fireTimeStartDate) { return(fireTimeStartDate); } // Always adjust the startTime to be startTimeOfDay startTimeUtc = fireTimeStartDate.ToUniversalTime(); // f. Continue to calculate the fireTime by incremental unit of intervals. startTimeUtc = TimeZoneUtil.ConvertTime(startTimeUtc, TimeZone); long secondsAfterStart = (long)(fireTime.Value - startTimeUtc).TotalSeconds; long repeatLong = RepeatInterval; DateTimeOffset sTime = startTimeUtc; IntervalUnit repeatUnit = RepeatIntervalUnit; if (repeatUnit == IntervalUnit.Second) { long jumpCount = secondsAfterStart / repeatLong; if (secondsAfterStart % repeatLong != 0) { jumpCount++; } sTime = sTime.AddSeconds(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Minute) { long jumpCount = secondsAfterStart / (repeatLong * 60L); if (secondsAfterStart % (repeatLong * 60L) != 0) { jumpCount++; } sTime = sTime.AddMinutes(RepeatInterval * (int)jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Hour) { long jumpCount = secondsAfterStart / (repeatLong * 60L * 60L); if (secondsAfterStart % (repeatLong * 60L * 60L) != 0) { jumpCount++; } sTime = sTime.AddHours(RepeatInterval * (int)jumpCount); fireTime = sTime; } // g. Ensure this new fireTime is within one day, or else we need to advance to next day. if (fireTime > fireTimeEndDate) { // Check to see if fireTime has pass fireTime's end of day. If not, we need to advance by one day. DateTimeOffset fireTimeEndOfDay = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTimeEndDate).Value; if (fireTime > fireTimeEndOfDay) { fireTime = AdvanceToNextDayOfWeek(fireTime.Value, false); } else { fireTime = AdvanceToNextDayOfWeek(fireTime.Value, true); } if (fireTime == null) { return(null); } // Check to see if next day fireTime is before startTimeOfDay, if not, we need to set to startTimeOfDay. DateTimeOffset nextDayfireTimeStartDate = StartTimeOfDay.GetTimeOfDayForDate(fireTime).Value; if (fireTime < nextDayfireTimeStartDate) { fireTime = nextDayfireTimeStartDate; } } // i. Return calculated fireTime. return(fireTime.Value.ToUniversalTime()); }
protected virtual void ProcessInternal(string xml) { PrepForProcessing(); ValidateXml(xml); MaybeThrowValidationException(); // deserialize as object model XmlSerializer xs = new XmlSerializer(typeof(QuartzXmlConfiguration20)); QuartzXmlConfiguration20 data = (QuartzXmlConfiguration20)xs.Deserialize(new StringReader(xml)); if (data == null) { throw new SchedulerConfigException("Job definition data from XML was null after deserialization"); } // // Extract pre-processing commands // if (data.preprocessingcommands != null) { foreach (preprocessingcommandsType command in data.preprocessingcommands) { if (command.deletejobsingroup != null) { foreach (string s in command.deletejobsingroup) { string deleteJobGroup = s.NullSafeTrim(); if (!String.IsNullOrEmpty(deleteJobGroup)) { jobGroupsToDelete.Add(deleteJobGroup); } } } if (command.deletetriggersingroup != null) { foreach (string s in command.deletetriggersingroup) { string deleteTriggerGroup = s.NullSafeTrim(); if (!String.IsNullOrEmpty(deleteTriggerGroup)) { triggerGroupsToDelete.Add(deleteTriggerGroup); } } } if (command.deletejob != null) { foreach (preprocessingcommandsTypeDeletejob s in command.deletejob) { string name = s.name.TrimEmptyToNull(); string group = s.group.TrimEmptyToNull(); if (name == null) { throw new SchedulerConfigException("Encountered a 'delete-job' command without a name specified."); } jobsToDelete.Add(new JobKey(name, group)); } } if (command.deletetrigger != null) { foreach (preprocessingcommandsTypeDeletetrigger s in command.deletetrigger) { string name = s.name.TrimEmptyToNull(); string group = s.group.TrimEmptyToNull(); if (name == null) { throw new SchedulerConfigException("Encountered a 'delete-trigger' command without a name specified."); } triggersToDelete.Add(new TriggerKey(name, group)); } } } } if (log.IsDebugEnabled) { log.Debug("Found " + jobGroupsToDelete.Count + " delete job group commands."); log.Debug("Found " + triggerGroupsToDelete.Count + " delete trigger group commands."); log.Debug("Found " + jobsToDelete.Count + " delete job commands."); log.Debug("Found " + triggersToDelete.Count + " delete trigger commands."); } // // Extract directives // if (data.processingdirectives != null && data.processingdirectives.Length > 0) { bool overWrite = data.processingdirectives[0].overwriteexistingdata; log.Debug("Directive 'overwrite-existing-data' specified as: " + overWrite); OverWriteExistingData = overWrite; } else { log.Debug("Directive 'overwrite-existing-data' not specified, defaulting to " + OverWriteExistingData); } if (data.processingdirectives != null && data.processingdirectives.Length > 0) { bool ignoreduplicates = data.processingdirectives[0].ignoreduplicates; log.Debug("Directive 'ignore-duplicates' specified as: " + ignoreduplicates); IgnoreDuplicates = ignoreduplicates; } else { log.Debug("Directive 'ignore-duplicates' not specified, defaulting to " + IgnoreDuplicates); } if (data.processingdirectives != null && data.processingdirectives.Length > 0) { bool scheduleRelative = data.processingdirectives[0].scheduletriggerrelativetoreplacedtrigger; log.Debug("Directive 'schedule-trigger-relative-to-replaced-trigger' specified as: " + scheduleRelative); ScheduleTriggerRelativeToReplacedTrigger = scheduleRelative; } else { log.Debug("Directive 'schedule-trigger-relative-to-replaced-trigger' not specified, defaulting to " + ScheduleTriggerRelativeToReplacedTrigger); } // // Extract Job definitions... // List <jobdetailType> jobNodes = new List <jobdetailType>(); if (data.schedule != null) { foreach (var schedule in data.schedule) { if (schedule != null) { if (schedule.job != null) { jobNodes.AddRange(schedule.job); } } } } log.Debug("Found " + jobNodes.Count + " job definitions."); foreach (jobdetailType jobDetailType in jobNodes) { string jobName = jobDetailType.name.TrimEmptyToNull(); string jobGroup = jobDetailType.group.TrimEmptyToNull(); string jobDescription = jobDetailType.description.TrimEmptyToNull(); string jobTypeName = jobDetailType.jobtype.TrimEmptyToNull(); bool jobDurability = jobDetailType.durable; bool jobRecoveryRequested = jobDetailType.recover; Type jobType = typeLoadHelper.LoadType(jobTypeName); IJobDetail jobDetail = JobBuilder.Create(jobType) .WithIdentity(jobName, jobGroup) .WithDescription(jobDescription) .StoreDurably(jobDurability) .RequestRecovery(jobRecoveryRequested) .Build(); if (jobDetailType.jobdatamap != null && jobDetailType.jobdatamap.entry != null) { foreach (entryType entry in jobDetailType.jobdatamap.entry) { string key = entry.key.TrimEmptyToNull(); string value = entry.value.TrimEmptyToNull(); jobDetail.JobDataMap.Add(key, value); } } if (log.IsDebugEnabled) { log.Debug("Parsed job definition: " + jobDetail); } AddJobToSchedule(jobDetail); } // // Extract Trigger definitions... // List <triggerType> triggerEntries = new List <triggerType>(); if (data.schedule != null) { foreach (var schedule in data.schedule) { if (schedule != null && schedule.trigger != null) { triggerEntries.AddRange(schedule.trigger); } } } log.Debug("Found " + triggerEntries.Count + " trigger definitions."); foreach (triggerType triggerNode in triggerEntries) { string triggerName = triggerNode.Item.name.TrimEmptyToNull(); string triggerGroup = triggerNode.Item.group.TrimEmptyToNull(); string triggerDescription = triggerNode.Item.description.TrimEmptyToNull(); string triggerCalendarRef = triggerNode.Item.calendarname.TrimEmptyToNull(); string triggerJobName = triggerNode.Item.jobname.TrimEmptyToNull(); string triggerJobGroup = triggerNode.Item.jobgroup.TrimEmptyToNull(); int triggerPriority = TriggerConstants.DefaultPriority; if (!triggerNode.Item.priority.IsNullOrWhiteSpace()) { triggerPriority = Convert.ToInt32(triggerNode.Item.priority); } DateTimeOffset triggerStartTime = SystemTime.UtcNow(); if (triggerNode.Item.Item != null) { if (triggerNode.Item.Item is DateTime) { triggerStartTime = new DateTimeOffset((DateTime)triggerNode.Item.Item); } else { triggerStartTime = triggerStartTime.AddSeconds(Convert.ToInt32(triggerNode.Item.Item)); } } DateTime?triggerEndTime = triggerNode.Item.endtimeSpecified ? triggerNode.Item.endtime : (DateTime?)null; IScheduleBuilder sched; if (triggerNode.Item is simpleTriggerType) { simpleTriggerType simpleTrigger = (simpleTriggerType)triggerNode.Item; string repeatCountString = simpleTrigger.repeatcount.TrimEmptyToNull(); string repeatIntervalString = simpleTrigger.repeatinterval.TrimEmptyToNull(); int repeatCount = ParseSimpleTriggerRepeatCount(repeatCountString); TimeSpan repeatInterval = repeatIntervalString == null ? TimeSpan.Zero : TimeSpan.FromMilliseconds(Convert.ToInt64(repeatIntervalString)); sched = SimpleScheduleBuilder.Create() .WithInterval(repeatInterval) .WithRepeatCount(repeatCount); if (!simpleTrigger.misfireinstruction.IsNullOrWhiteSpace()) { ((SimpleScheduleBuilder)sched).WithMisfireHandlingInstruction(ReadMisfireInstructionFromString(simpleTrigger.misfireinstruction)); } } else if (triggerNode.Item is cronTriggerType) { cronTriggerType cronTrigger = (cronTriggerType)triggerNode.Item; string cronExpression = cronTrigger.cronexpression.TrimEmptyToNull(); string timezoneString = cronTrigger.timezone.TrimEmptyToNull(); TimeZoneInfo tz = timezoneString != null?TimeZoneInfo.FindSystemTimeZoneById(timezoneString) : null; sched = CronScheduleBuilder.CronSchedule(cronExpression) .InTimeZone(tz); if (!cronTrigger.misfireinstruction.IsNullOrWhiteSpace()) { ((CronScheduleBuilder)sched).WithMisfireHandlingInstruction(ReadMisfireInstructionFromString(cronTrigger.misfireinstruction)); } } else if (triggerNode.Item is calendarIntervalTriggerType) { calendarIntervalTriggerType calendarIntervalTrigger = (calendarIntervalTriggerType)triggerNode.Item; string repeatIntervalString = calendarIntervalTrigger.repeatinterval.TrimEmptyToNull(); IntervalUnit intervalUnit = ParseDateIntervalTriggerIntervalUnit(calendarIntervalTrigger.repeatintervalunit.TrimEmptyToNull()); int repeatInterval = repeatIntervalString == null ? 0 : Convert.ToInt32(repeatIntervalString); sched = CalendarIntervalScheduleBuilder.Create() .WithInterval(repeatInterval, intervalUnit); if (!calendarIntervalTrigger.misfireinstruction.IsNullOrWhiteSpace()) { ((CalendarIntervalScheduleBuilder)sched).WithMisfireHandlingInstruction(ReadMisfireInstructionFromString(calendarIntervalTrigger.misfireinstruction)); } } else { throw new SchedulerConfigException("Unknown trigger type in XML configuration"); } IMutableTrigger trigger = (IMutableTrigger)TriggerBuilder.Create() .WithIdentity(triggerName, triggerGroup) .WithDescription(triggerDescription) .ForJob(triggerJobName, triggerJobGroup) .StartAt(triggerStartTime) .EndAt(triggerEndTime) .WithPriority(triggerPriority) .ModifiedByCalendar(triggerCalendarRef) .WithSchedule(sched) .Build(); if (triggerNode.Item.jobdatamap != null && triggerNode.Item.jobdatamap.entry != null) { foreach (entryType entry in triggerNode.Item.jobdatamap.entry) { string key = entry.key.TrimEmptyToNull(); string value = entry.value.TrimEmptyToNull(); trigger.JobDataMap.Add(key, value); } } if (log.IsDebugEnabled) { log.Debug("Parsed trigger definition: " + trigger); } AddTriggerToSchedule(trigger); } }
private IntervalSchedule(DateTime startDate, DateTime?endDate, IntervalUnit intervalUnit, double interval) { this.startDate = startDate; this.endDate = endDate; double increment; switch (intervalUnit) { case IntervalUnit.Seconds: increment = interval; advanceRunDate = d => d.AddSeconds(increment); break; case IntervalUnit.Minutes: increment = interval; advanceRunDate = d => d.AddMinutes(increment); break; case IntervalUnit.Hours: increment = interval; advanceRunDate = d => d.AddHours(increment); break; case IntervalUnit.Days: increment = interval; advanceRunDate = d => d.AddDays(increment); break; case IntervalUnit.Weeks: increment = 7.0 * interval; advanceRunDate = d => d.AddDays(increment); break; case IntervalUnit.Months: if (interval % 1 > 0) { throw new Exceptions.ConfigurationFileException($"Cannot schedule Operation for {interval} Months later"); } else { increment = interval; advanceRunDate = d => d.AddMonths((int)increment); } break; case IntervalUnit.Quarters: if (interval % 1 > 0) { throw new Exceptions.ConfigurationFileException($"Cannot schedule Operation for {interval} Quarters later"); } else { increment = interval * 3; advanceRunDate = d => d.AddMonths((int)increment); } break; case IntervalUnit.Years: if (interval % 1 > 0) { throw new Exceptions.ConfigurationFileException($"Cannot schedule Operation for {interval} Years later"); } else { increment = interval; advanceRunDate = d => d.AddYears((int)increment); } break; } }
/// <summary> /// Create a <see cref="IDailyTimeIntervalTrigger" /> that will occur at the given time, /// and repeat at the given interval until the given end time. /// </summary> /// <param name="name"></param> /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" />to fire.</param> /// <param name="endTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" />to quit repeat firing.</param> /// <param name="startTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should begin occurring.</param> /// <param name="endTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should stop occurring.</param> /// <param name="intervalUnit">The repeat interval unit. The only intervals that are valid for this type of trigger are /// <see cref="IntervalUnit.Second"/>, <see cref="IntervalUnit.Minute"/>, and <see cref="IntervalUnit.Hour"/>.</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public DailyTimeIntervalTriggerImpl(string name, DateTimeOffset startTimeUtc, DateTimeOffset?endTimeUtc, TimeOfDay startTimeOfDayUtc, TimeOfDay endTimeOfDayUtc, IntervalUnit intervalUnit, int repeatInterval) : this(name, null, startTimeUtc, endTimeUtc, startTimeOfDayUtc, endTimeOfDayUtc, intervalUnit, repeatInterval) { }
/// <summary> /// Create a <see cref="ICalendarIntervalTrigger" /> that will occur immediately, and /// repeat at the the given interval /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="group">Group for the trigger instance.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, string group, IntervalUnit intervalUnit, int repeatInterval) : this(name, group, SystemTime.UtcNow(), null, intervalUnit, repeatInterval) { }
/// <summary> /// Create a <see cref="IDailyTimeIntervalTrigger" /> that will occur at the given time, /// and repeat at the given interval until the given end time. /// </summary> /// <param name="name"></param> /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" />to fire.</param> /// <param name="endTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" />to quit repeat firing.</param> /// <param name="startTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should begin occurring.</param> /// <param name="endTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should stop occurring.</param> /// <param name="intervalUnit">The repeat interval unit. The only intervals that are valid for this type of trigger are /// <see cref="IntervalUnit.Second"/>, <see cref="IntervalUnit.Minute"/>, and <see cref="IntervalUnit.Hour"/>.</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public DailyTimeIntervalTriggerImpl(string name, DateTimeOffset startTimeUtc, DateTimeOffset? endTimeUtc, TimeOfDay startTimeOfDayUtc, TimeOfDay endTimeOfDayUtc, IntervalUnit intervalUnit, int repeatInterval) : this(name, null, startTimeUtc, endTimeUtc, startTimeOfDayUtc, endTimeOfDayUtc, intervalUnit, repeatInterval) { }
/// <summary> /// Create a <see cref="ICalendarIntervalTrigger" /> that will occur at the given time, /// and repeat at the the given interval until the given end time. /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="group">Group for the trigger instance.</param> /// <param name="jobName">Name of the associated job.</param> /// <param name="jobGroup">Group of the associated job.</param> /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to fire.</param> /// <param name="endTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to quit repeat firing.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, string group, string jobName, string jobGroup, DateTimeOffset startTimeUtc, DateTimeOffset? endTimeUtc, IntervalUnit intervalUnit, int repeatInterval) : base(name, group, jobName, jobGroup) { StartTimeUtc = startTimeUtc; EndTimeUtc = endTimeUtc; RepeatIntervalUnit = intervalUnit; RepeatInterval = repeatInterval; }
/// <summary> /// Create a <see cref="IDailyTimeIntervalTrigger" /> that will occur at the given time, /// fire the identified job and repeat at the given /// interval until the given end time. /// </summary> /// <param name="name"></param> /// <param name="group"></param> /// <param name="jobName"></param> /// <param name="jobGroup"></param> /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" />to fire.</param> /// <param name="endTimeUtc">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" />to quit repeat firing.</param> /// <param name="startTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should begin occurring.</param> /// <param name="endTimeOfDayUtc">The <see cref="TimeOfDay" /> that the repeating should stop occurring.</param> /// <param name="intervalUnit">The repeat interval unit. The only intervals that are valid for this type of trigger are /// <see cref="IntervalUnit.Second"/>, <see cref="IntervalUnit.Minute"/>, and <see cref="IntervalUnit.Hour"/>.</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public DailyTimeIntervalTriggerImpl(string name, string group, string jobName, string jobGroup, DateTimeOffset startTimeUtc, DateTimeOffset? endTimeUtc, TimeOfDay startTimeOfDayUtc, TimeOfDay endTimeOfDayUtc, IntervalUnit intervalUnit, int repeatInterval) : base(name, group, jobName, jobGroup) { StartTimeUtc = startTimeUtc; EndTimeUtc = endTimeUtc; RepeatIntervalUnit = intervalUnit; RepeatInterval = repeatInterval; StartTimeOfDay = startTimeOfDayUtc; EndTimeOfDay = endTimeOfDayUtc; }
/// <summary> /// Create a <see cref="ICalendarIntervalTrigger" /> that will occur immediately, and /// repeat at the given interval /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="group">Group for the trigger instance.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, string group, IntervalUnit intervalUnit, int repeatInterval) : this(name, group, SystemTime.UtcNow(), null, intervalUnit, repeatInterval) { }
public Interval(long factor, IntervalUnit unit) { Factor = factor; Unit = unit; SetSeconds(Factor, unit); }
/// <summary> /// Create a <see cref="CalendarIntervalTriggerImpl" /> that will occur immediately, and /// repeat at the given interval. /// </summary> /// <param name="name">Name for the trigger instance.</param> /// <param name="intervalUnit">The repeat interval unit (minutes, days, months, etc).</param> /// <param name="repeatInterval">The number of milliseconds to pause between the repeat firing.</param> public CalendarIntervalTriggerImpl(string name, IntervalUnit intervalUnit, int repeatInterval) : this(name, null, intervalUnit, repeatInterval) { }
public Job Seconds() { _intervalUnit = IntervalUnit.Second; return(this); }