private void Load() { timedImages.Clear(); try { FileStream file = new FileStream("timedimages.txt", FileMode.Open); StreamReader reader = new StreamReader(file); string line = reader.ReadLine(); TimedImageItem item = null; TimeFrame onframe = null; TimeFrame offframe = null; while (line != null) { line = line.Trim(); if (!line.StartsWith("#")) { string value; if (Framework.ExtractKey(out value, line, "name:")) { if (item != null) { if (onframe != null) { item.OnTimes.Add(onframe); onframe = null; } if (offframe != null) { item.OffTimes.Add(offframe); offframe = null; } timedImages.Add(item); } item = new TimedImageItem(); item.Name = value; } else if (Framework.ExtractKey(out value, line, "file:")) { item.Filename = value; } else if (Framework.ExtractKey(out value, line, "on_frame:")) { if (onframe != null) item.OnTimes.Add(onframe); onframe = new TimeFrame(); } else if (Framework.ExtractKey(out value, line, "on_start_date:")) { onframe.StartDate = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "on_stop_date:")) { onframe.StopDate = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "on_start_time:")) { onframe.StartTime = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "on_stop_time:")) { onframe.StopTime = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "on_recurrence:")) { onframe.Recurrence = (TimeFrame.RecurringType) Enum.Parse(typeof(TimeFrame.RecurringType), value); } else if (Framework.ExtractKey(out value, line, "on_recurrence_week:")) { onframe.RecurrenceWeek = (TimeFrame.RecurringWeek) Enum.Parse(typeof(TimeFrame.RecurringWeek), value); } else if (Framework.ExtractKey(out value, line, "on_weekdays:")) { onframe.WeekDays = value; } else if (Framework.ExtractKey(out value, line, "on_month:")) { onframe.Month = int.Parse(value); } else if (Framework.ExtractKey(out value, line, "on_day:")) { onframe.Day = int.Parse(value); } else if (Framework.ExtractKey(out value, line, "off_frame:")) { if (offframe != null) item.OnTimes.Add(offframe); offframe = new TimeFrame(); } else if (Framework.ExtractKey(out value, line, "off_start_date:")) { offframe.StartDate = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "off_stop_date:")) { offframe.StopDate = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "off_start_time:")) { offframe.StartTime = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "off_stop_time:")) { offframe.StopTime = DateTime.Parse(value); } else if (Framework.ExtractKey(out value, line, "off_recurrence:")) { offframe.Recurrence = (TimeFrame.RecurringType) Enum.Parse(typeof(TimeFrame.RecurringType), value); } else if (Framework.ExtractKey(out value, line, "off_recurrence_week:")) { offframe.RecurrenceWeek = (TimeFrame.RecurringWeek) Enum.Parse(typeof(TimeFrame.RecurringWeek), value); } else if (Framework.ExtractKey(out value, line, "off_weekdays:")) { offframe.WeekDays = value; } else if (Framework.ExtractKey(out value, line, "off_month:")) { offframe.Month = int.Parse(value); } else if (Framework.ExtractKey(out value, line, "off_day:")) { offframe.Day = int.Parse(value); } } line = reader.ReadLine(); } reader.Close(); reader.Dispose(); file.Close(); file.Dispose(); if (item != null) { if (onframe != null) { item.OnTimes.Add(onframe); } if (offframe != null) { item.OffTimes.Add(offframe); } timedImages.Add(item); } } catch (Exception ex) { Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); } }
private string GetImage(DateTime time) { time = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0); if (time != lastChecked) { lastChecked = time; List<TimedImageItem> items = FindActive(DateTime.Now); if (items.Count > 0) { if (activeItem != items[0]) { activeItem = items[0]; images.Clear(); string pathname = "pictures/" + items[0].Filename; Console.WriteLine("Loading images: " + pathname); if (File.GetAttributes(pathname).HasFlag(FileAttributes.Directory)) { Console.WriteLine("path is a directory: " + pathname); foreach (string name in Directory.GetFiles(pathname)) { Console.WriteLine("Add directory image: " + name); images.Add(name); } } else { Console.WriteLine("Add file image: " + pathname); images.Add(pathname); } } } } string result = ""; if (images.Count > 0) { if (time.Subtract(lastImageTime).TotalMinutes > minutesPerImage) { lastImageTime = time; imageIndex++; } if (imageIndex >= images.Count) imageIndex = 0; result = images[imageIndex]; } return result; }