Exemplo n.º 1
1
        /// <summary>
        /// Queries the calendar for events matching the specified criteria.
        /// </summary>
        /// <param name="fullTextQuery"></param>
        /// <param name="from"></param>
        /// <param name="until"></param>
        /// <returns></returns>
        public CalendarEvent[] GetEvents(string fullTextQuery, DateTime? from, DateTime? until)
        {
            EventQuery query = new EventQuery();

            query.Uri = new Uri(CALENDAR_URI);

            query.Query = fullTextQuery;

            if (from != null)
            {
                query.StartTime = from.Value;
            }

            if (until != null)
            {
                query.EndTime = until.Value;
            }

            EventFeed calFeed = _service.Query(query);

            List<CalendarEvent> events = CollectionUtils.Map<EventEntry, CalendarEvent, List<CalendarEvent>>(calFeed.Entries,
                delegate(EventEntry e) { return new CalendarEvent(e); });
            events.Sort();
            return events.ToArray();
        }
Exemplo n.º 2
0
 public bool Delete(Task task)
 {
     ErrorMessage = String.Empty;
     CalendarService service = new CalendarService("googleCalendar");
     service.setUserCredentials(task.AccountInfo.Username, task.AccountInfo.Password);
     Log.InfoFormat("Fetching google account : [{0}]", task.AccountInfo.ToString());
     string queryUri = String.Format(CultureInfo.InvariantCulture,
                                     "http://www.google.com/calendar/feeds/{0}/private/full",
                                     service.Credentials.Username);
     Log.DebugFormat("Query='{0}'", queryUri);
     EventQuery eventQuery = new EventQuery(queryUri);
     try
     {
         EventFeed eventFeed = service.Query(eventQuery);
         foreach (EventEntry eventEntry in eventFeed.Entries.Cast<EventEntry>())
         {
             if (eventEntry.Times.Count > 0)
             {
                 if (eventEntry.EventId == task.Id)
                 {
                     Log.InfoFormat("Deleting : [{0}]-[{1}]", eventEntry.EventId, eventEntry.Title);
                     eventEntry.Delete();
                     return true;
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Log.ErrorFormat(exception.Message);
         Log.ErrorFormat(exception.ToString());
         ErrorMessage = exception.Message;
     }
     return false;
 }
Exemplo n.º 3
0
 public EventFeed GetAllCalendarEvents()
 {
     EventQuery query = new EventQuery();
     query.Uri = new Uri("https://www.google.com/calendar/feeds/" + _userID + "/private/full");
     EventFeed resultFeed = _myService.Query(query);
     return resultFeed;
 }
        public static List<CalendarEvent> GetCalendarEvents(Calendar calendar)
        {
            List<CalendarEvent> eventList = new List<CalendarEvent>();

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("GoogleCalendarReminder");
            service.SetAuthenticationToken(GetAuthToken());

            //service.setUserCredentials(Account.Default.Username
            //                            , SecureStringUtility.SecureStringToString(Account.Default.Password));

            query.Uri = new Uri(calendar.CalendarUri);
            query.SingleEvents = true;
            query.StartTime = DateTime.Now;
            query.EndTime = DateTime.Today.AddDays(Settings.Default.DayRange);

            EventFeed calFeed;
            try
            {
                calFeed = service.Query(query) as EventFeed;
            }
            catch (Exception)
            {
                return null;
            }

            // now populate the calendar
            while (calFeed != null && calFeed.Entries.Count > 0)
            {
                foreach (EventEntry entry in calFeed.Entries)
                {
                    eventList.Add(new CalendarEvent(entry)
                                        {
                                            Color = calendar.Color
                                        });
                }

                // just query the same query again.
                if (calFeed.NextChunk != null)
                {
                    query.Uri = new Uri(calFeed.NextChunk);

                    try
                    {
                        calFeed = service.Query(query) as EventFeed;
                    }
                    catch (Exception ex)
                    {
                        return null;
                    }
                }
                else
                {
                    calFeed = null;
                }
            }

            return eventList;
        }
Exemplo n.º 5
0
        public IEnumerable<Event> GetAllEvents()
        {
            EnsureAuthentication();

            var eventQuery = new EventQuery { Uri = _calendarUri };
            var eventFeed = _calendarService.Query(eventQuery);
            return eventFeed.Entries.Select(x => MapToEvent(x as EventEntry));
        }
Exemplo n.º 6
0
 public bool IsUserAvailable(string user, DateTime datetime)
 {
     EventQuery query = new EventQuery(string.Format(feedUrl, user));
     query.StartTime = datetime;      
     query.EndTime = datetime + new System.TimeSpan(0, 0, 30, 0);
     EventFeed feed = calendar.Query(query);
     return feed.Entries.Count == 0;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Checks whether a calendar has any events.
        /// </summary>
        /// <returns><c>true</c> if the calendar has any events, otherwise <c>false</c>.</returns>
        public bool HasEvents()
        {
            var query = new EventQuery( _calendarUrl )
            {
                NumberToRetrieve = 1,
            };

            EventFeed feed = _service.Query( query );

            return feed.Entries.Any();
        }
        public IList<CalendarItem> GetAllEvents()
        {
            var query = new EventQuery { Uri = new Uri("http://www.google.com/calendar/feeds/[email protected]/private/full") };

            return (from i in CreateCalendarService().Query(query).Entries
                       select new CalendarItem
                       {
                           Date = ((EventEntry)i).Times.First().StartTime,
                           Title = i.Title.Text
                       }).ToList();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the calendar items.
        /// </summary>
        /// <returns>The Calendar Items.</returns>
        public IEnumerable<EventEntry> GetCalendarItems()
        {
            var query = new EventQuery(ApplicationData.GoogleCalendarUri.ToString());
            var result = this.CalendarService.Query(query);

            if (result != null)
            {
                return result.Entries.Cast<EventEntry>();
            }

            return new List<EventEntry>();
        }
        public IEnumerable<CalendarItem> GetItems()
        {
            var query = new EventQuery
                            {
                                Uri = new Uri(GOOGLE_CALENDAR_URI),
                                StartTime = DateTime.Now.AddMonths(_monthsPast),
                                EndTime = DateTime.Now.AddMonths(_monthsFuture)
                            };
            EventFeed calFeed = Service.Query(query);

            return calFeed.Entries.Select(item => new GoogleCalendarItem((EventEntry)item)).OrderBy(calendarItem => calendarItem.Start);
        }
Exemplo n.º 11
0
        public IEnumerable<string> Alle_Termine(DateTime startTime, DateTime endTime) {
            var service = CalendarService();
            var query = new EventQuery(string.Format("https://www.google.com/calendar/feeds/{0}/private/full", googleUserName));
            query.StartTime = startTime;
            query.EndTime = endTime;

            EventFeed eventFeed = service.Query(query);
            if (eventFeed.Entries == null) {
                return new string[0];
            }

            return eventFeed.Entries.Select(x => ((EventEntry)x).Times.First().StartTime + ": " + x.Title.Text);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Prints the titles of all events on the specified calendar.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        static void PrintAllEvents(CalendarService service)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("All events on your calendar:");
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Prints the titles of all events matching a full-text query.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="queryString">The text for which to query.</param>
        static void FullTextQuery(CalendarService service, String queryString)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            myQuery.Query = queryString;

            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("Events matching \"{0}\":", queryString);
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
 /// <summary>
 /// Delete a given event from the google calendar
 /// </summary>
 public void DeleteEvent(string id)
 {
     EventQuery query = new EventQuery(string.Format(calendarUrl, this.calendarId));
     query.ExtraParameters = string.Format("extq=[{1}:{0}]", id, syncExtendedParameterName);
     EventFeed myResultsFeed = this.calService.Query(query);
     if (myResultsFeed.Entries.Count == 1)
     {
         EventEntry firstMatchEntry = (EventEntry)myResultsFeed.Entries[0];
         firstMatchEntry.Delete();
     }
     else if (myResultsFeed.Entries.Count > 1)
     {
         throw new Exception("DeleteEvent: Found more then one event with the given id.");
     }
 }
        public IList<CalendarItem> GetFutureEvents(int maxNumberOfEventsToReturn)
        {
            var query = new EventQuery
                            {
                                Uri = new Uri("http://www.google.com/calendar/feeds/[email protected]/private/full"),
                                StartTime = DateTime.Now
                            };

            return (from i in CreateCalendarService().Query(query).Entries
                       orderby ((EventEntry) i).Times.First().StartTime
                       select new CalendarItem
                       {
                           Date = ((EventEntry)i).Times.First().StartTime,
                           Title = i.Title.Text
                       }).Take(maxNumberOfEventsToReturn).ToList();
        }
        public Appointment GetAppointment(string eventId)
        {
            Appointment appointment = null;

            var query = new EventQuery();

            CalendarService calendarService = GetCalendarService(query, eventId, DateTime.MinValue, DateTime.MaxValue);

            var calFeed = calendarService.Query(query);
            if (calFeed.Entries.Any())
            {
                var entry = (EventEntry) calFeed.Entries.First();
                appointment = GetAppointmentFromEventEntry(entry);
            }

            return appointment;
        }
Exemplo n.º 17
0
        private List<Event> getEvents(String url, DateTime startDateTime, DateTime endDateTime)
        {
            // Create the query object:
            EventQuery query = new EventQuery();
            query.Uri = new Uri(url);
            query.SingleEvents = true;
            query.FutureEvents = false;
            query.StartTime = startDateTime;
            query.EndTime = endDateTime.Date.AddDays(1).AddSeconds(-1);
            query.NumberToRetrieve = 100;

            // Tell the service to query:
            EventFeed calFeed = getService().Query(query);
            AtomEntryCollection entries = calFeed.Entries;

            return mapEvents(entries);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Prints the titles of all events in a specified date/time range.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="startTime">Start time (inclusive) of events to print.</param>
        /// <param name="endTime">End time (exclusive) of events to print.</param>
        static void DateRangeQuery(CalendarService service, DateTime startTime, DateTime endTime)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            myQuery.StartTime = startTime;
            myQuery.EndTime = endTime;

            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("Matching events from {0} to {1}:", 
                              startTime.ToShortDateString(),
                              endTime.ToShortDateString());
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
Exemplo n.º 19
0
        public List<CalendarEvent> GetAllEvents(string calID)
        {
            EventQuery myQuery = new EventQuery(String.Format("https://www.google.com/calendar/feeds/{0}/private/full",calID));
            EventFeed myResultsFeed = calendarService.Query(myQuery) as EventFeed;
            List<CalendarEvent> result = new List<CalendarEvent>();

            foreach (EventEntry item in myResultsFeed.Entries)
            {
                var calendarEvent = new CalendarEvent
                {
                    Title = item.Title.Text,
                    Summary = item.Content.Content,
                    StartTime = item.Times.First().StartTime.ToString(),
                    EndTime = item.Times.First().EndTime.ToString()
                };

                result.Add(calendarEvent);
            }

            return result;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Purges events from a Google Calendar within a specified date range.
        /// </summary>
        /// <param name="start">The start date.</param>
        /// <param name="end">The end date.</param>
        /// <returns>Returns names of calendar events that were deleted.</returns>
        public IEnumerable<string> Purge( DateTime start, DateTime end )
        {
            var query = new EventQuery( _calendarUrl )
                        {
                            StartDate = start,
                            EndDate = end,
                        };

            EventFeed feed = _service.Query( query );

            var deleted = new List<string>();

            // TODO: (P. Palmer) [2014-06-18] Why are we calling Query over and over again in PurgeAll? What's wrong with this:
            for( int i = feed.Entries.Count - 1; i >= 0; i-- )
            {
                feed.Entries[i].Delete();
                deleted.Add( feed.Entries[i].Title.Text );
            }

            return deleted;
        }
Exemplo n.º 21
0
 public IEnumerable<GCalItem> ReadSchedule(DateTime startTime, DateTime endTime, Boolean allDays)
 {
     EventQuery query = new EventQuery();
     query.Uri = new Uri("https://www.google.com/calendar/feeds/" + this._gmailID + "/private/full");
     query.StartTime = startTime;
     query.EndTime = endTime.AddDays(1);
     query.SortOrder = CalendarSortOrder.descending;
     query.SingleEvents = true;
     EventFeed feeds = _gCal.Query(query);
     while (feeds != null && feeds.Entries.Count > 0)
     {
         foreach(EventEntry entry in feeds.Entries)
         {
             GCalItem item = new GCalItem
             {
                     Title = entry.Title.Text,
                     AllDay = entry.Times[0].AllDay,
                     StartTime = entry.Times[0].StartTime,
                     EndTime = entry.Times[0].EndTime,
                     Location = entry.Locations[0].ValueString
             };
             List<String> guests = new List<String>();
             foreach(Who w in entry.Participants)
             {
                 guests.Add(w.Email);
             }
             item.GuestsEmail = guests;
             yield return item;
         }
         if(feeds.NextChunk != null)
         {
             query.Uri = new Uri(feeds.NextChunk);
             feeds = _gCal.Query(query);
         }
         else
         {
             feeds = null;
         }
     }
 }
        public EventDto[] GetItems()
        {
            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("Virtual ALT.NET calendar");

            query.Uri = new Uri(@"http://www.google.com/calendar/feeds/[email protected]/public/full");
            query.StartTime = DateTime.Now;
            query.EndTime = DateTime.Now.AddMonths(3);
            query.SingleEvents = true;
            query.ExtraParameters = "orderby=starttime&sortorder=ascending";

            try
            {
                EventFeed calFeed = service.Query(query);

                return this.GetEventDtos(calFeed.Entries.OfType<EventEntry>());
            }
            catch (Exception)
            {
                return new EventDto[0];
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length != 1 && args.Length != 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];

            string userName = args.Length == 3 ? args[1] : null;
            string passWord = args.Length == 3 ? args[2] : null;

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query) as EventFeed;

            Console.WriteLine("");
            Console.WriteLine("Query Feed Test " + query.Uri);

            Console.WriteLine("Post URI is:  " + calFeed.Post); 

            foreach (EventEntry feedEntry in calFeed.Entries)
            {
                DumpEventEntry(feedEntry);
            }
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length < 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];
            string userName = args[1];
            string passWord = args[2];

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query);

            EventEntry insertedEntry = InsertEvent(calFeed, "Conference www2006",
                "Frank Mantek", DateTime.Now, 
                                DateTime.Now.AddDays(1), 
                                true,
                                "Edinburgh");

            if (insertedEntry != null) 
            {
                DumpEventEntry(insertedEntry);
            }
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length < 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];
            string userName = args[1];
            string passWord = args[2];

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query) as EventFeed;

 			foreach (EventEntry entry in calFeed.Entries)
            {
            	if (entry.Title.Text == "Conference www2006") 
            	{
                	entry.Content.Content = "The conference was fun... ";
                	entry.Update();
                	Console.WriteLine("Updated the Conference entry"); 
                }
            }
        }
Exemplo n.º 26
0
        private void RefreshFeed()
        {
            string calendarURI = this.CalendarURI.Text;
            string userName =    this.UserName.Text;
            string passWord =    this.Password.Text;

            this.entryList = new ArrayList(50);
            ArrayList dates = new ArrayList(50);
            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("CalendarSampleApp");

            if (userName != null && userName.Length > 0)
            {
                service.setUserCredentials(userName, passWord);
            }

            // only get event's for today - 1 month until today + 1 year

            query.Uri = new Uri(calendarURI);

            query.StartTime = DateTime.Now.AddDays(-28);
            query.EndTime = DateTime.Now.AddMonths(6);

            EventFeed calFeed = service.Query(query) as EventFeed;

            // now populate the calendar
            while (calFeed != null && calFeed.Entries.Count > 0)
            {
                // look for the one with dinner time...
                foreach (EventEntry entry in calFeed.Entries)
                {
                    this.entryList.Add(entry);
                    if (entry.Times.Count > 0)
                    {
                        foreach (When w in entry.Times)
                        {
                            dates.Add(w.StartTime);
                        }
                    }
                }
                // just query the same query again.
                if (calFeed.NextChunk != null)
                {
                    query.Uri = new Uri(calFeed.NextChunk);
                    calFeed = service.Query(query) as EventFeed;
                }
                else
                    calFeed = null;
            }

            DateTime[] aDates = new DateTime[dates.Count];

            int i =0;
            foreach (DateTime d in dates)
            {
                aDates[i++] = d;
            }

            this.calendarControl.BoldedDates = aDates;
        }
        protected override void ProcessRecord()
        {
            Log.Debug("Get-OSAGCalendar - ProcessRecord - Started");

            CalendarService service = new CalendarService("OSA");
            service.setUserCredentials(Username, Password);

            EventQuery query = new EventQuery();
            query.Uri = new Uri("http://www.google.com/calendar/feeds/" + Username + "/private/full");

            if (FromDate != DateTime.MinValue) query.StartTime = fromDate;

            query.RecurrenceStart = DateTime.Now;

            if (ToDate != DateTime.MinValue) query.EndTime = ToDate;

            if (FutureEvents)
            {
                Log.Debug("Only looking for future events");
                query.FutureEvents = true;
            }
            else
                query.FutureEvents = false;

            query.SortOrder = CalendarSortOrder.ascending;
            query.ExtraParameters = "orderby=starttime";

            // Tell the service to query:
            EventFeed calFeed = service.Query(query);

            List<CalendarEvent> events = new List<CalendarEvent>();

            foreach (var entry in calFeed.Entries)
            {
               Log.Debug("Found Entry: " + entry.ToString());
               EventEntry eventEntry = entry as Google.GData.Calendar.EventEntry;
               if (eventEntry != null)
               {
                   if (!eventEntry.Status.Value.Contains("event.canceled"))
                   {
                       Log.Debug("Entry is an EventEntry");
                       CalendarEvent c = new CalendarEvent();
                       c.Title = eventEntry.Title.Text;
                       c.Content = eventEntry.Content.Content;

                       if (eventEntry.Times.Count > 0)
                       {
                           c.Start = eventEntry.Times[0].StartTime;
                           c.End = eventEntry.Times[0].EndTime;
                       }

                       events.Add(c);
                   }
                }
            }
            WriteObject(events);
        }
        public void WriteEventInformation()
        {
            log.Debug("Attempting to write all calendar information for user.....");
            EventQuery query = new EventQuery();
            query.Uri = new Uri("https://www.google.com/calendar/feeds/[email protected]/private/[email protected]");
            // Tell the service to query:
            EventFeed calFeed = service.Query(query);
            int i = 0;
            writer = new ExchangeWriter();
            List<String> List = new List<String>();
            foreach (EventEntry entry in calFeed.Entries)
            {

                if(List.Contains(entry.EventId) == false){
                List.Add(entry.EventId);
                log.Debug("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ");
                log.Debug("Calendar entry number: " + (i++));
                log.Debug("Calendar entry title = " + entry.Title.Text);
                WriteTitleOrSummary(entry);//DONE - works
                GetCalendarId(entry);//not needed
                GetEventId(entry);//not needed
                WriteCreatorDisplayName(entry);//Cannot directly write it to exchange as exchange treate the organisor as the creator
                WriteEventId(entry);//not needed
                WriteUpdatedDateTimeW(entry);//don't think this is needed
                WriteDescription(entry); // DONE - works
                WriteEventStatus( entry); // i.e. confirmed
                WriteRecurrenceDetails(entry);// TODO
                WriteTransparency(entry); //i.e  opaque
                WriteVisibility(entry); //i.e. default
                WriteStartDateAndTime(entry);//DONE - works although need to test dif time zones
                WriteEndDateAndTime(entry);//DONE - works although need to test dif time zones
                WriteEventAllDay(entry);//DONE - works
                WriteLocation(entry); //DONE - works
                WriteEndTimeZone(entry);
                WriteReminders(entry); //DONE - works
                WriteAttendees(entry); //SO FAR HAVE WRITTEN ALL ATTENDEES AS OPTIONAL ATTENDEES
                WriteGuestsCanModify(entry); //STILL NEED TO GET DATA FROM GOOGLE

                writer.SaveAndResetAppointment();
                }
            }
        }
 /// <summary>
 /// overloaded to create typed version of Query
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <returns>EventFeed</returns>
 public EventFeed Query(EventQuery feedQuery)
 {
     return(base.Query(feedQuery) as EventFeed);
 }
Exemplo n.º 30
0
        private bool CollectEntries()
        {
            entries.Clear();

            EventQuery query = null;
            string queryString = "https://www.google.com/calendar/feeds/default/private/full";

            try
            {
                while (!string.IsNullOrEmpty(queryString))
                {
                    query = new EventQuery(queryString);
                    EventFeed feed = service.Query(query);

                    foreach (EventEntry entry in feed.Entries)
                    {
                        entries.Add(entry.Id.AbsoluteUri, entry);
                    }
                    queryString = feed.NextChunk;
                }
            }
            catch (System.Exception)
            {
                return false;
            }

            return true;
        }
Exemplo n.º 31
0
        public IEnumerable<ChannelEvent> GetEvents(ChannelCalendar calendar)
        {
            var creds = CredentialsProvider.GetCredentials();
            service.setUserCredentials(creds.Claim, creds.Evidence);
            string url = String.Format("http://www.google.com/calendar/feeds/{0}/private/full", creds.Claim);

            // Check for 404 with custom httpclient on photourl since regular HttpWebClient keeps throwing exceptions
            var token = service.QueryAuthenticationToken();
            var code = HttpStatusClient.GetStatusCode(url,
                new Dictionary<string, string> { { "Authorization", "GoogleLogin auth=" + token } });

            if (!(code == 200 || code == 302))
            {
                Logger.Warn("Not downloading calendar events because of un expected HttpStatusCode. Code = [0}", LogSource.Sync, code);

                yield break;
            }

            EventQuery query = new EventQuery { Uri = new Uri(url) };
            EventFeed feed = service.Query(query);

            foreach (EventEntry item in feed.Entries)
            {
                // Create a new channelevent
                ChannelEvent evt = new ChannelEvent();

                // Get the event key
                evt.ChannelEventKey = item.Id.Uri.ToString();

                // Get subject, description and location
                evt.Subject = item.Title.Text;
                evt.Description = item.Content.Content;
                evt.Location = item.Locations[0].ValueString;

                // Get the start, end date and date modified
                evt.StartDate = item.Times[0].StartTime;
                evt.EndDate = item.Times[0].EndTime;
                evt.Modified = item.Updated;

                // Get the date of the event when it was initially created
                evt.Stamp = item.Published;

                // Set the date of the event when it was created by Inbox2
                evt.DateCreated = DateTime.Now;

                // Get the status
                if (item.Status == EventEntry.EventStatus.CONFIRMED) evt.State = EventState.Confirmed;
                else if (item.Status == EventEntry.EventStatus.TENTATIVE) evt.State = EventState.Tentative;
                else if (item.Status == EventEntry.EventStatus.CANCELED) evt.State = EventState.Cancelled;
                else evt.State = EventState.Confirmed;

                // Get the visability (/class)
                if (item.EventVisibility.Value == EventEntry.Visibility.PUBLIC_VALUE) evt.Class = EventClassType.Public;
                else if (item.EventVisibility.Value == EventEntry.Visibility.PRIVATE_VALUE) evt.Class = EventClassType.Private;
                else if (item.EventVisibility.Value == EventEntry.Visibility.CONFIDENTIAL_VALUE) evt.Class = EventClassType.Confidential;
                else if (item.EventVisibility.Value == EventEntry.Visibility.DEFAULT_VALUE) evt.Class = EventClassType.Public;
                else evt.Class = EventClassType.Public;

                // Gmail hasn't a priority status, so set it to None
                evt.Priority = EventPriority.None;

                // Return the event
                yield return evt;
            }
        }