示例#1
0
 public CalendarFeed GetAllCalendars()
 {
     CalendarQuery query = new CalendarQuery();
     query.Uri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");
     CalendarFeed resultFeed = _myService.Query(query);
     return resultFeed;
 }
            /// <summary>
            /// Attempts to capture a Google.GData.Client.GDataRequestException.
            /// </summary>
            private void ValidateCalendarUrl()
            {
                var calQuery = new CalendarQuery( _credentials.CalendarUrl );

                try
                {
                    _service.Query( calQuery );
                }
                catch( GDataRequestException ex )
                {
                    // this will occur when the calendar URL is invalid, i.e.,
                    // the calendar hasn't been shared as public, but they inluced public in the url:
                    // http://www.google.com/calendar/feeds/UserName%40gmail.com/public/basic
                    // should be:
                    // http://www.google.com/calendar/feeds/UserName%40gmail.com/private/basic
                    // finally, in order to modify events, the url needs to have the full modifier as well:
                    // http://www.google.com/calendar/feeds/UserName%40gmail.com/private/full

                    // TODO: try correcting the URL by replacing /public/ with /private/ and re-authenticating, if fails, throw same exception as currenlty throwing.
                    // TODO: try correcting the URL by replacing /basic with /full and re-authenticating, if fails, throw same exception as currenlty throwing.

                    if( ex.InnerException is WebException && ex.InnerException.Message == "The remote server returned an error: (403) Forbidden." )
                    {
                        string msg = string.Format( "{0} : {1}", ex.InnerException.Message, ex.Message );
                        throw new AuthenticationException( msg, ex );
                    }

                    throw;
                }
            }
示例#3
0
        public IEnumerable<string> Kalendernamen() {
            var service = CalendarService();
            var query = new CalendarQuery();
            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
            var resultFeed = service.Query(query);

            return resultFeed.Entries.Select(x => x.Title.Text);
        }
示例#4
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();
            }
        }
        public void GetCalendarFeed()
        {
            // example of performing a query (use OAuthUri or query.OAuthRequestorId)
            Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/allcalendars/full", "david.turner_adm", ConfigurationManager.AppSettings["consumerKey"]); //allcalendars or owncalendars

            // https://www.googleapis.com/calendar/v3/users/userId/calendarList

            CalendarQuery query = new CalendarQuery();
            query.Uri = calendarUri;
            // query.OAuthRequestorId = "*****@*****.**"; // can do this instead of using OAuthUri for queries
            CalendarFeed feed = service.Query(query);
            foreach (CalendarEntry entry in feed.Entries)
            {
                log.Debug("Calendar title from GetCalendarFeed: " + entry.Title.Text);
            }
        }
示例#6
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");
                    }
                }
            }
        }
示例#7
0
        public EventEntry 创建活动(string 标题, string 说明, string 地点, DateTime 开始时间, DateTime 结束时间, Reminder.ReminderMethod 提醒方式, TimeSpan 提前提醒时间)
        {
            if (提醒方式 != Reminder.ReminderMethod.none && 提前提醒时间.TotalMinutes < 1) throw new Exception("提前提醒时间不得小于1分钟,因为低于分钟的单位将被忽略");

            var q = new EventEntry(标题, 说明, 地点);
            q.Times.Add(new When(开始时间, 结束时间));
            q.Reminder = new Reminder { Minutes = 提前提醒时间.Minutes, Days = 提前提醒时间.Days, Hours = 提前提醒时间.Hours, Method = Reminder.ReminderMethod.all };

            if (操作日历名称 == null)
            {
                return 日历服务.Insert(new Uri(访问网址), q) as EventEntry;
            }
            else
            {
                var query = new CalendarQuery(访问网址);
                CalendarEntry c = null;
                foreach (CalendarEntry f in 日历服务.Query(query).Entries)
                {
                    if (f.Title.Text == 操作日历名称) c = f;
                }
                return 日历服务.Insert(new Uri(c.Content.AbsoluteUri), q) as EventEntry;
            }
        }
        private void toolStripButtonLogin_Click(object sender, EventArgs e)
        {
            toolStripStatusLabelGoogle1.Text = "Status: Logging into Google® Calendar with the Google® Account information you provided. Please wait as I retrieve your Google® Calendar list...";
            Application.DoEvents();

            calendarService = new CalendarService(Application.ProductName);

            try
            {
                calendarService.setUserCredentials(toolStripTextBoxUserName.Text, toolStripTextBoxPassword.Text);
                CalendarQuery query = new CalendarQuery();
                query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
                CalendarFeed resultFeed = (CalendarFeed)calendarService.Query(query);
                System.Diagnostics.Debug.WriteLine("Your calendars:");
                foreach (CalendarEntry entry in resultFeed.Entries)
                {
                    System.Diagnostics.Debug.WriteLine(" >> \"" + entry.Title.Text + "\"");
                    ListViewItem lvi = new ListViewItem(entry.Title.Text);
                    lvi.Tag = entry;
                    this.listViewCalendars.Items.Add(lvi);
                }
            }
            catch (AuthenticationException ex)
            {
                toolStripStatusLabelGoogle1.Text = "Error: Login to Google® Calendar failed with the Google® Account information you provided. Please check your user name and password and try again. " + ex.Message;
                Application.DoEvents();

                //bounce out to let the user try again
                return;
            }
            catch (GDataRequestException ex)
            {
                toolStripStatusLabelGoogle1.Text = "An error has occurred with the data request. Login failed. Message: " + ex.Message;
                Application.DoEvents();

                //bounce out to let the user try again
                return;
            }
            catch (Exception ex)
            {
                toolStripStatusLabelGoogle1.Text = "An unknown error has occurred. Login failed. Message: " + ex.Message;
                Application.DoEvents();

                //bounce out to let the user try again
                return;
            }

            this.toolStripStatusLabelGoogle1.Text = "Status: You have been logged in and I have imported the names of all your Google® Calendars.";
            Application.DoEvents();
        }
示例#9
0
        private string getUriOfSelectedCalendar(string calendarTitle)
        {
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)myService.Query(query);
            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (calendarTitle == entry.Title.Text)
                    return entry.Content.AbsoluteUri;
            }
            return "NO";
        }
示例#10
0
        private void refreshCalendar()
        {
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)myService.Query(query);
            //Console.WriteLine("Your calendars:\n");
            listBox1.Items.Clear();
            foreach (CalendarEntry entry in resultFeed.Entries)
            {

                listBox1.Items.Add(entry.Title.Text);
                richTextBox1.AppendText(entry.Content.AbsoluteUri.ToString() + "\n");
                //richTextBox1.Text += entry.Title.Text + "\n";
            }
        }
示例#11
0
        private bool SaveCalendarIdAndUrl()
        {
            CalendarQuery query = new CalendarQuery();
            query.Uri = new Uri(CALENDARS_URL);
            CalendarFeed resultFeed = (CalendarFeed)m_Service.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (entry.Title.Text == m_CalendarName)
                {
                    m_CalendarId = entry.Id.AbsoluteUri.Substring(63);
                    m_CalendarUrl = string.Format(CALENDAR_TEMPLATE, m_CalendarId);
                    return true;
                }
            }
            return false;
        }
示例#12
0
            protected override void ProcessRecord()
            {
                var _domain = dgcGoogleCalendarService.GetDomain(service.CalendarService);
                var _calendarQuery = new CalendarQuery();
                _calendarQuery.Uri = new Uri("https://www.google.com/calendar/feeds/" + id + "@" + _domain + "/allcalendars/full");

                try
                {
                    var _calendarFeed = service.CalendarService.Query(_calendarQuery);

                    if (_calendarName == null)
                    {
                        var _calendarEntrys = dgcGoogleCalendarService.CreateCalendarEntrys(_calendarFeed);
                        WriteObject(_calendarEntrys, true);
                    }
                    else
                    {
                        var _calendarSelection = from _selection in _calendarFeed.Entries
                                                    where _selection.Title.Text.ToString() == _calendarName
                                                    select _selection;

                        var _calendarEntrys = new GDataTypes.GDataCalendarEntrys();
                        foreach (CalendarEntry _entry in _calendarSelection)
                        {
                            _calendarEntrys = dgcGoogleCalendarService.AppendCalendarEntrys(_entry, _calendarEntrys);
                        }
                        WriteObject(_calendarEntrys, true);
                    }
                }
                catch (Exception _exception)
                {
                    WriteObject(_exception);
                }
            }
示例#13
0
 protected override void ProcessRecord()
 {
     var _domain = dgcGoogleCalendarService.GetDomain(service.CalendarService);
     var _calendarQuery = new CalendarQuery();
     _calendarQuery.Uri = new Uri(selfUri);
     try
     {
         var _calendarFeed = (CalendarFeed)service.CalendarService.Query(_calendarQuery);
         foreach (var _entry in _calendarFeed.Entries)
         {
             if (_entry.SelfUri.ToString() == selfUri)
             {
                 try
                 {
                     _entry.Delete();
                     WriteObject(_entry);
                 }
                 catch (Exception _exception)
                 {
                     WriteObject(_exception);
                 }
             }
         }
     }
     catch (Exception _exception)
     {
         WriteObject(_exception);
     }
 }
示例#14
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;
            }

        }
示例#15
0
            protected override void ProcessRecord()
            {
                var _domain = dgcGoogleCalendarService.GetDomain(service.CalendarService);
                var _query = new CalendarQuery();
                _query.Uri = new Uri(selfUri);

                try
                {
                    var _entry = service.CalendarService.Query(_query);
                    var _links = _entry.Entries[0].Links;

                    if (_links == null)
                    {
                        throw new Exception("AclFeed new null");
                    }

                    var _linkSelection = from _selection in _links
                                where _selection.Rel.ToString() == "http://schemas.google.com/acl/2007#accessControlList"
                                select _selection;

                    foreach (var _Link in _linkSelection)
                    {

                        var _aclQuery = new AclQuery(_Link.HRef.ToString());
                        var _Feed = service.CalendarService.Query(_aclQuery);

                        var _feedSelection = from AclEntry _selection in _Feed.Entries
                                    where _selection.Scope.Value.ToString() == id
                                    select _selection;

                        foreach (AclEntry _aclEntry in _feedSelection)
                        {
                                _aclEntry.Delete();
                                WriteObject(id);
                        }

                    }
                }
                catch (Exception _exception)
                {
                    WriteObject(_exception);
                }
            }
示例#16
0
            protected override void ProcessRecord()
            {
                var _domain = dgcGoogleCalendarService.GetDomain(service.CalendarService);

                var _calendarQuery = new CalendarQuery();
                _calendarQuery.Uri = new Uri(selfUri);
                try
                {
                    var _calendarFeed = (CalendarFeed)service.CalendarService.Query(_calendarQuery);
                    foreach (CalendarEntry _entry in _calendarFeed.Entries)
                    {
                        if (_entry.SelfUri.ToString() == selfUri)
                        {
                            try
                            {
                                if (calendarName != null)
                                {
                                    _entry.Title.Text = calendarName;
                                }
                                if (description != null)
                                {
                                    _entry.Summary.Text = description;
                                }
                                if (timeZone != null)
                                {
                                    _entry.TimeZone = timeZone;
                                }

                                _entry.Update();

                                _calendarFeed = (CalendarFeed)service.CalendarService.Query(_calendarQuery);
                                foreach (CalendarEntry _resultEntry in _calendarFeed.Entries)
                                {
                                    if (_resultEntry.SelfUri.ToString() == selfUri)
                                    {
                                        var _calendarEntry = dgcGoogleCalendarService.CreateCalendarEntry(_resultEntry);
                                        WriteObject(_calendarEntry);

                                    }
                                }
                            }
                            catch (Exception _exception)
                            {
                                WriteObject(_exception);
                            }
                        }
                    }
                }
                catch (Exception _exception)
                {
                    WriteObject(_exception);
                }
            }
示例#17
0
            protected override void ProcessRecord()
            {
                var _domain = dgcGoogleCalendarService.GetDomain(service.CalendarService);

                var _query = new CalendarQuery();
                _query.Uri = new Uri(selfUri);

                try
                {
                    var _entry = service.CalendarService.Query(_query);
                    var _links = _entry.Entries[0].Links;

                    if (_links == null)
                    {
                        throw new Exception("AclFeed new null");
                    }

                    var _linkSelection = from _selection in _links
                                         where _selection.Rel.ToString() == "http://schemas.google.com/acl/2007#accessControlList"
                                         select _selection;

                    foreach (var _link in _linkSelection)
                    {

                        var _aclEntry = new AclEntry();
                        _aclEntry.Scope = new AclScope();
                        _aclEntry.Scope.Type = AclScope.SCOPE_USER;
                        _aclEntry.Scope.Value = id;

                        if (_role.ToUpper() == "FREEBUSY")
                        {
                            _aclEntry.Role = AclRole.ACL_CALENDAR_FREEBUSY;
                        }
                        else if (_role.ToUpper() == "READ")
                        {
                            _aclEntry.Role = AclRole.ACL_CALENDAR_READ;
                        }
                        else if (_role.ToUpper() == "EDITOR")
                        {
                            _aclEntry.Role = AclRole.ACL_CALENDAR_EDITOR;
                        }
                        else if (_role.ToUpper() == "OWNER")
                        {
                            _aclEntry.Role = AclRole.ACL_CALENDAR_OWNER;
                        }
                        else
                        {
                            throw new Exception("-Role needs a FREEBUSY/READ/EDITOR/OWNER parameter");
                        }

                        var _aclUri = new Uri(_link.HRef.ToString());
                        var _alcEntry = service.CalendarService.Insert(_aclUri, _aclEntry) as AclEntry;
                        var _calendarAclEntry = dgcGoogleCalendarService.CreateCalendarAclEntry(_aclEntry);
                        WriteObject(_calendarAclEntry);
                    }
                }
                catch (Exception _exception)
                {
                    WriteObject(_exception);
                }
            }
        /// <summary>
        /// Gets all the calendars the user has write access to
        /// </summary>
        public List<string> GetAllOwnedCalendars()
        {
            List<string> calendars = new List<string>();
            CalendarQuery query = new CalendarQuery();

            query.Uri = new Uri(calendarsOwnedUrl);
            CalendarFeed resultFeed = (CalendarFeed)this.calService.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                calendars.Add(entry.Title.Text);
            }

            return calendars;
        }
        public static void AddMenuButton()
        {
            var ribbonBarItem = K12.Presentation.NLDPanels.Course.RibbonBarItems["課程行事曆"];

            Catalog button_syncCalendar = RoleAclSource.Instance["課程"]["功能按鈕"];
            button_syncCalendar.Add(new RibbonFeature("Reset_Course_Calendar", "重置課程行事曆"));
            bool isEnabled = UserAcl.Current["Reset_Course_Calendar"].Executable;
            var btn = ribbonBarItem["重置課程行事曆"];
            if (isEnabled)
            {
                ribbonBarItem["重置課程行事曆"].Click += delegate
                {
                    if (System.Windows.Forms.MessageBox.Show("將會清空行事例曆中所有資料,\n以及系統內課程同步狀態。\n\nPS.不會影響輸入的上課時間資料。", "重置課程行事曆", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                    {
                        System.ComponentModel.BackgroundWorker bkw = new System.ComponentModel.BackgroundWorker();
                        bkw.WorkerReportsProgress = true;
                        bkw.RunWorkerCompleted += delegate
                        {
                            FISCA.Presentation.MotherForm.SetStatusBarMessage("重置課程行事曆完成。", 100);
                            System.Windows.Forms.MessageBox.Show("課程行事曆已重置,\n請上google calendar檢查,\n如有殘留資料請再執行此功能。");
                        };
                        bkw.ProgressChanged += delegate(object sender, System.ComponentModel.ProgressChangedEventArgs e)
                        {
                            FISCA.Presentation.MotherForm.SetStatusBarMessage("重置課程行事曆...", e.ProgressPercentage);
                        };
                        bkw.DoWork += delegate
                        {
                            bkw.ReportProgress(1);
                            var accessHelper = new FISCA.UDT.AccessHelper();
                            var l1 = accessHelper.Select<Section>();
                            foreach (Section section in l1)
                            {
                                section.IsPublished = false;
                            }
                            l1.SaveAll();
                            bkw.ReportProgress(5);
                            var l2 = accessHelper.Select<Calendar>();
                            foreach (Calendar cal in l2)
                            {
                                cal.Deleted = true;
                            }
                            l2.SaveAll();
                            bkw.ReportProgress(10);
                            #region 清空行事曆
                            CalendarService myService = new CalendarService("ischool.CourseCalendar");
                            myService.setUserCredentials(googleAcc, googlePWD);
                            CalendarQuery cq = new CalendarQuery();
                            cq.Uri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");
                            CalendarFeed resultFeed = myService.Query(cq);
                            foreach (CalendarEntry entry in resultFeed.Entries)
                            {
                                String calendarURI = entry.Id.Uri.ToString();
                                String calendarID = calendarURI.Substring(calendarURI.LastIndexOf("/") + 1);
                                clearAndDeleteCalender(calendarID);
                            }
                            bkw.ReportProgress(55);
                            deleteAllEvent("default");
                            #endregion
                            bkw.ReportProgress(100);
                        };
                        bkw.RunWorkerAsync();
                    }
                };
            }
            else
            {
                btn.Enable = false;
            }
        }
示例#20
0
 /// <summary>
 /// overloaded to create typed version of Query for Calendar feeds
 /// </summary>
 /// <param name="calQuery">The query object for searching a calendar feed.</param>
 /// <returns>CalendarFeed of the returned calendar entries.</returns>
 public CalendarFeed Query(CalendarQuery calQuery) {
     return base.Query(calQuery) as CalendarFeed;
 }
示例#21
0
文件: GGSync.cs 项目: wertkh32/gg
        /// <summary>
        /// Delete duplicate GG calendar
        /// </summary>
        /// <param name="GGService">Google calendar service object</param>
        private void DeleteGGCalendar(CalendarService GGService)
        {
            // Query server to get all calendars
            CalendarQuery query = new CalendarQuery();
            query.Uri = new Uri(CALENDAR_QUERY_URL);
            CalendarFeed resultFeed = (CalendarFeed)GGService.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (entry.Title.Text == GG_CALENDAR_TITLE)
                {
                    // Delete this calendar
                    Log("Delete calendar: " + entry.Title.Text + "\n");
                    entry.Delete();
                }
            }
        }
示例#22
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();
                }
            }
        }
示例#23
0
文件: GGSync.cs 项目: wertkh32/gg
        /// <summary>
        /// Select GG calendar
        /// </summary>
        /// <param name="GGService">Google calendar service object</param>
        /// <returns>selected GG calendar</returns>
        private CalendarEntry SelectGGCalendar(CalendarService GGService)
        {
            // Query server to get all calendars
            CalendarQuery query = new CalendarQuery();
            query.Uri = new Uri(CALENDAR_QUERY_URL);
            CalendarFeed resultFeed = (CalendarFeed)GGService.Query(query);

            Log("Your calendars:\n");

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                Log(entry.Title.Text + "\n");
                if (entry.Title.Text == "GG To-do List")
                {
                    // Return GG calendar
                    return entry;
                }
            }

            // GG calendar does not exist
            return null;
        }
 /// <summary>
 /// overloaded to create typed version of Query for Calendar feeds
 /// </summary>
 /// <param name="calQuery">The query object for searching a calendar feed.</param>
 /// <returns>CalendarFeed of the returned calendar entries.</returns>
 public CalendarFeed Query(CalendarQuery calQuery)
 {
     return(base.Query(calQuery) as CalendarFeed);
 }
        public static List<Calendar> GetCalendarList()
        {
            // Create a CalenderService and authenticate
            var service = new CalendarService("GoogleCalendarReminder");
            service.SetAuthenticationToken(GetAuthToken());

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

            var query = new CalendarQuery
                            {
                                Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full")
                            };

            CalendarFeed resultFeed;

            try
            {
                resultFeed = service.Query(query) as CalendarFeed;
            }
            catch (CaptchaRequiredException ex)
            {
                // TODO: CDA - http://code.google.com/googleapps/faq.html
                MessageBox.Show(ex.Message, ex.GetType().ToString());

                //https://www.google.com/accounts/UnlockCaptcha
                return null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
                return null;
            }

            return (from CalendarEntry entry in resultFeed.Entries where !entry.Hidden select new Calendar(entry)).ToList();
        }