public void Register() { if (!IsRegistered) { Schedules.Register(this); } }
public void Unregister() { if (IsRegistered) { Schedules.Unregister(this); } }
public virtual DateTime?FindAfter(DateTime dt) { if (Months == ScheduleMonths.None || Days == ScheduleDays.None || Times.Count == 0) { return(null); } TimeSpan ts; Validate(ref dt, out ts); try { var future = false; for (var year = dt.Year; year <= dt.Year + 1; year++) { for (var month = future ? 1 : dt.Month; month <= 12; month++) { if (!HasMonth(Schedules.ConvertMonth(month))) { future = true; continue; } var start = new DateTime(year, month, future ? 1 : dt.Day, 0, 0, 0, dt.Kind); var end = new DateTime(year, month, DateTime.DaysInMonth(year, month), 0, 0, 0, dt.Kind); for (var date = start; date <= end; date += _OneDay) { if (!HasDay(Schedules.ConvertDay(date.DayOfWeek))) { future = true; continue; } foreach (var time in Times.Where(t => future || t > ts).OrderBy(t => t.Ticks)) { return(new DateTime(year, month, date.Day, time.Hours, time.Minutes, 0, dt.Kind)); } future = true; } } future = true; } } catch (Exception e) { VitaNexCore.Catch(e); } return(null); }
public virtual DateTime?FindBefore(DateTime dt) { if (Months == ScheduleMonths.None || Days == ScheduleDays.None || Times.Count == 0) { return(null); } TimeSpan ts; Validate(ref dt, out ts); try { var past = false; for (var year = dt.Year; year >= dt.Year - 1; year--) { for (var month = past ? 12 : dt.Month; month >= 1; month--) { if (!HasMonth(Schedules.ConvertMonth(month))) { past = true; continue; } var start = new DateTime(year, month, past ? DateTime.DaysInMonth(year, month) : dt.Day, 0, 0, 0, dt.Kind); var end = new DateTime(year, month, 1, 0, 0, 0, dt.Kind); for (var date = start; date >= end; date -= _OneDay) { if (!HasDay(Schedules.ConvertDay(date.DayOfWeek))) { past = true; continue; } foreach (var time in Times.Where(t => past || t < ts).OrderByDescending(t => t.Ticks)) { return(new DateTime(year, month, date.Day, time.Hours, time.Minutes, 0, dt.Kind)); } past = true; } } past = true; } } catch (Exception e) { VitaNexCore.Catch(e); } return(null); }
public override string ToString() { var times = new string[_List.Count]; for (int i = 0; i < times.Length; i++) { times[i] = Schedules.FormatTime(_List[i]); } return(String.Join(", ", times)); }
protected override void CompileLayout(SuperGumpLayout layout) { base.CompileLayout(layout); layout.Replace( "label/header/title", () => AddLabelCropped(90, 15, 185, 20, GetTitleHue(), String.IsNullOrEmpty(Title) ? DefaultTitle : Title)); layout.Replace( "label/header/subtitle", () => AddLabelCropped(275, 15, 100, 20, HighlightHue, Schedules.FormatTime(DateTime.UtcNow.TimeOfDay, true))); }
public virtual DateTime?FindBefore(DateTime dt) { Validate(ref dt); TimeSpan ts; Validate(dt, out ts); bool past = false; for (int year = dt.Year; year >= dt.Year - 10; year--) { for (int month = dt.Month; month >= 1; month--) { if (!HasMonth(Schedules.ConvertMonth(month))) { past = true; continue; } try { var start = new DateTime(year, month, dt.Day); var end = new DateTime(year, month, 1); for (DateTime date = start; date >= end; date = date.Subtract(_OneDay)) { if (!HasDay(Schedules.ConvertDay(date.DayOfWeek))) { past = true; continue; } for (int i = Times.Count - 1; i >= 0; i--) { var time = Times[i]; if (time != null && (past || time.Value < ts)) { return(date.AddHours(time.Value.Hours).AddMinutes(time.Value.Minutes)); } } past = true; } } catch { } } } return(null); }
public virtual DateTime?FindAfter(DateTime dt) { Validate(ref dt); TimeSpan ts; Validate(dt, out ts); bool future = false; for (int year = dt.Year; year < dt.Year + 10; year++) { for (int month = dt.Month; month <= 12; month++) { if (!HasMonth(Schedules.ConvertMonth(month))) { future = true; continue; } try { var start = new DateTime(year, month, dt.Day); var end = new DateTime(year, month, DateTime.DaysInMonth(year, month)); for (DateTime date = start; date <= end; date = date.Add(_OneDay)) { if (!HasDay(Schedules.ConvertDay(date.DayOfWeek))) { future = true; continue; } for (int i = 0; i < Times.Count; i++) { var time = Times[i]; if (time != null && (future || time.Value > ts)) { return(date.AddHours(time.Value.Hours).AddMinutes(time.Value.Minutes)); } } future = true; } } catch { } } } return(null); }
public virtual string ToHtmlString(bool big = true) { DateTime now = DateTime.UtcNow; var html = new StringBuilder(); html.AppendFormat("Current Date: {0}\n", Schedules.FormatDate(now)); html.AppendFormat("Current Time: {0}\n", Schedules.FormatTime(now.TimeOfDay, true)); html.AppendLine("\nSchedule Overview:\n"); if (!_Enabled) { html.AppendLine("Schedule is currently disabled.".WrapUOHtmlColor(Color.OrangeRed)); return(html.ToString()); } bool print = false; string months = _Info.Months.ToString(), days = String.Empty, times = String.Empty; if (months == "All") { months = String.Join(" ", Enum.GetNames(typeof(ScheduleMonths))); months = months.Replace("All", String.Empty).Replace("None", String.Empty).Trim().Replace(" ", ", "); } if (months == "None") { html.AppendLine("Schedule requires at least one Month to be set.".WrapUOHtmlColor(Color.OrangeRed)); } else { days = _Info.Days.ToString(); if (days == "All") { days = String.Join(" ", Enum.GetNames(typeof(ScheduleDays))); days = days.Replace("All", String.Empty).Replace("None", String.Empty).Trim().Replace(" ", ", "); } if (days == "None") { html.AppendLine("Schedule requires at least one Day to be set.".WrapUOHtmlColor(Color.OrangeRed)); } else { times = _Info.Times.ToString(); if (String.IsNullOrWhiteSpace(times)) { html.AppendLine("Schedule requires at least one Time to be set.".WrapUOHtmlColor(Color.OrangeRed)); } else { int cc = 0; string wrap = String.Empty; foreach (char t in times) { if (t == ',') { cc++; wrap += ','; if (cc % 6 == 0) { wrap += '\n'; } else { wrap += ' '; } } else if (t != ' ') { wrap += t; } } times = wrap; print = true; } } } if (print) { html.AppendFormat("<BASEFONT COLOR=#{0:X6}>", Color.Cyan.ToArgb()); html.AppendLine("Schedule is set to perform an action:"); html.AppendLine("\n<B>In...</B>"); html.AppendLine(months); html.AppendLine("\n<B>On...</B>"); html.AppendLine(days); html.AppendLine("\n<B>At...</B>"); html.AppendLine(times); if (NextGlobalTick != null) { bool today = (NextGlobalTick.Value.Day == DateTime.UtcNow.Day); html.AppendLine( String.Format( "\n\nThe next tick will be at {0} {1}.", NextGlobalTick.Value.TimeOfDay.ToSimpleString("h:m:s"), today ? "today." : "on " + NextGlobalTick.Value.ToSimpleString("D, M d"))); } } return((big ? String.Format("<big>{0}</big>", html) : html.ToString()).WrapUOHtmlColor( SuperGump.DefaultHtmlColor, false)); }
protected override string GetLabelText(int index, int pageIndex, TimeSpan entry) { return(Schedules.FormatTime(entry, true)); }
public override string GetSearchKeyFor(TimeSpan key) { return(Schedules.FormatTime(key, true)); }