public UserCalendarsPreferences Load() { UserCalendarsPreferences calendars = new UserCalendarsPreferences(); try { if (File.Exists(CONFIG)) { log.Debug("Loading UserCalendarsPreferences..."); Stream stream = File.Open(CONFIG, FileMode.Open); BinaryFormatter bformatter = new BinaryFormatter(); calendars = (UserCalendarsPreferences)bformatter.Deserialize(stream); stream.Close(); log.Debug("UserCalendarsPreferences were loaded"); } } catch (Exception ex) { log.Error("Failed to load UserCalendarsPreferences:", ex); } return(calendars); }
public CalendarEventList GetEventsMultipleCalendars(IGoogleCalendar calendar, DateTime start, DateTime end, UserCalendarsPreferences preferences) { CalendarEventList selectedEvents = new CalendarEventList(); var userCalendars = preferences.UserCalendars; foreach (var userCalendar in userCalendars) { CalendarEventList events = new CalendarEventList(); if (userCalendar.IsVisible == true) { calendar.SetCalendar(userCalendar.Id); events = GetEvents(calendar, start, end); calendar.SetCalendar(DEFAULT_CALENDAR); } // Mark events from not default calendar as fake if (userCalendar.IsPrimary == false) { foreach (var ev in events) { ev.IsFake = true; } } selectedEvents.AddRange(events); } selectedEvents = AddEmptyDaysFakeEvents(selectedEvents, start, end, preferences); return(selectedEvents); }
public CalendarEventList GetEventsMultipleCalendars(IGoogleCalendar calendar, TimeIntervals period, UserCalendarsPreferences preferences) { return(GetEventsMultipleCalendars(calendar, period.Start, period.End, preferences)); }
private CalendarEventList AddEmptyDaysFakeEvents(CalendarEventList events, DateTime start, DateTime end, UserCalendarsPreferences preferences) { if (preferences.ShowEmptyDays || preferences.ShowEmptyWeekends) { HashSet <DateTime> emptyDays = new HashSet <DateTime>(); // Add all days in the period to empty days list foreach (DateTime day in EachDay(start, end)) { emptyDays.Add(new DateTime(day.Year, day.Month, day.Day)); } // Remove days from empty day list if there is an event in this day foreach (var ev in events) { emptyDays.Remove(new DateTime(ev.Start.Year, ev.Start.Month, ev.Start.Day)); DateTime stop = ev.End ?? ev.Start; emptyDays.Remove(new DateTime(stop.Year, stop.Month, stop.Day)); } // Add Fake Events for empty days foreach (var emptyDay in emptyDays) { if (preferences.ShowEmptyDays == true && preferences.ShowEmptyWeekends == false) { events.Add(new CalendarEvent("Empty", emptyDay)); } else if (preferences.ShowEmptyDays == false && preferences.ShowEmptyWeekends == true) { if (IsWeekend(emptyDay)) { events.Add(new CalendarEvent("Weekend", emptyDay)); } } else if (preferences.ShowEmptyDays == true && preferences.ShowEmptyWeekends == true) { if (IsWeekend(emptyDay)) { events.Add(new CalendarEvent("Weekend", emptyDay)); } else { events.Add(new CalendarEvent("Empty", emptyDay)); } } } events.Sort((ev1, ev2) => DateTime.Compare(ev1.Start, ev2.Start)); } return(events); }