diff Agendas/trunk/src/Agendas.Google/GCalendarAdapter.cs @ 125:34b2f85aecab

Se crea adaptador para conectar con Google Calendar, además de crear funcionalidad para insertar y eliminar un evento en el calendario de google. Se agregan package de nuget para el trabajo con Google Calendar.
author alabra
date Tue, 28 Jun 2011 23:32:52 -0400
parents
children 0ea32a748453
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Google/GCalendarAdapter.cs	Tue Jun 28 23:32:52 2011 -0400
@@ -0,0 +1,54 @@
+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 void CreateEvent(string title, DateTime startEvent, DateTime endEvent, string location, string summary)
+        {
+            var entry = new EventEntry
+                            {
+                                Title = { Text = title },
+                                Content = { Content = summary }
+                            };
+
+            var eventLocation = new Where
+                                    {
+                                        ValueString = location
+                                    };
+
+            entry.Locations.Add(eventLocation);
+
+            var eventTime = new When(startEvent, endEvent);
+            entry.Times.Add(eventTime);
+            
+            _service.Insert(_feedUri, entry);
+        }
+
+        public void DeleteEvent(DateTime startEvent, DateTime endEvent)
+        {
+            var myQuery = new EventQuery
+                              {
+                                  StartTime = startEvent,
+                                  EndTime = endEvent,
+                                  Uri = _feedUri
+                              };
+
+            var myResultsFeed = _service.Query(myQuery);
+            if (myResultsFeed.Entries.Count > 0)
+                myResultsFeed.Entries[0].Delete();
+        }
+
+        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");
+        }
+    }
+}
\ No newline at end of file