public static List<CalendarEvent> GetCalendarEvents(Calendar calendar)
        {
            List<CalendarEvent> eventList = new List<CalendarEvent>();

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("GoogleCalendarReminder");
            service.SetAuthenticationToken(GetAuthToken());

            //service.setUserCredentials(Account.Default.Username
            //                            , SecureStringUtility.SecureStringToString(Account.Default.Password));

            query.Uri = new Uri(calendar.CalendarUri);
            query.SingleEvents = true;
            query.StartTime = DateTime.Now;
            query.EndTime = DateTime.Today.AddDays(Settings.Default.DayRange);

            EventFeed calFeed;
            try
            {
                calFeed = service.Query(query) as EventFeed;
            }
            catch (Exception)
            {
                return null;
            }

            // now populate the calendar
            while (calFeed != null && calFeed.Entries.Count > 0)
            {
                foreach (EventEntry entry in calFeed.Entries)
                {
                    eventList.Add(new CalendarEvent(entry)
                                        {
                                            Color = calendar.Color
                                        });
                }

                // just query the same query again.
                if (calFeed.NextChunk != null)
                {
                    query.Uri = new Uri(calFeed.NextChunk);

                    try
                    {
                        calFeed = service.Query(query) as EventFeed;
                    }
                    catch (Exception ex)
                    {
                        return null;
                    }
                }
                else
                {
                    calFeed = null;
                }
            }

            return eventList;
        }
        // end of accessor public TimeZone TimeZone


        //////////////////////////////////////////////////////////////////////
        /// <summary>searches through the evententries to
        /// find the original event</summary>
        /// <param name="original">The original event to find</param>
        /// <returns> </returns>
        //////////////////////////////////////////////////////////////////////
        public EventEntry FindEvent(OriginalEvent original)
        {
            // first try the internal cache

            foreach (EventEntry entry  in this.Entries)
            {
                if (entry.SelfUri.ToString() == original.Href)
                {
                    return(entry);
                }
            }

            // did not find it in the cache. Need to call the server to get it.
            CalendarService calService = this.Service as CalendarService;

            if (calService != null)
            {
                EventQuery query   = new EventQuery(original.Href);
                EventFeed  newFeed = (EventFeed)calService.Query(query);

                if (newFeed != null && newFeed.Entries != null)
                {
                    Tracing.Assert(newFeed.Entries.Count == 1, "There should be just one entry returned");
                    return(newFeed.Entries[0] as EventEntry);
                }
            }
            return(null);
        }
 public bool Delete(Task task)
 {
     ErrorMessage = String.Empty;
     CalendarService service = new CalendarService("googleCalendar");
     service.setUserCredentials(task.AccountInfo.Username, task.AccountInfo.Password);
     Log.InfoFormat("Fetching google account : [{0}]", task.AccountInfo.ToString());
     string queryUri = String.Format(CultureInfo.InvariantCulture,
                                     "http://www.google.com/calendar/feeds/{0}/private/full",
                                     service.Credentials.Username);
     Log.DebugFormat("Query='{0}'", queryUri);
     EventQuery eventQuery = new EventQuery(queryUri);
     try
     {
         EventFeed eventFeed = service.Query(eventQuery);
         foreach (EventEntry eventEntry in eventFeed.Entries.Cast<EventEntry>())
         {
             if (eventEntry.Times.Count > 0)
             {
                 if (eventEntry.EventId == task.Id)
                 {
                     Log.InfoFormat("Deleting : [{0}]-[{1}]", eventEntry.EventId, eventEntry.Title);
                     eventEntry.Delete();
                     return true;
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Log.ErrorFormat(exception.Message);
         Log.ErrorFormat(exception.ToString());
         ErrorMessage = exception.Message;
     }
     return false;
 }
示例#4
0
        /// <summary>
        /// Prints the titles of all events on the specified calendar.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        static void PrintAllEvents(CalendarService service)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("All events on your calendar:");
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
示例#5
0
文件: Program.cs 项目: Zelxin/RPiKeg
        static void Main(string[] args)
        {
            try
            {
                // create an OAuth factory to use
                GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
                requestFactory.ConsumerKey = "CONSUMER_KEY";
                requestFactory.ConsumerSecret = "CONSUMER_SECRET";

                // example of performing a query (use OAuthUri or query.OAuthRequestorId)
                Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "USER", "DOMAIN");
                // can use plain Uri if setting OAuthRequestorId in the query
                // Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");

                CalendarQuery query = new CalendarQuery();
                query.Uri = calendarUri;
                query.OAuthRequestorId = "USER@DOMAIN"; // can do this instead of using OAuthUri for queries

                CalendarService service = new CalendarService("MyApp");
                service.RequestFactory = requestFactory;
                service.Query(query);
                Console.WriteLine("Query Success!");

                // example with insert (must use OAuthUri)
                Uri contactsUri = new OAuthUri("http://www.google.com/m8/feeds/contacts/default/full", "USER", "DOMAIN");

                ContactEntry entry = new ContactEntry();
                EMail primaryEmail = new EMail("*****@*****.**");
                primaryEmail.Primary = true;
                primaryEmail.Rel = ContactsRelationships.IsHome;
                entry.Emails.Add(primaryEmail);

                ContactsService contactsService = new ContactsService("MyApp");
                contactsService.RequestFactory = requestFactory;
                contactsService.Insert(contactsUri, entry); // this could throw if contact exists

                Console.WriteLine("Insert Success!");

                // to perform a batch use
                // service.Batch(batchFeed, new OAuthUri(atomFeed.Batch, userName, domain));

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fail!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ReadKey();
            }
        }
示例#6
0
        /// <summary>
        /// Prints the titles of all events matching a full-text query.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="queryString">The text for which to query.</param>
        static void FullTextQuery(CalendarService service, String queryString)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            myQuery.Query = queryString;

            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("Events matching \"{0}\":", queryString);
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
示例#7
0
        /// <summary>
        /// Prints a list of the user's calendars.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        static void PrintUserCalendars(CalendarService service)
        {
            FeedQuery query = new FeedQuery();
            query.Uri = new Uri("http://www.google.com/calendar/feeds/default");

            // Tell the service to query:
            AtomFeed calFeed = service.Query(query);

            Console.WriteLine("Your calendars:");
            Console.WriteLine();
            for (int i = 0; i < calFeed.Entries.Count; i++)
            {
                Console.WriteLine(calFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
示例#8
0
        private void deleteCalendar(CalendarService service,string calendarTitle)
        {
            //assume title is non-empty for now
            CalendarQuery query = new CalendarQuery();
            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)service.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (entry.Title.Text == calendarTitle)
                {
                    try
                    {
                        entry.Delete();
                    }
                    catch (GDataRequestException)
                    {
                        MessageBox.Show("Unable to delete primary calendar.\n");
                    }
                }
            }
        }
        public EventDto[] GetItems()
        {
            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("Virtual ALT.NET calendar");

            query.Uri = new Uri(@"http://www.google.com/calendar/feeds/[email protected]/public/full");
            query.StartTime = DateTime.Now;
            query.EndTime = DateTime.Now.AddMonths(3);
            query.SingleEvents = true;
            query.ExtraParameters = "orderby=starttime&sortorder=ascending";

            try
            {
                EventFeed calFeed = service.Query(query);

                return this.GetEventDtos(calFeed.Entries.OfType<EventEntry>());
            }
            catch (Exception)
            {
                return new EventDto[0];
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length < 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];
            string userName = args[1];
            string passWord = args[2];

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query);

            EventEntry insertedEntry = InsertEvent(calFeed, "Conference www2006",
                "Frank Mantek", DateTime.Now, 
                                DateTime.Now.AddDays(1), 
                                true,
                                "Edinburgh");

            if (insertedEntry != null) 
            {
                DumpEventEntry(insertedEntry);
            }
        }
示例#11
0
文件: main.cs 项目: mintwans/cpsc483
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length != 1 && args.Length != 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];

            string userName = args.Length == 3 ? args[1] : null;
            string passWord = args.Length == 3 ? args[2] : null;

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query) as EventFeed;

            Console.WriteLine("");
            Console.WriteLine("Query Feed Test " + query.Uri);

            Console.WriteLine("Post URI is:  " + calFeed.Post); 

            foreach (EventEntry feedEntry in calFeed.Entries)
            {
                DumpEventEntry(feedEntry);
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length < 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];
            string userName = args[1];
            string passWord = args[2];

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query) as EventFeed;

 			foreach (EventEntry entry in calFeed.Entries)
            {
            	if (entry.Title.Text == "Conference www2006") 
            	{
                	entry.Content.Content = "The conference was fun... ";
                	entry.Update();
                	Console.WriteLine("Updated the Conference entry"); 
                }
            }
        }
示例#13
0
        /////////////////////////////////////////////////////////////////////////////

   
       //////////////////////////////////////////////////////////////////////
        /// <summary>Tests the reminder method property</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarReminderMethodTest()
        {
            Tracing.TraceMsg("Entering CalendarReminderMethodTest");

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

        
            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);
                EventFeed calFeed = service.Query(query) as EventFeed;
                
                String strTitle = "Dinner & time" + Guid.NewGuid().ToString(); 

                if (calFeed != null)
                {
                    // get the first entry
                    EventEntry entry  = ObjectModelHelper.CreateEventEntry(1); 
                    entry.Title.Text = strTitle;

                    entry.Reminders.Clear();
                    
                    Reminder r1 = new Reminder();
                    r1.Method = Reminder.ReminderMethod.email;
                    r1.Minutes = 30;
                    Reminder r2 = new Reminder();
                    r2.Method = Reminder.ReminderMethod.alert;
                    r2.Minutes = 60;

                    entry.Reminders.Add(r1);
                    entry.Reminders.Add(r2);

                    EventEntry newEntry = (EventEntry) calFeed.Insert(entry); 

                    Assert.AreEqual(2, newEntry.Reminders.Count,  "There should be two reminders");

                    Reminder r3 = newEntry.Reminders[0] as Reminder;
                    Reminder r4 = newEntry.Reminders[1] as Reminder;

                    Reminder r1a;
                    Reminder r2a;
                    if (r3.Method == Reminder.ReminderMethod.email)
                    {
                        r1a = r3;
                        r2a = r4;
                    }
                    else 
                    {
                        r1a = r4;
                        r2a = r3;
                    }
                
                    Assert.AreEqual(r1.Minutes, r1a.Minutes, "Reminder time should be identical"); 
                    Assert.AreEqual(r1.Method,  r1a.Method, "Reminder method should be identical"); 
                    Assert.AreEqual(r2.Minutes, r2a.Minutes, "Reminder time should be identical"); 
                    Assert.AreEqual(r2.Method,  r2a.Method, "Reminder method should be identical"); 
                    Tracing.TraceMsg("Created calendar entry");
                }

                service.Credentials = null; 

            }
        }
示例#14
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a test of batch support on the events feed</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarBatchTest()
        {
            Tracing.TraceMsg("Entering CalendarBatchTest");

            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                EventQuery query = new EventQuery(this.defaultCalendarUri);

                EventFeed feed = service.Query(query);
                AtomFeed batchFeed = new AtomFeed(feed);

                string newEntry1Title = "new event" + Guid.NewGuid().ToString();
                EventEntry newEntry1 = new EventEntry(newEntry1Title);
                newEntry1.BatchData = new GDataBatchEntryData("1", GDataBatchOperationType.insert);
                batchFeed.Entries.Add(newEntry1);

                string newEntry2Title = "new event" + Guid.NewGuid().ToString();
                EventEntry newEntry2 = new EventEntry(newEntry2Title);
                newEntry2.BatchData = new GDataBatchEntryData("2", GDataBatchOperationType.insert);
                batchFeed.Entries.Add(newEntry2);

                string newEntry3Title = "new event" + Guid.NewGuid().ToString();
                EventEntry newEntry3 = new EventEntry(newEntry3Title);
                newEntry3.BatchData = new GDataBatchEntryData("3", GDataBatchOperationType.insert);
                batchFeed.Entries.Add(newEntry3);

                Tracing.TraceMsg("Creating batch items");

                EventFeed batchResultFeed = (EventFeed)service.Batch(batchFeed, new Uri(feed.Batch));

                foreach (EventEntry evt in batchResultFeed.Entries)
                {
                    Assert.IsNotNull(evt.BatchData, "Result should contain batch information.");
                    Assert.IsNotNull(evt.BatchData.Id, "Result should have a Batch ID.");
                    Assert.AreEqual(201, evt.BatchData.Status.Code, "Created entries should return 201");
 
                    switch (evt.BatchData.Id)
                    {
                        case "1":
                            Assert.AreEqual(newEntry1Title, evt.Title.Text, "titles should be equal.");
                            break;
                        case "2":
                            Assert.AreEqual(newEntry2Title, evt.Title.Text, "titles should be equal.");
                            break;
                        case "3":
                            Assert.AreEqual(newEntry3Title, evt.Title.Text, "titles should be equal.");
                            break;
                        default:
                            Assert.Fail("Unrecognized entry in result of batch insert feed");
                            break;
                    }

                }

                Tracing.TraceMsg("Updating created entries.");

                batchFeed = new AtomFeed(feed);
                foreach (EventEntry evt in batchResultFeed.Entries)
                {
                    evt.BatchData = new GDataBatchEntryData(evt.BatchData.Id, GDataBatchOperationType.update);
                    evt.Title.Text = evt.Title.Text + "update";
                    batchFeed.Entries.Add(evt);
                }

                batchResultFeed = (EventFeed) service.Batch(batchFeed, new Uri(feed.Batch));

                foreach (EventEntry evt in batchResultFeed.Entries)
                {
                    Assert.IsNotNull(evt.BatchData, "Result should contain batch information.");
                    Assert.IsNotNull(evt.BatchData.Id, "Result should have a Batch ID.");
                    Assert.AreEqual(200, evt.BatchData.Status.Code, "Updated entries should return 200");

                    switch (evt.BatchData.Id)
                    {
                        case "1":
                            Assert.AreEqual(newEntry1Title + "update", evt.Title.Text, "titles should be equal.");
                            break;
                        case "2":
                            Assert.AreEqual(newEntry2Title + "update", evt.Title.Text, "titles should be equal.");
                            break;
                        case "3":
                            Assert.AreEqual(newEntry3Title + "update", evt.Title.Text, "titles should be equal.");
                            break;
                        default:
                            Assert.Fail("Unrecognized entry in result of batch update feed");
                            break;
                    }

                }



                Tracing.TraceMsg("Deleting created entries.");

                batchFeed = new AtomFeed(feed);
                foreach (EventEntry evt in batchResultFeed.Entries)
                {
                    evt.BatchData = new GDataBatchEntryData(GDataBatchOperationType.delete);
                    evt.Id = new AtomId(evt.EditUri.ToString());
                    batchFeed.Entries.Add(evt);
                }

                batchResultFeed = (EventFeed)service.Batch(batchFeed, new Uri(feed.Batch));

                foreach (EventEntry evt in batchResultFeed.Entries)
                {
                    Assert.AreEqual(200, evt.BatchData.Status.Code, "Deleted entries should return 200");
                }

                service.Credentials = null;
            }
        }
示例#15
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarQuickAddTest()
        {
            Tracing.TraceMsg("Entering CalendarQuickAddTest");

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);
                EventFeed calFeed = service.Query(query) as EventFeed;

                if (calFeed != null)
                {
                    // get the first entry
                    EventEntry entry  = new EventEntry();
                    entry.Content.Content = "Dinner with Sabine, Oct 1st, 10pm";
                    entry.Content.Type = "html";
                    entry.QuickAdd = true;


                    EventEntry newEntry = (EventEntry) calFeed.Insert(entry); 

                    Assert.IsTrue(newEntry.Title.Text.StartsWith("Dinner with Sabine"), "both titles should be identical" + newEntry.Title.Text); 

                }
                service.Credentials = null; 
            }
        }
示例#16
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarExtensionTest()
        {
            Tracing.TraceMsg("Entering CalendarExtensionTest");

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            int iCount; 

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);
                EventFeed calFeed = service.Query(query) as EventFeed;

                if (calFeed.TimeZone != null)
                {
                    Tracing.TraceMsg(calFeed.TimeZone.Value); 
                }

                iCount = calFeed.Entries.Count; 

               String strTitle = "Dinner & time" + Guid.NewGuid().ToString(); 

                if (calFeed != null)
                {
                    // get the first entry
                    EventEntry entry  = ObjectModelHelper.CreateEventEntry(1); 
                    entry.Title.Text = strTitle;

                    EventEntry newEntry = (EventEntry) calFeed.Insert(entry); 

                    iCount++; 
                    Tracing.TraceMsg("Created calendar entry");

                    Reminder rNew = null;
                    Reminder rOld = null;
                    if (newEntry.Reminders.Count > 0)
                    {
                        rNew = newEntry.Reminders[0] as Reminder;
                    }
                    if (entry.Reminders.Count > 0)
                    {
                        rOld = entry.Reminders[0] as Reminder;
                    }

                    Assert.IsTrue(rNew != null, "Reminder should not be NULL);");
                    Assert.IsTrue(rOld != null, "Original Reminder should not be NULL);");
                    Assert.AreEqual(rNew.Minutes, rOld.Minutes, "Reminder time should be identical"); 

                    Where wOldOne, wOldTwo;
                    Where wNewOne;

                    Assert.IsTrue(entry.Locations.Count == 2, "entry should have 2 locations");
                    // calendar ignores sending more than one location
                    Assert.IsTrue(newEntry.Locations.Count == 1, "new entry should have 1 location");


                    if (entry.Locations.Count > 1)
                    {
                        wOldOne = entry.Locations[0];
                        wOldTwo = entry.Locations[1];
                    
                        if (newEntry.Locations.Count == 1)
                        {
                            wNewOne = newEntry.Locations[0];
                            Assert.IsTrue(wOldOne != null, "Where oldOne should not be NULL);");
                            Assert.IsTrue(wOldTwo != null, "Where oldTwo should not be NULL);");
                            Assert.IsTrue(wNewOne != null, "Where newOne should not be NULL);");
                            Assert.IsTrue(wOldOne.ValueString == wNewOne.ValueString, "location one should be identical");
                        }
                    }

                    newEntry.Content.Content = "Updated..";
                    newEntry.Update();

                    // try to get just that guy.....
                    FeedQuery singleQuery = new FeedQuery();
                    singleQuery.Uri = new Uri(newEntry.SelfUri.ToString()); 

                    EventFeed newFeed = service.Query(query) as EventFeed;
                    EventEntry sameGuy = newFeed.Entries[0] as EventEntry; 

                    sameGuy.Content.Content = "Updated again..."; 
                    When x = sameGuy.Times[0]; 
                    sameGuy.Times.Clear();
                    x.StartTime = DateTime.Now; 
                    sameGuy.Times.Add(x); 
                    sameGuy.Update();

                    Assert.IsTrue(sameGuy.Title.Text.Equals(newEntry.Title.Text), "both titles should be identical"); 

                }

                calFeed = service.Query(query) as EventFeed;

                Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have one more entry, it has: " + calFeed.Entries.Count); 

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (EventEntry entry in calFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            Assert.AreEqual(ObjectModelHelper.DEFAULT_REMINDER_TIME, entry.Reminder.Minutes, "Reminder time should be identical"); 
                            entry.Content.Content = "Maybe stay until breakfast";
                            entry.Update();
                            Tracing.TraceMsg("Updated entry");
                        }
                    }
                }

                calFeed = service.Query(query) as EventFeed;

                Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have one more entry, it has: " + calFeed.Entries.Count); 

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in calFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            entry.Delete();
                            iCount--; 
                            Tracing.TraceMsg("deleted entry");
                        }
                    }
                }

                calFeed = service.Query(query) as EventFeed;
                Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have the same count again, it has: " + calFeed.Entries.Count); 

                service.Credentials = null; 
            }

        }
示例#17
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>tests the original event </summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarOriginalEventTest()
        {
            Tracing.TraceMsg("Entering CalendarOriginalEventTest");

            FeedQuery query = new FeedQuery();

            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory) this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);

                EventFeed calFeed = service.Query(query) as EventFeed;

                string recur  = 
                    "DTSTART;TZID=America/Los_Angeles:20060314T060000\n" +
                    "DURATION:PT3600S\n" + 
                    "RRULE:FREQ=DAILY;UNTIL=20060321T220000Z\n" +
                    "BEGIN:VTIMEZONE\n" + 
                    "TZID:America/Los_Angeles\n" +
                    "X-LIC-LOCATION:America/Los_Angeles\n" +
                    "BEGIN:STANDARD\n" +
                    "TZOFFSETFROM:-0700\n" +
                    "TZOFFSETTO:-0800\n" +
                    "TZNAME:PST\n" +
                    "DTSTART:19671029T020000\n" +
                    "RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\n" +
                    "END:STANDARD\n" +
                    "BEGIN:DAYLIGHT\n" +
                    "TZOFFSETFROM:-0800\n" +
                    "TZOFFSETTO:-0700\n" +
                    "TZNAME:PDT\n" +
                    "DTSTART:19870405T020000\n" +
                    "RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU\n" +
                    "END:DAYLIGHT\n" +
                    "END:VTIMEZONE\n"; 

                EventEntry entry  =  ObjectModelHelper.CreateEventEntry(1); 
                entry.Title.Text = "New recurring event" + Guid.NewGuid().ToString();  

                // get rid of the when entry
                entry.Times.Clear(); 

                entry.Recurrence = new Recurrence();
                entry.Recurrence.Value = recur; 

                EventEntry recEntry = calFeed.Insert(entry) as EventEntry;

                entry = ObjectModelHelper.CreateEventEntry(1); 
                entry.Title.Text = "whateverfancy"; 

                OriginalEvent originalEvent = new OriginalEvent();
                When start = new When();
                start.StartTime = new DateTime(2006, 03, 14, 15, 0,0); 
                originalEvent.OriginalStartTime = start;
                originalEvent.Href = recEntry.SelfUri.ToString();
                originalEvent.IdOriginal = recEntry.EventId;
                entry.OriginalEvent = originalEvent;
                entry.Times.Add(new When(new DateTime(2006, 03, 14, 9,0,0),
                                         new DateTime(2006, 03, 14, 10,0,0)));
                calFeed.Insert(entry);

                service.Credentials = null; 
                factory.MethodOverride = false;
            }
        }
示例#18
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>tests that a default reminder get's created if none is set</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarDefaultReminderTest()
        {
            Tracing.TraceMsg("Entering CalendarDefaultReminderTest");

            FeedQuery query = new FeedQuery();

            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory) this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);

                EventFeed calFeed = service.Query(query) as EventFeed;

                EventEntry entry  =  ObjectModelHelper.CreateEventEntry(1); 
                entry.Title.Text = "New event with default reminder" + Guid.NewGuid().ToString();  

                entry.Reminder = new Reminder();
                entry.Reminder.Method = Reminder.ReminderMethod.unspecified;

                EventEntry newEntry = calFeed.Insert(entry) as EventEntry;
                Reminder reminder = newEntry.Reminder;
                Assert.IsTrue(reminder != null, "reminder should not be null - this only works if the calendar HAS default remidners set"); 
                Assert.IsTrue(reminder.Method != Reminder.ReminderMethod.unspecified, "reminder should not be unspecified - this only works if the calendar HAS default remidners set"); 

                service.Credentials = null; 
                factory.MethodOverride = false;
            }
        }
示例#19
0
        /////////////////////////////////////////////////////////////////////////////

        
        //////////////////////////////////////////////////////////////////////
        /// <summary>tests the extended property against the calendar</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarExtendedPropertyTest()
        {
            Tracing.TraceMsg("Entering CalendarExtendedPropertyTest");

            FeedQuery query = new FeedQuery();

            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);

                EventFeed calFeed = service.Query(query) as EventFeed;

                string guid = Guid.NewGuid().ToString(); 

                ExtendedProperty prop; 
                EventEntry entry;

                if (calFeed != null)
                {
                    entry = ObjectModelHelper.CreateEventEntry(1); 
                    entry.Title.Text = guid; 

                    prop = new ExtendedProperty(); 
                    prop.Name = "http://frank.schemas/2005#prop"; 
                    prop.Value = "Mantek"; 

                    entry.ExtensionElements.Add(prop); 

                    calFeed.Insert(entry); 
                }

                calFeed = service.Query(query) as EventFeed;
                prop = null;
                entry = null;

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    entry = calFeed.Entries[0] as EventEntry;

                    Assert.AreEqual(entry.Title.Text, guid, "Expected the same entry");

                    foreach (Object o in entry.ExtensionElements )
                    {
                        ExtendedProperty p = o as ExtendedProperty; 
                        if (p != null)
                        {
                            Tracing.TraceMsg("Found one extended property"); 
                            Assert.AreEqual(p.Name, "http://frank.schemas/2005#prop", "Expected the same entry");
                            Assert.AreEqual(p.Value, "Mantek", "Expected the same entry");
                            prop = p; 
                        }
                    }
                }

                Assert.IsTrue(prop != null, "prop should not be null"); 

                // now delete the prop again
                // BUGBUG: currently you can not delete extended properties in the calendar
                /*
                if (entry != null)
                {
                    entry.ExtensionElements.Remove(prop);
                    prop = null;
                    EventEntry newEntry = entry.Update() as EventEntry; 
                    foreach (Object o in newEntry.ExtensionElements )
                    {
                        ExtendedProperty p = o as ExtendedProperty; 
                        if (p != null)
                        {
                            Tracing.TraceMsg("Found one extended property"); 
                            prop = p; 
                            break;
                        }
                    }
                    Assert.IsTrue(prop == null, "prop should be gone now");
                }
                */
                // get rid of the entry
                if (entry != null)
                    entry.Delete();
                
                service.Credentials = null; 

            }
        }
        protected override void ProcessRecord()
        {
            Log.Debug("Get-OSAGCalendar - ProcessRecord - Started");

            CalendarService service = new CalendarService("OSA");
            service.setUserCredentials(Username, Password);

            EventQuery query = new EventQuery();
            query.Uri = new Uri("http://www.google.com/calendar/feeds/" + Username + "/private/full");

            if (FromDate != DateTime.MinValue) query.StartTime = fromDate;

            query.RecurrenceStart = DateTime.Now;

            if (ToDate != DateTime.MinValue) query.EndTime = ToDate;

            if (FutureEvents)
            {
                Log.Debug("Only looking for future events");
                query.FutureEvents = true;
            }
            else
                query.FutureEvents = false;

            query.SortOrder = CalendarSortOrder.ascending;
            query.ExtraParameters = "orderby=starttime";

            // Tell the service to query:
            EventFeed calFeed = service.Query(query);

            List<CalendarEvent> events = new List<CalendarEvent>();

            foreach (var entry in calFeed.Entries)
            {
               Log.Debug("Found Entry: " + entry.ToString());
               EventEntry eventEntry = entry as Google.GData.Calendar.EventEntry;
               if (eventEntry != null)
               {
                   if (!eventEntry.Status.Value.Contains("event.canceled"))
                   {
                       Log.Debug("Entry is an EventEntry");
                       CalendarEvent c = new CalendarEvent();
                       c.Title = eventEntry.Title.Text;
                       c.Content = eventEntry.Content.Content;

                       if (eventEntry.Times.Count > 0)
                       {
                           c.Start = eventEntry.Times[0].StartTime;
                           c.End = eventEntry.Times[0].EndTime;
                       }

                       events.Add(c);
                   }
                }
            }
            WriteObject(events);
        }
        /// <summary>
        /// Prints the titles of all events in a specified date/time range.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="startTime">Start time (inclusive) of events to print.</param>
        /// <param name="endTime">End time (exclusive) of events to print.</param>
        static void DateRangeQuery(CalendarService service, DateTime startTime, DateTime endTime)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            myQuery.StartTime = startTime;
            myQuery.EndTime = endTime;

            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("Matching events from {0} to {1}:",
                              startTime.ToShortDateString(),
                              endTime.ToShortDateString());
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
示例#22
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an CalendarWebContentTest test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarWebContentTest()
        {
            Tracing.TraceMsg("Entering CalendarWebContentTest");

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);
                EventFeed calFeed = service.Query(query) as EventFeed;

                if (calFeed.TimeZone != null)
                {
                    Tracing.TraceMsg(calFeed.TimeZone.Value); 
                }

                String strTitle = "Dinner & time" + Guid.NewGuid().ToString(); 

                if (calFeed != null)
                {
                    // get the first entry
                    EventEntry entry  = ObjectModelHelper.CreateEventEntry(1); 
                    entry.Title.Text = strTitle;

                    WebContentLink wc = new WebContentLink();
                    wc.Type = "image/gif";
                    wc.Url = "http://www.google.com/logos/july4th06.gif";
                    wc.Icon = "http://www.google.com/calendar/images/google-holiday.gif";
                    wc.Title = "Test content"; 
                    wc.Width = 270;
                    wc.Height = 130; 
                    wc.GadgetPreferences.Add("color", "blue");
                    wc.GadgetPreferences.Add("taste", "sweet");
                    wc.GadgetPreferences.Add("smell", "fresh");

                    entry.WebContentLink = wc;

                    EventEntry newEntry = (EventEntry) calFeed.Insert(entry); 

                    // check if the web content link came back
                    Assert.IsTrue(newEntry.WebContentLink != null, "the WebContentLink did not come back for the webContent"); 
                    Tracing.TraceMsg("Created calendar entry");

                    Assert.IsTrue(newEntry.WebContentLink.WebContent != null, "The returned WebContent element was not found");

                    Assert.AreEqual(3, newEntry.WebContentLink.GadgetPreferences.Count, "The gadget preferences should be there");
                    Assert.AreEqual("blue", newEntry.WebContentLink.GadgetPreferences["color"], "Color should be blue");
                    Assert.AreEqual("sweet", newEntry.WebContentLink.GadgetPreferences["taste"], "Taste should be sweet");
                    Assert.AreEqual("fresh", newEntry.WebContentLink.GadgetPreferences["smell"], "smell should be fresh");


                    newEntry.Content.Content = "Updated..";
                    newEntry.Update();


                    // try to get just that guy.....
                    FeedQuery singleQuery = new FeedQuery();
                    singleQuery.Uri = new Uri(newEntry.SelfUri.ToString()); 

                    EventFeed newFeed = service.Query(query) as EventFeed;

                    EventEntry sameGuy = newFeed.Entries[0] as EventEntry; 

                    sameGuy.Content.Content = "Updated again..."; 
                    When x = sameGuy.Times[0]; 
                    sameGuy.Times.Clear();
                    x.StartTime = DateTime.Now; 
                    sameGuy.Times.Add(x); 
                    sameGuy.Update();


                    Assert.IsTrue(sameGuy.Title.Text.Equals(newEntry.Title.Text), "both titles should be identical"); 

                }

                calFeed = service.Query(query) as EventFeed;


                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (EventEntry entry in calFeed.Entries)
                    {
                        Tracing.TraceMsg("Entry title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            Assert.AreEqual(ObjectModelHelper.DEFAULT_REMINDER_TIME, entry.Reminder.Minutes, "Reminder time should be identical"); 
                            // check if the link came back
                            // check if the web content link came back
                            Assert.IsTrue(entry.WebContentLink != null, "the WebContentLink did not come back for the webContent"); 

                        }
                    }
                }

                calFeed = service.Query(query) as EventFeed;

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (EventEntry entry in calFeed.Entries)
                    {
                        Tracing.TraceMsg("Entry title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            entry.Delete();
                            Tracing.TraceMsg("deleted entry");
                        }
                    }
                }

                service.Credentials = null; 
            }

        }
示例#23
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>Tests the ACL extensions</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarACLTest()
        {
            Tracing.TraceMsg("Entering CalendarACLTest");

            AclQuery query = new AclQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            int iCount; 

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.aclFeedUri);
                AclFeed aclFeed = service.Query(query);
                AclEntry newEntry = null;

                foreach (AclEntry e in aclFeed.Entries ) 
                {
                    if (e.Scope.Value.StartsWith(this.userName) == false)
                    {
                        e.Delete();
                    }
                }
                aclFeed = service.Query(query);

                iCount = aclFeed.Entries.Count;

                if (aclFeed != null)
                {
                    // create an entry
                    AclEntry entry = new AclEntry();
                    entry.Role = AclRole.ACL_CALENDAR_FREEBUSY;
                    AclScope scope = new AclScope();
                    scope.Type = AclScope.SCOPE_USER;
                    scope.Value = "*****@*****.**";
                    entry.Scope = scope;

                    newEntry = (AclEntry) aclFeed.Insert(entry);

                    Assert.AreEqual(newEntry.Role.Value, entry.Role.Value);
                    Assert.AreEqual(newEntry.Scope.Type, entry.Scope.Type);
                    Assert.AreEqual(newEntry.Scope.Value, entry.Scope.Value);
                }

                Tracing.TraceMsg("CalendarACLTest: done insering Acl:entry");


                iCount++;
                aclFeed = (AclFeed) service.Query(query);

                Tracing.TraceMsg("CalendarACLTest: done query after: Acl:entry");

                // update that entry

                if (newEntry != null)
                {
                    newEntry.Role = AclRole.ACL_CALENDAR_READ;
                    newEntry = (AclEntry) newEntry.Update();
                    Assert.AreEqual(AclRole.ACL_CALENDAR_READ.Value, newEntry.Role.Value);
                }

                Tracing.TraceMsg("CalendarACLTest: done updating Acl:entry");

                newEntry.Delete();
                iCount--;

                Tracing.TraceMsg("CalendarACLTest: done deleting Acl:entry");


                aclFeed = (AclFeed) service.Query(query);
                Assert.AreEqual(iCount, aclFeed.Entries.Count, "Feed should have one more entry, it has: " + aclFeed.Entries.Count); 


                service.Credentials = null; 
            }
        }
示例#24
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>Tests the ACL extensions, this time getting the feed from the entry</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarACL2Test()
        {
            Tracing.TraceMsg("Entering CalendarACL2Test");

            CalendarQuery query = new CalendarQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }


                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.defaultOwnCalendarsUri);
                CalendarFeed calFeed = service.Query(query);

                if (calFeed != null && calFeed.Entries != null && calFeed.Entries[0] != null)
                {
                   AtomLink link = calFeed.Entries[0].Links.FindService(AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, null);
                   AclEntry aclEntry = new AclEntry();

                   aclEntry.Scope = new AclScope();
                   aclEntry.Scope.Type = AclScope.SCOPE_USER;
                   aclEntry.Scope.Value = "*****@*****.**";
                   aclEntry.Role = AclRole.ACL_CALENDAR_READ;

                   Uri aclUri = null;
                   if (link != null)
                   {
                       aclUri = new Uri(link.HRef.ToString());
                   }
                   else
                   {
                       throw new Exception("ACL link was null.");
                   }

                   AclEntry insertedEntry = service.Insert(aclUri, aclEntry); 
                   insertedEntry.Delete();
                }
            }
        }
示例#25
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>test for composite mode</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarCompositeTest()
        {
            Tracing.TraceMsg("Entering CalendarCompositeTest");

            // first run the RecurranceTest to create a recurring event
            this.CalendarRecurranceTest(); 

            // now get the feedService

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCompositeUri); 
                EventFeed calFeed = service.Query(query) as EventFeed;
                Assert.IsTrue(calFeed!=null, "that's wrong, there should be a feed object" + calFeed); 
                service.Credentials = null; 
            }
        }
示例#26
0
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarRecurranceTest()
        {
            Tracing.TraceMsg("Entering CalendarRecurranceTest");

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);
                EventFeed calFeed = service.Query(query) as EventFeed;

                string recur  = 
                    "DTSTART;TZID=America/Los_Angeles:20060314T060000\n" +
                    "DURATION:PT3600S\n" + 
                    "RRULE:FREQ=DAILY;UNTIL=20060321T220000Z\n" +
                    "BEGIN:VTIMEZONE\n" + 
                    "TZID:America/Los_Angeles\n" +
                    "X-LIC-LOCATION:America/Los_Angeles\n" +
                    "BEGIN:STANDARD\n" +
                    "TZOFFSETFROM:-0700\n" +
                    "TZOFFSETTO:-0800\n" +
                    "TZNAME:PST\n" +
                    "DTSTART:19671029T020000\n" +
                    "RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\n" +
                    "END:STANDARD\n" +
                    "BEGIN:DAYLIGHT\n" +
                    "TZOFFSETFROM:-0800\n" +
                    "TZOFFSETTO:-0700\n" +
                    "TZNAME:PDT\n" +
                    "DTSTART:19870405T020000\n" +
                    "RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU\n" +
                    "END:DAYLIGHT\n" +
                    "END:VTIMEZONE\n"; 

                EventEntry entry  =  ObjectModelHelper.CreateEventEntry(1); 
                entry.Title.Text = "New recurring event" + Guid.NewGuid().ToString();  

                // get rid of the when entry
                entry.Times.Clear(); 

                entry.Recurrence = new Recurrence();
                entry.Recurrence.Value = recur; 

                calFeed.Insert(entry); 

                if (calFeed.TimeZone != null)
                {
                    Tracing.TraceMsg(calFeed.TimeZone.Value); 
                }

                // requery
                calFeed = service.Query(query) as EventFeed;


                ObjectModelHelper.DumpAtomObject(calFeed,CreateDumpFileName("CalendarRecurrance")); 

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    // look for all events that have an original Event pointer, and if so, try to find that one
                    foreach (EventEntry e in calFeed.Entries)
                    {
                        Tracing.TraceMsg("Looping Feed entries, title: " + e.Title.Text); 
                        if (e.OriginalEvent != null)
                        {
                            Tracing.TraceMsg("Searching for original Event"); 
                            EventEntry original = calFeed.FindEvent(e.OriginalEvent); 
                            Tracing.TraceMsg("Found original Event: " + original.Title.Text); 
                            Assert.IsTrue(original != null, "can not find original event"); 
                        }
                    }
                }
                service.Credentials = null; 
            }

        }
示例#27
0
        /////////////////////////////////////////////////////////////////////////////


        /// <summary>
        /// Test to check creating/updating/deleting a secondary calendar.
        /// </summary>
        [Test] public void CalendarOwnCalendarsTest()
        {
            Tracing.TraceMsg("Enterting CalendarOwnCalendarsTest");

            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultOwnCalendarsUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                CalendarEntry newCalendar = new CalendarEntry();
                newCalendar.Title.Text = "new calendar" + Guid.NewGuid().ToString();
                newCalendar.Summary.Text = "some unique summary" + Guid.NewGuid().ToString();
                newCalendar.TimeZone = "America/Los_Angeles";
                newCalendar.Hidden = false;
                newCalendar.Selected = true;
                newCalendar.Color = "#2952A3";
                newCalendar.Location = new Where("", "", "Test City");

                Uri postUri = new Uri(this.defaultOwnCalendarsUri);
                CalendarEntry createdCalendar = (CalendarEntry) service.Insert(postUri, newCalendar);

                Assert.IsNotNull(createdCalendar, "created calendar should be returned.");

                Assert.AreEqual(newCalendar.Title.Text, createdCalendar.Title.Text, "Titles should be equal");
                Assert.AreEqual(newCalendar.Summary.Text, createdCalendar.Summary.Text, "Summaries should be equal");
                Assert.AreEqual(newCalendar.TimeZone, createdCalendar.TimeZone, "Timezone should be equal");
                Assert.AreEqual(newCalendar.Hidden, createdCalendar.Hidden, "Hidden property should be equal");
                Assert.AreEqual(newCalendar.Color, createdCalendar.Color, "Color property should be equal");
                Assert.AreEqual(newCalendar.Location.ValueString, createdCalendar.Location.ValueString, "Where should be equal");

                createdCalendar.Title.Text = "renamed calendar" + Guid.NewGuid().ToString();
                createdCalendar.Hidden = true;
                CalendarEntry updatedCalendar = (CalendarEntry) createdCalendar.Update();

                Assert.AreEqual(createdCalendar.Title.Text, updatedCalendar.Title.Text, "entry should have been updated");

                updatedCalendar.Delete();

                CalendarQuery query = new CalendarQuery();
                query.Uri = postUri;

                CalendarFeed calendarList = service.Query(query);

                foreach (CalendarEntry entry in calendarList.Entries)
                {
                    Assert.IsTrue(entry.Title.Text != updatedCalendar.Title.Text, "Calendar should have been removed");
                }


                service.Credentials = null;
            }

        }
        /// <summary>
        /// Retrieves and prints the access control lists of all
        /// of the authenticated user's calendars.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        static void RetrieveAcls(CalendarService service)
        {
            FeedQuery query = new FeedQuery();
            query.Uri = new Uri("http://www.google.com/calendar/feeds/default");
            AtomFeed calFeed = service.Query(query);

            Console.WriteLine();
            Console.WriteLine("Sharing permissions for your calendars:");

            // Retrieve the meta-feed of all calendars.
            foreach (AtomEntry calendarEntry in calFeed.Entries)
            {
                Console.WriteLine("Calendar: {0}", calendarEntry.Title.Text);
                AtomLink link = calendarEntry.Links.FindService(
                    AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, null);

                // For each calendar, retrieve its ACL feed.
                if (link != null)
                {
                    AclFeed feed = service.Query(new AclQuery(link.HRef.ToString()));
                    foreach (AclEntry aclEntry in feed.Entries)
                    {
                        Console.WriteLine("\tScope: Type={0} ({1})", aclEntry.Scope.Type,
                            aclEntry.Scope.Value);
                        Console.WriteLine("\tRole: {0}", aclEntry.Role.Value);
                    }
                }
            }
        }
示例#29
0
        [Test] public void CalendarCommentTest()
        {
            Tracing.TraceMsg("Entering CalendarCommentTest");

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(this.ApplicationName);

            int iCount; 

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);
                EventFeed calFeed = service.Query(query) as EventFeed;

                iCount = calFeed.Entries.Count; 

                String strTitle = "Comment Test" + Guid.NewGuid().ToString(); 

                if (calFeed != null)
                {
                    // insert a new entry
                    EventEntry entry  = ObjectModelHelper.CreateEventEntry(1); 
                    entry.Title.Text = strTitle;

                    entry.Times[0].AllDay = true; 

                    calFeed.Insert(entry); 
                    iCount++; 
                    Tracing.TraceMsg("Created calendar entry");
                }

                calFeed = service.Query(query) as EventFeed;

                Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have one more entry, it has: " + calFeed.Entries.Count); 

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (EventEntry entry in calFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            // get the comment feed
                            Uri commentFeedUri = new Uri(entry.Comments.FeedLink.Href); 

                            // now we use an AtomFeed to post there
                            Service feedService = new Service("cl", "UnitTests"); 
                            feedService.Credentials = new GDataCredentials(this.userName, this.passWord);
                            query.Uri = commentFeedUri; 

                            AtomFeed commentFeed = feedService.Query(query); 
                            AtomEntry newEntry = ObjectModelHelper.CreateAtomEntry(1); 
                            Tracing.TraceMsg("trying to insert a comment"); 
                            try
                            {
                                commentFeed.Insert(newEntry);
                            } catch (GDataRequestException e )
                            {
                                Console.WriteLine(e.ResponseString); 
                                Tracing.TraceMsg(e.ResponseString); 
                            }
                            
                        }
                    }
                }
                service.Credentials = null; 
            }

        }
示例#30
0
        private void RefreshFeed()
        {
            string calendarURI = this.CalendarURI.Text;
            string userName =    this.UserName.Text;
            string passWord =    this.Password.Text;

            this.entryList = new ArrayList(50);
            ArrayList dates = new ArrayList(50);
            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("CalendarSampleApp");

            if (userName != null && userName.Length > 0)
            {
                service.setUserCredentials(userName, passWord);
            }

            // only get event's for today - 1 month until today + 1 year

            query.Uri = new Uri(calendarURI);

            query.StartTime = DateTime.Now.AddDays(-28);
            query.EndTime = DateTime.Now.AddMonths(6);

            EventFeed calFeed = service.Query(query) as EventFeed;

            // now populate the calendar
            while (calFeed != null && calFeed.Entries.Count > 0)
            {
                // look for the one with dinner time...
                foreach (EventEntry entry in calFeed.Entries)
                {
                    this.entryList.Add(entry);
                    if (entry.Times.Count > 0)
                    {
                        foreach (When w in entry.Times)
                        {
                            dates.Add(w.StartTime);
                        }
                    }
                }
                // just query the same query again.
                if (calFeed.NextChunk != null)
                {
                    query.Uri = new Uri(calFeed.NextChunk);
                    calFeed = service.Query(query) as EventFeed;
                }
                else
                    calFeed = null;
            }

            DateTime[] aDates = new DateTime[dates.Count];

            int i =0;
            foreach (DateTime d in dates)
            {
                aDates[i++] = d;
            }

            this.calendarControl.BoldedDates = aDates;
        }
示例#31
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>tests the sendNotification property against the calendar</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void CalendarNotificationTest()
        {
            Tracing.TraceMsg("Entering CalendarNotificationTest");

            FeedQuery query = new FeedQuery();

            CalendarService service = new CalendarService(this.ApplicationName);

            if (this.defaultCalendarUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory) this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultCalendarUri);

                EventFeed calFeed = service.Query(query) as EventFeed;

                string guid = Guid.NewGuid().ToString(); 

                if (calFeed != null)
                {
                    EventEntry entry = ObjectModelHelper.CreateEventEntry(1); 
                    entry.Title.Text = guid; 
                    entry.Notifications = true; 
                    calFeed.Insert(entry); 
                }

                calFeed = service.Query(query) as EventFeed;

                if (calFeed != null && calFeed.Entries.Count > 0)
                {
                    EventEntry entry = calFeed.Entries[0] as EventEntry;

                    Assert.AreEqual(entry.Title.Text, guid, "Expected the same entry");
                    // Assert.IsTrue(entry.Notifications, "Expected the sendNotify to be true" + entry.Notifications.ToString()); 
                }

                service.Credentials = null; 

                factory.MethodOverride = false;
            }
        }