Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Google/GCalendarAdapter.cs @ 256:12d72efb43ca
Combinar
author | juanjose.montesdeocaarbos |
---|---|
date | Tue, 18 Oct 2011 07:26:59 -0300 |
parents | 734d3f0853bf |
children |
line wrap: on
line source
using System; using AltNetHispano.Agendas.Configurations; 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) : this(applicationName, AgendasConfigurationManager.Publicadores.Google.Calendar. UserName, AgendasConfigurationManager.Publicadores.Google.Calendar. Password, AgendasConfigurationManager.Publicadores.Google.Calendar. CalendarId) { } 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"); } } }