Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Google/GCalendarAdapter.cs @ 154:2233039ac2eb
Unificando vistas
author | Nelo@Guinea.neluz.int |
---|---|
date | Wed, 03 Aug 2011 01:02:42 -0300 |
parents | 0ea32a748453 |
children | 734d3f0853bf |
line wrap: on
line source
using System; using Google.GData.Calendar; using Google.GData.Extensions; namespace AltNetHispano.Agendas.Google { public class GCalendarAdapter : IGCalendarAdapter { private readonly CalendarService _service; private readonly Uri _feedUri; public bool CreateEvent(IGEventDetail gEventDetail, out string message) { try { var entry = new EventEntry { Title = { Text = gEventDetail.Title }, Content = { Content = gEventDetail.Summary } }; var eventLocation = new Where { ValueString = gEventDetail.Location }; entry.Locations.Add(eventLocation); var eventTime = new When(gEventDetail.StartEvent, gEventDetail.EndEvent); entry.Times.Add(eventTime); _service.Insert(_feedUri, entry); message = "Event create successful"; return true; } catch (Exception exception) { message = exception.Message; return false; } } public bool DeleteEvent(DateTime startEvent, DateTime endEvent, out string message) { try { var myQuery = new EventQuery { StartTime = startEvent, EndTime = endEvent, Uri = _feedUri }; var myResultsFeed = _service.Query(myQuery); if (myResultsFeed.Entries.Count > 0) { myResultsFeed.Entries[0].Delete(); message = "Event delete successful"; return true; } message = "Event not found"; return false; } catch (Exception exception) { message = exception.Message; return false; } } public GCalendarAdapter(string applicationName ,string userName, string password, string calendarId) { _service = new CalendarService(applicationName); _service.setUserCredentials(userName, password); _feedUri = new Uri("https://www.google.com/calendar/feeds/" + calendarId + "/private/full"); } } }