The following code shows how to Retrieve All Calendar Feeds
public
void GetCalendarFeeds()
{
//"_day"
is a global Hashtable. The key is yearDay(string)-->the value is composed by
// a list
of object "Impegno". In this list there is an item for each events in
day.
//in the
object "Impegno" there are the seguent info: start date, end date,
title, description, event's uri.
//I use
this Hashtable to make update/delete of the events.
//when i
click on the MonthCalendar i load some variables with the references
_days.Clear();
EventQuery
query = new EventQuery();
CalendarService
service = new CalendarService("appName");
service.setUserCredentials("yourMail@gmail.com", "yourPassword");
service.QueryClientLoginToken();
//"cmb_calendars"
is a ComboBox on the form containing the calendar.
query.Uri = new Uri("http://www.google.com/calendar/feeds/" + ((ComboboxItem)cmb_calendars.SelectedItem).Value.ToString()
+ "/private/full");
//the
start/end period i want to get
query.StartTime = DateTime.Now.AddMonths(Convert.ToInt32("n-month before"));
query.EndTime = DateTime.Now.AddMonths(Convert.ToInt32("n-month after"));
EventFeed
calFeed = service.Query(query) as EventFeed;
DateTime[]
events = new DateTime[calFeed.Entries.Count];
while
(calFeed != null &&
calFeed.Entries.Count > 0)
{
foreach
(EventEntry entry in
calFeed.Entries)
{
When
w = entry.Times[0];
DateTime
d = w.StartTime;
string
day = d.Year.ToString() + d.DayOfYear.ToString();
//
if the feed is into _day, remove it and add it else...
if
(_days.ContainsKey(day))
{
//the list of the events per day
List<Impegno> even = (List<Impegno>)_days[day];
//below the definition of the class "Impegno"
Impegno imp = new Impegno(w.StartTime, w.EndTime, entry.Title.Text, "", entry.EditUri.ToString());
even.Add(imp);
_days.Remove(day);
_days.Add(day, even);
}
else
{
// if the feed is not present add it
List<Impegno> eventi =
new List<Impegno>();
Impegno imp = new Impegno(w.StartTime, w.EndTime, entry.Title.Text, "", entry.EditUri.ToString());
eventi.Add(imp);
_days.Add(day, eventi);
}
//calendar
is a MonthCalendar on the form
calendar.AddBoldedDate(d);
}
if
(calFeed.NextChunk != null)
{
query.Uri = new Uri(calFeed.NextChunk);
calFeed =
service.Query(query) as EventFeed;
}
else
calFeed = null;
}
calendar.UpdateBoldedDates();
}
*The following code shows the definition of the class "Impegno"
class Impegno
{
public DateTime _start;
public DateTime _end;
public string _title;
public string _description;
public string _uri;
public
Impegno(DateTime start, DateTime end, string
title, string description, string uri)
{
_start = start;
_end = end;
_title = title;
_description = description;
_uri = uri;
}
}