comparison Agendas/trunk/src/Agendas.Google/GCalendarAdapter.cs @ 158:734d3f0853bf

Manejando configuración de los publicadores con una sección propia en los .config Agregando la opción de habilitar / deshabilitar un publicador
author nelopauselli
date Fri, 05 Aug 2011 16:55:18 -0300
parents 0ea32a748453
children
comparison
equal deleted inserted replaced
157:f17252543cbf 158:734d3f0853bf
1 using System; 1 using System;
2 using AltNetHispano.Agendas.Configurations;
2 using Google.GData.Calendar; 3 using Google.GData.Calendar;
3 using Google.GData.Extensions; 4 using Google.GData.Extensions;
4 5
5 namespace AltNetHispano.Agendas.Google 6 namespace AltNetHispano.Agendas.Google
6 { 7 {
7 public class GCalendarAdapter : IGCalendarAdapter 8 public class GCalendarAdapter : IGCalendarAdapter
8 { 9 {
9 private readonly CalendarService _service; 10 private readonly CalendarService _service;
10 private readonly Uri _feedUri; 11 private readonly Uri _feedUri;
11 12
12 public bool CreateEvent(IGEventDetail gEventDetail, out string message) 13 public bool CreateEvent(IGEventDetail gEventDetail, out string message)
13 { 14 {
14 try 15 try
15 { 16 {
16 var entry = new EventEntry 17 var entry = new EventEntry
17 { 18 {
18 Title = { Text = gEventDetail.Title }, 19 Title = {Text = gEventDetail.Title},
19 Content = { Content = gEventDetail.Summary } 20 Content = {Content = gEventDetail.Summary}
20 }; 21 };
21 22
22 var eventLocation = new Where 23 var eventLocation = new Where
23 { 24 {
24 ValueString = gEventDetail.Location 25 ValueString = gEventDetail.Location
25 }; 26 };
26 27
27 entry.Locations.Add(eventLocation); 28 entry.Locations.Add(eventLocation);
28 29
29 var eventTime = new When(gEventDetail.StartEvent, gEventDetail.EndEvent); 30 var eventTime = new When(gEventDetail.StartEvent, gEventDetail.EndEvent);
30 entry.Times.Add(eventTime); 31 entry.Times.Add(eventTime);
31 32
32 _service.Insert(_feedUri, entry); 33 _service.Insert(_feedUri, entry);
33 message = "Event create successful"; 34 message = "Event create successful";
34 return true; 35 return true;
35 } 36 }
36 catch (Exception exception) 37 catch (Exception exception)
37 { 38 {
38 message = exception.Message; 39 message = exception.Message;
39 return false; 40 return false;
40 } 41 }
41 } 42 }
42 43
43 public bool DeleteEvent(DateTime startEvent, DateTime endEvent, out string message) 44 public bool DeleteEvent(DateTime startEvent, DateTime endEvent, out string message)
44 { 45 {
45 try 46 try
46 { 47 {
47 var myQuery = new EventQuery 48 var myQuery = new EventQuery
48 { 49 {
49 StartTime = startEvent, 50 StartTime = startEvent,
50 EndTime = endEvent, 51 EndTime = endEvent,
51 Uri = _feedUri 52 Uri = _feedUri
52 }; 53 };
53 54
54 var myResultsFeed = _service.Query(myQuery); 55 var myResultsFeed = _service.Query(myQuery);
55 if (myResultsFeed.Entries.Count > 0) 56 if (myResultsFeed.Entries.Count > 0)
56 { 57 {
57 myResultsFeed.Entries[0].Delete(); 58 myResultsFeed.Entries[0].Delete();
58 message = "Event delete successful"; 59 message = "Event delete successful";
59 return true; 60 return true;
60 } 61 }
61 62
62 message = "Event not found"; 63 message = "Event not found";
63 return false; 64 return false;
64 } 65 }
65 catch (Exception exception) 66 catch (Exception exception)
66 { 67 {
67 message = exception.Message; 68 message = exception.Message;
68 return false; 69 return false;
69 } 70 }
70 } 71 }
71 72
72 public GCalendarAdapter(string applicationName ,string userName, string password, string calendarId) 73 public GCalendarAdapter(string applicationName) : this(applicationName,
73 { 74 AgendasConfigurationManager.Publicadores.Google.Calendar.
74 _service = new CalendarService(applicationName); 75 UserName,
75 _service.setUserCredentials(userName, password); 76 AgendasConfigurationManager.Publicadores.Google.Calendar.
76 _feedUri = new Uri("https://www.google.com/calendar/feeds/" + calendarId + "/private/full"); 77 Password,
77 } 78 AgendasConfigurationManager.Publicadores.Google.Calendar.
78 } 79 CalendarId)
80 {
81 }
82
83 public GCalendarAdapter(string applicationName, string userName, string password, string calendarId)
84 {
85 _service = new CalendarService(applicationName);
86 _service.setUserCredentials(userName, password);
87 _feedUri = new Uri("https://www.google.com/calendar/feeds/" + calendarId + "/private/full");
88 }
89 }
79 } 90 }