Exemple #1
0
        public void LoadGoogleGroups()
        {
            GroupsQuery query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));
            query.NumberToRetrieve = 256;
            query.StartIndex = 0;
            query.ShowDeleted = false;

            GroupsFeed feed;
            feed = _googleService.Query(query);
            _googleGroups = feed.Entries;
            while (feed.Entries.Count == query.NumberToRetrieve)
            {
                query.StartIndex = _googleGroups.Count;
                feed = _googleService.Query(query);
                foreach (AtomEntry a in feed.Entries)
                {
                    _googleGroups.Add(a);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////


        /////////////////////////////////////////////////////////////////////
        /// <summary>runs an basic auth test against the groups feed test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void GroupsSystemTest()
        {
            Tracing.TraceMsg("Entering GroupsSystemTest");

            GroupsQuery query = new GroupsQuery(ContactsQuery.CreateGroupsUri(this.userName + "@googlemail.com"));
            ContactsService service = new ContactsService("unittests");

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

            GroupsFeed feed = service.Query(query);

            int i = 0; 
            foreach (GroupEntry g in feed.Entries )
            {
               if (g.SystemGroup != null)
               {
                   i++;
               }
            }

            Assert.IsTrue(i==4, "There should be 4 system groups in the groups feed");


            ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("GroupsAuthTest"));

            GroupEntry newGroup = new GroupEntry();
            newGroup.Title.Text = "Private Data";

            GroupEntry insertedGroup = feed.Insert(newGroup);

            GroupEntry g2 = new GroupEntry();
            g2.Title.Text = "Another Private Group";
            GroupEntry insertedGroup2 = feed.Insert(g2);

            // now insert a new contact that belongs to that group
            ContactsQuery q = new ContactsQuery(ContactsQuery.CreateContactsUri(this.userName + "@googlemail.com"));
            ContactsFeed cf = service.Query(q);
            ContactEntry entry = ObjectModelHelper.CreateContactEntry(1);
            GroupMembership member = new GroupMembership();
            member.HRef = insertedGroup.Id.Uri.ToString();
            GroupMembership member2 = new GroupMembership();
            member2.HRef = insertedGroup2.Id.Uri.ToString();

            ContactEntry insertedEntry = cf.Insert(entry);
            // now change the group membership
            insertedEntry.GroupMembership.Add(member);
            insertedEntry.GroupMembership.Add(member2);
            ContactEntry currentEntry = insertedEntry.Update();

            Assert.IsTrue(currentEntry.GroupMembership.Count == 2, "The entry should be in 2 groups");

            currentEntry.GroupMembership.Clear();
            currentEntry = currentEntry.Update();
            // now we should have 2 new groups and one new entry with no groups anymore


            int oldCountGroups = feed.Entries.Count;
            int oldCountContacts = cf.Entries.Count;

            currentEntry.Delete();

            insertedGroup.Delete();
            insertedGroup2.Delete();

            feed = service.Query(query);
            cf = service.Query(q);

            Assert.AreEqual(oldCountContacts, cf.Entries.Count, "Contacts count should be the same");
            Assert.AreEqual(oldCountGroups, feed.Entries.Count, "Groups count should be the same");
        }
        private void LoadGoogleGroups()
        {
            string message = "Error Loading Google Groups. Cannot connect to Google.\r\nPlease ensure you are connected to the internet. If you are behind a proxy, change your proxy configuration!";
            try
            {
                Logger.Log("Loading Google Groups...", EventType.Information);
                GroupsQuery query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));
                query.NumberToRetrieve = 256;
                query.StartIndex = 0;
                //query.ShowDeleted = false;

                GoogleGroups = new Collection<Group>();

                Feed<Group> feed = ContactsRequest.Get<Group>(query);

                while (feed != null)
                {
                    foreach (Group a in feed.Entries)
                    {
                        GoogleGroups.Add(a);
                    }
                    query.StartIndex += query.NumberToRetrieve;
                    feed = ContactsRequest.Get<Group>(feed, FeedRequestType.Next);

                }

                ////Only for debugging or reset purpose: Delete all Gougle Groups:
                //for (int i = GoogleGroups.Count; i > 0;i-- )
                //    _googleService.Delete(GoogleGroups[i-1]);
            }
            catch (System.Net.WebException ex)
            {
                //Logger.Log(message, EventType.Error);
                throw new GDataRequestException(message, ex);
            }
            catch (System.NullReferenceException ex)
            {
                //Logger.Log(message, EventType.Error);
                throw new GDataRequestException(message, new System.Net.WebException("Error accessing feed", ex));
            }
        }
Exemple #4
0
 /// <summary>
 /// overloaded to create typed version of Query
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <returns>EventFeed</returns>
 public GroupsFeed Query(GroupsQuery feedQuery) {
     return base.Query(feedQuery) as GroupsFeed;
 }
 /// <summary>
 /// overloaded to create typed version of Query
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <returns>EventFeed</returns>
 public GroupsFeed Query(GroupsQuery feedQuery)
 {
     return(base.Query(feedQuery) as GroupsFeed);
 }
		public void FetchTask()
		{
			if (syncEngine.SyncCanceled)
			{
				this.FetchSem.Release();
				return;
			}

			mans.Clear();
			contactsByFullName.Clear();

			googleService = new ContactsService("Contact Infomation");

			if (Credentials == null)
			{
				this.FetchSem.Release();
				return;
			}
			else
			{
				if (Credentials.UserName != null && !Credentials.UserName.ToLower().EndsWith("@gmail.com"))
				{
					Credentials.UserName += "@gmail.com";
				}
				googleService.setUserCredentials(Credentials.UserName, Credentials.Password);
			}

			((GDataRequestFactory)googleService.RequestFactory).Timeout = 3000;

			queruUriFull = ContactsQuery.CreateContactsUri(Credentials.UserName, ContactsQuery.fullProjection);
			contactsQuery = new ContactsQuery(queruUriFull);
			contactsQuery.NumberToRetrieve = 1000;

			try
			{

				feed = googleService.Query(contactsQuery);
			}
			catch (Google.GData.Client.GDataRequestException e)
			{
				Credentials = null;

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.InnerException.Message, null);

				this.FetchSem.Release();
				return;
			}
			catch (Google.GData.Client.InvalidCredentialsException e)
			{
				Credentials = null;

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.Message, null);

				this.FetchSem.Release();
				return;
			}
			catch (CaptchaRequiredException e)
			{
				Credentials = null;

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.Message, "https://www.google.com/accounts/UnlockCaptcha");

				this.FetchSem.Release();
				return;
			}
			catch (Exception e)
			{
				Credentials = null;

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.Message, null);

				this.FetchSem.Release();
				return;
			}

			syncEngine.CurrentTotal += feed.Entries.Count;
			
			GroupsQuery groupsQuery = new GroupsQuery(GroupsQuery.
				CreateGroupsUri(Credentials.UserName, ContactsQuery.thinProjection));

			try
			{
				groupsFeed = googleService.Query(groupsQuery);
			} 
			catch (Google.GData.Client.GDataRequestException e)
			{
				Credentials = null;

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.InnerException.Message, null);
								
				this.FetchSem.Release();
				return;
			}

			foreach (ContactEntry entry in feed.Entries)
			{

				if (owner != null)
				{
					Dispatcher.Invoke(new SyncProgressEventHandler(owner.Progress), this,
						"Loading " + "(" + syncEngine.CurrentItemNum + "/" + syncEngine.CurrentTotal + ")",
						syncEngine.CurrentItemNum, syncEngine.CurrentTotal);
					syncEngine.CurrentItemNum++;
				}

				Contact contact = GetCanonicalContact(entry);
				
				string fullname = contact.FullName;

				if (fullname == null || fullname.Trim() == "")
				{
				}
				else
				{
					contactsByFullName[fullname] = contact;
					mans.Add(new Man { FullName = fullname, EMail = contact.EMail, Phone = contact.Phone });
				}
				
			}

			this.FetchSem.Release();
		}