public GDataTypes.GDataContactEntrys CreateContactEntrys(ContactsFeed contactEntrys) { var _gDataContactEntrys = new GDataTypes.GDataContactEntrys(); foreach (ContactEntry _contactEntry in contactEntrys.Entries) { var _gDataContactEntry = new GDataTypes.GDataContactEntry(); _gDataContactEntry.Name = _contactEntry.Title.Text; foreach (var _emailEntry in _contactEntry.Emails) { if (_emailEntry.Work == true) { _gDataContactEntry.Email = _emailEntry.Address; } } foreach (var _phoneNumberEntry in _contactEntry.Phonenumbers) { if (_phoneNumberEntry.Rel == ContactsRelationships.IsWork) { _gDataContactEntry.PhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsHome) { _gDataContactEntry.HomePhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsMobile) { _gDataContactEntry.MobilePhoneNumber = _phoneNumberEntry.Value; } if (_phoneNumberEntry.Rel == ContactsRelationships.IsOther) { _gDataContactEntry.OtherPhoneNumber = _phoneNumberEntry.Value; } } foreach (var _postaAddressEntry in _contactEntry.PostalAddresses) { if (_postaAddressEntry.Rel == ContactsRelationships.IsWork) { _gDataContactEntry.PostalAddress = _postaAddressEntry.FormattedAddress; } if (_postaAddressEntry.Rel == ContactsRelationships.IsHome) { _gDataContactEntry.HomeAddress = _postaAddressEntry.FormattedAddress; } } _gDataContactEntry.SelfUri = _contactEntry.SelfUri.ToString(); _gDataContactEntrys.Add(_gDataContactEntry); } return _gDataContactEntrys; }
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(); }