コード例 #1
0
 public Schedule(ScheduleFileName filename,
                 ISunsetProvider sunsetProvider)
 {
     this.scheduleHelper = new ScheduleHelper(sunsetProvider);
     this.filename       = filename.FileName;
     LoadSchedule();
 }
コード例 #2
0
ファイル: Schedule.cs プロジェクト: jeremybytes/vslive-di-lab
        public void RollSchedule()
        {
            for (int i = Count - 1; i >= 0; i--)
            {
                var currentItem = this[i];
                if (currentItem.Info.EventTime.IsInPast())
                {
                    switch (currentItem.Info.Type)
                    {
                    case ScheduleType.Daily:
                        currentItem.Info.EventTime =
                            ScheduleHelper.RollForwardToNextDay(currentItem.Info);
                        break;

                    case ScheduleType.Weekday:
                        currentItem.Info.EventTime =
                            ScheduleHelper.RollForwardToNextWeekdayDay(currentItem.Info);
                        break;

                    case ScheduleType.Weekend:
                        currentItem.Info.EventTime =
                            ScheduleHelper.RollForwardToNextWeekendDay(currentItem.Info);
                        break;

                    case ScheduleType.Once:
                        this.RemoveAt(i);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Schedule.cs プロジェクト: jeremybytes/vslive-di-lab
 private void LoadScheduleFromCSV(string fileName)
 {
     if (File.Exists(fileName))
     {
         var    sr = new StreamReader(fileName);
         string line;
         while ((line = sr.ReadLine()) != null)
         {
             var fields       = line.Split(',');
             var scheduleItem = new ScheduleItem()
             {
                 ScheduleSet = fields[0],
                 Info        = new ScheduleInfo()
                 {
                     EventTime = ScheduleHelper.Today() +
                                 DateTime.Parse(fields[1]).TimeOfDay,
                     TimeType       = (ScheduleTimeType)Enum.Parse(typeof(ScheduleTimeType), fields[2], true),
                     RelativeOffset = TimeSpan.Parse(fields[3]),
                     Type           = (ScheduleType)Enum.Parse(typeof(ScheduleType), fields[4], true),
                 },
                 Device    = Int32.Parse(fields[5]),
                 Command   = (DeviceCommands)Enum.Parse(typeof(DeviceCommands), fields[6]),
                 IsEnabled = bool.Parse(fields[7]),
             };
             this.Add(scheduleItem);
         }
         RollSchedule();
     }
 }
コード例 #4
0
 public List <ScheduleItem> GetCurrentScheduleItems()
 {
     return(this.Where(si => si.IsEnabled &&
                       ScheduleHelper.DurationFromNow(si.Info.EventTime) < TimeSpan.FromSeconds(30))
            .ToList());
 }
コード例 #5
0
 public Schedule(string filename, ISunsetProvider sunsetProvider)
 {
     this.scheduleHelper = new ScheduleHelper(sunsetProvider);
     this.filename       = filename;
     LoadSchedule();
 }