Mercurial > altnet-hispano
comparison 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 |
comparison
equal
deleted
inserted
replaced
124:35498fb9b59b | 125:34b2f85aecab |
---|---|
1 using System; | |
2 using Google.GData.Calendar; | |
3 using Google.GData.Extensions; | |
4 | |
5 namespace AltNetHispano.Agendas.Google | |
6 { | |
7 public class GCalendarAdapter : IGCalendarAdapter | |
8 { | |
9 private readonly CalendarService _service; | |
10 private readonly Uri _feedUri; | |
11 | |
12 public void CreateEvent(string title, DateTime startEvent, DateTime endEvent, string location, string summary) | |
13 { | |
14 var entry = new EventEntry | |
15 { | |
16 Title = { Text = title }, | |
17 Content = { Content = summary } | |
18 }; | |
19 | |
20 var eventLocation = new Where | |
21 { | |
22 ValueString = location | |
23 }; | |
24 | |
25 entry.Locations.Add(eventLocation); | |
26 | |
27 var eventTime = new When(startEvent, endEvent); | |
28 entry.Times.Add(eventTime); | |
29 | |
30 _service.Insert(_feedUri, entry); | |
31 } | |
32 | |
33 public void DeleteEvent(DateTime startEvent, DateTime endEvent) | |
34 { | |
35 var myQuery = new EventQuery | |
36 { | |
37 StartTime = startEvent, | |
38 EndTime = endEvent, | |
39 Uri = _feedUri | |
40 }; | |
41 | |
42 var myResultsFeed = _service.Query(myQuery); | |
43 if (myResultsFeed.Entries.Count > 0) | |
44 myResultsFeed.Entries[0].Delete(); | |
45 } | |
46 | |
47 public GCalendarAdapter(string applicationName ,string userName, string password, string calendarId) | |
48 { | |
49 _service = new CalendarService(applicationName); | |
50 _service.setUserCredentials(userName, password); | |
51 _feedUri = new Uri("https://www.google.com/calendar/feeds/" + calendarId + "/private/full"); | |
52 } | |
53 } | |
54 } |