示例#1
0
        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);
        }
示例#2
0
        private static CalendarEventList ConvertToCalendarEvents(IList <Event> googleEvents)
        {
            CalendarEventList calendarEvents = new CalendarEventList();

            foreach (Event ev in googleEvents)
            {
                calendarEvents.Add(ConvertGoogleEventToCalendarEvent(ev));
            }

            return(calendarEvents);
        }
示例#3
0
        public CalendarEventList FormatEventsDatesStringRepresentation(CalendarEventList allEvents, DateTimePreferences preferences)
        {
            CalendarEventList formatedEvents = new CalendarEventList();

            bool multipleMonths;

            // Find if there are events from different month in the list by comparing years and month data of the first and last event in the list
            if (allEvents.Count > 1)
            {
                multipleMonths = allEvents[0].Start.Year != allEvents[allEvents.Count - 1].Start.Year ? true :
                                 allEvents[0].Start.Month != allEvents[allEvents.Count - 1].Start.Month;
            }
            else
            {
                multipleMonths = false;
            }

            try
            {
                int month = 0;

                foreach (CalendarEvent ev in allEvents)
                {
                    if (preferences.GroupByMonth && multipleMonths && month != ev.Start.Month)
                    {
                        formatedEvents.Add(new CalendarEvent(months[ev.Start.Month]));
                        month = ev.Start.Month;
                    }

                    ev.FormatedStartDate = preferences.StartDateTime(ev);
                    ev.FormatedEndDate   = preferences.EndDateTime(ev);
                    formatedEvents.Add(ev);
                }
                return(formatedEvents);
            }
            catch (Exception ex)
            {
                log.Error("Failed to format events dates", ex);
                return(allEvents);
            }
        }
示例#4
0
        public CalendarEventList SearchEvents(CalendarEventList events, String keyword)
        {
            CalendarEventList selectedEvents = new CalendarEventList();

            try
            {
                if (!String.IsNullOrEmpty(keyword))
                {
                    foreach (CalendarEvent ev in events)
                    {
                        if (!string.IsNullOrEmpty(ev.Title))
                        {
                            if (ev.Title.ToLower().Contains(keyword.ToLower()))
                            {
                                selectedEvents.Add(ev);
                            }
                        }
                        else if (!string.IsNullOrEmpty(ev.Location))
                        {
                            if (ev.Location.ToLower().Contains(keyword.ToLower()))
                            {
                                selectedEvents.Add(ev);
                            }
                        }
                        else if (!string.IsNullOrEmpty(ev.Location))
                        {
                            if (ev.Content.ToLower().Contains(keyword.ToLower()))
                            {
                                selectedEvents.Add(ev);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Failed to get events for a specified keyword \"" + keyword + "\"", ex);
            }

            return(selectedEvents);
        }
示例#5
0
        public CalendarEventList FilterByStatus(CalendarEventList allEvents, SortFilterPreferences preferences)
        {
            if (!preferences.EnableStatusFilter)
            {
                return(allEvents);
            }

            CalendarEventList filteredEvents = new CalendarEventList();

            foreach (CalendarEvent ev in allEvents)
            {
                if (ev.Status == (preferences.ShowConfirmedOnly ? CONFIRMED : TENTATIVE))
                {
                    filteredEvents.Add(ev);
                }
            }
            return(filteredEvents);
        }
示例#6
0
        public CalendarEventList FilterByStartTime(CalendarEventList allEvents, SortFilterPreferences preferences)
        {
            if (!preferences.EnableTimeFilter)
            {
                return(allEvents);
            }

            CalendarEventList filteredEvents = new CalendarEventList();

            foreach (CalendarEvent ev in allEvents)
            {
                int starTimeInMinutes = ev.Start.Hour * 60 + ev.Start.Minute;
                if (starTimeInMinutes >= preferences.TimeInMinutesMin && starTimeInMinutes <= preferences.TimeInMinutesMax)
                {
                    filteredEvents.Add(ev);
                }
            }
            return(filteredEvents);
        }
示例#7
0
        public CalendarEventList FilterByDayOfWeek(CalendarEventList allEvents, SortFilterPreferences preferences)
        {
            if (!preferences.EnableDayOfWeekFilter)
            {
                return(allEvents);
            }

            CalendarEventList filteredEvents = new CalendarEventList();

            foreach (CalendarEvent ev in allEvents)
            {
                if (ev.Start.DayOfWeek == DayOfWeek.Monday && preferences.Monday)
                {
                    filteredEvents.Add(ev);
                }
                else if (ev.Start.DayOfWeek == DayOfWeek.Tuesday && preferences.Tuesday)
                {
                    filteredEvents.Add(ev);
                }
                else if (ev.Start.DayOfWeek == DayOfWeek.Wednesday && preferences.Wednesday)
                {
                    filteredEvents.Add(ev);
                }
                else if (ev.Start.DayOfWeek == DayOfWeek.Thursday && preferences.Thursday)
                {
                    filteredEvents.Add(ev);
                }
                else if (ev.Start.DayOfWeek == DayOfWeek.Friday && preferences.Friday)
                {
                    filteredEvents.Add(ev);
                }
                else if (ev.Start.DayOfWeek == DayOfWeek.Saturday && preferences.Saturday)
                {
                    filteredEvents.Add(ev);
                }
                else if (ev.Start.DayOfWeek == DayOfWeek.Sunday && preferences.Sunday)
                {
                    filteredEvents.Add(ev);
                }
            }
            return(filteredEvents);
        }
示例#8
0
        public CalendarEventList GetEvents(IGoogleCalendar calendar, DateTime start, DateTime end)
        {
            log.Debug("Select events, period=" + start + " - " + end);
            CalendarEventList selectedEvents = new CalendarEventList();


            foreach (CalendarEvent ev in calendar.GetEvents(start, end))
            {
                try
                {
                    if (MatchStartDate(ev.Start, start) && MatchEndDate(ev.End, end))
                    {
                        selectedEvents.Add(ev);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Failed to get events for a specified period", ex);
                    log.Info("Event info: " + ev.ToString());
                }
            }
            log.Debug("Successfully selected events for a specified period");
            return(selectedEvents);
        }