internal static Schedule ToSchedule(this string rawSchedule) { string[] args = ParsingTools.SplitArguments(rawSchedule); var s = new Schedule { Name = args[0], Date = args[1].ToLower().FixScheduleDate(), Time = args[2], Action = args[3].Replace("\"", string.Empty) .Replace("'", string.Empty), }; s.Status = args.Length > 4 ? s.Status = Convert.ToBoolean(args[4]) : s.Status = Convert.ToBoolean(Schedule.State.Enable); return s; }
static void ScheduleListener(Schedule oSchedule, int interval) { bool _done = false; IList<DayOfWeek> WorkDays = new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday }; IList<DayOfWeek> Weekend = new[] { DayOfWeek.Saturday, DayOfWeek.Sunday }; var method = Methods.Instance; lock (_schedule_locker) { while (oSchedule.Status) { if ((oSchedule.Date == Period.Repeat || oSchedule.Date == Period.Interval || oSchedule.Date == Period.Timer) || // repeated (ms) (oSchedule.Date == Period.Daily || oSchedule.Date == Period.Everyday) && oSchedule.Time == method.GetTime24() || // every day oSchedule.Date == Period.Workdays && oSchedule.Time == method.GetTime24() && WorkDays.Contains(DateTime.Now.DayOfWeek) || // workdays oSchedule.Date == Period.Weekend && oSchedule.Time == method.GetTime24() && Weekend.Contains(DateTime.Now.DayOfWeek) || // weekends oSchedule.Date.ToUpper().Contains(method.GetDay().ToUpper()) && oSchedule.Time == method.GetTime24() || // specific day oSchedule.Date == method.GetCalendarDate() && oSchedule.Time == method.GetTime24()) // specific date - only once, then deleted { if (!_done) { if (method.GetInstructionSet(oSchedule.Action).Count > 0) oSchedule.Action.Parse(); else Parser.SayText(oSchedule.Action); if (oSchedule.Date != Period.Repeat && oSchedule.Date != Period.Interval && oSchedule.Date != Period.Timer) _done = true; if (oSchedule.Date != Period.Repeat && oSchedule.Date != Period.Interval && oSchedule.Date != Period.Timer && oSchedule.Date != Period.Daily && oSchedule.Date != Period.Everyday && oSchedule.Date != Period.Weekend && oSchedule.Date != Period.Workdays && !oSchedule.Date.ToUpper().Contains(method.GetDay().ToUpper())) ChangeStatus(oSchedule.Name, State.Remove); } } else _done = false; Monitor.Wait(_schedule_locker, interval); } } }
internal static string Add(Schedule ss, int interval) { interval = interval < 1000 ? 1000 : interval; try { if (!ScheduleList.Contains(ss)) ScheduleList.Add(ss); lock (_schedule_locker) Task.Factory.StartNew(() => ScheduleListener(ss, interval)); return "Schedule " + ss.Name + " added"; } catch { return "Failed to add " + ss.Name + " schedule"; } }
internal static string Add(Schedule ss) { return Add(ss, 1000); }