Example #1
0
        /**
         * filter events
         *
         * @param calId
         * @param startMin
         * @param updatedMin
         * @param maxResults
         * @return
         */
        public List <GCalEvent> GetEvents(String calId, DateTime?startDate, DateTime?maxEndDate, int maxResults)
        {
            List <GCalEvent> events = new List <GCalEvent>();

            try
            {
                GCal gcal = GetCalendar(calId);

                if (maxResults < 0)
                {
                    maxResults = DEFAULT_MAX_RESULTS;
                }

                EventsResource.ListRequest request = cs.Events.List(calId);
                request.MaxResults = maxResults;



                if (startDate != null)
                {
                    request.TimeMin = startDate;
                }

                request.TimeMax = maxEndDate;

                request.OrderBy      = Google.Apis.Calendar.v3.EventsResource.ListRequest.OrderByEnum.StartTime;
                request.SingleEvents = true;
                request.ShowDeleted  = false;

                Events gevents = request.Execute();

                foreach (Event e in gevents.Items)
                {
                    GCalEvent g = Convert(e, gcal);
                    g.Calendar = gcal;

                    events.Add(g);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(events);
        }
Example #2
0
        private GCalEvent Convert(Event e, GCal gcal)
        {
            if (e == null)
            {
                return(null);
            }

            GCalEvent item = new GCalEvent();

            item.Id    = e.Id;
            item.Title = e.Summary;

            ColorDefinition cdefCal       = new ColorDefinition();
            bool            colorCalFound = colors.Calendar.TryGetValue(gcal.ColorId, out cdefCal);

            if (colorCalFound)
            {
                item.HexaColorCal = cdefCal.Background.Replace("#", "");
            }

            item.HexaColor = "000000";
            if (e.ColorId != null)
            {
                ColorDefinition cdef       = new ColorDefinition();
                bool            colorFound = colors.Event__.TryGetValue(e.ColorId, out cdef);
                if (colorFound)
                {
                    item.HexaColor = cdef.Background.Replace("#", "");
                }
            }
            else
            {
                ColorDefinition cdef       = new ColorDefinition();
                bool            colorFound = colors.Calendar.TryGetValue(gcal.ColorId, out cdef);
                if (colorFound)
                {
                    item.HexaColor = item.HexaColorCal;
                }
            }


            if (e.Start.DateTime != null)
            {
                item.IsAllDay = false;
                item.Start    = e.Start.DateTime.Value;
                item.End      = e.End.DateTime.Value;
            }
            else
            {
                item.IsAllDay = true;

                // All day event if startTime is yyyy-MM-dd
                item.Start = DateTime.ParseExact(e.Start.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                item.End   = DateTime.ParseExact(e.End.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            }

            item.Link        = e.HtmlLink;
            item.IsRecurring = (!String.IsNullOrEmpty(e.RecurringEventId));

            return(item);
        }