Beispiel #1
0
        private void GetContact(int i, IList <IContact> result, Google.Contacts.Contact e)
        {
            if (e.PrimaryEmail == null)
            {
                return;
            }
            Contact contact = new Contact();

            contact.Index     = i;
            contact.FirstName = e.Title;
            contact.Email     = e.PrimaryEmail.Address;
            result.Add(contact);
        }
Beispiel #2
0
        private IList <IContact> GetContacts(int pageNumber, int pageSize, ISelection selection)
        {
            IList <IContact>       result      = new List <IContact>();
            GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cp", applicationName);

            authFactory.Token      = this.token.ToString();
            authFactory.PrivateKey = getRsaKey();
            RequestSettings rs = new RequestSettings(applicationName, token.ToString());

            rs.AutoPaging = true;
            ContactsService cs = new ContactsService(applicationName);

            cs.RequestFactory = authFactory;
            ContactsRequest cr = new ContactsRequest(rs);

            cr.Service = cs;
            Feed <Google.Contacts.Contact> contacts = cr.GetContacts();
            int i = 1;

            if (pageNumber > 0)
            {
                foreach (Google.Contacts.Contact e in contacts.Entries)
                {
                    if (i < (pageNumber * pageSize) - (pageSize - 1))
                    {
                        i++;
                        continue;
                    }
                    if (i > (pageNumber * pageSize))
                    {
                        break;
                    }

                    GetContact(i++, result, e);
                }

                this.totalCount = contacts.TotalResults;
            }
            else if (selection != null)
            {
                foreach (Google.Contacts.Contact e in contacts.Entries)
                {
                    if (!selection.SelectedAll && !selection.SelectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                                                          {
                                                                                                              return(true);
                                                                                                          }
                                                                                                          return(false); }))
                    {
                        i++;
                        continue;
                    }
                    if (selection.SelectedAll && selection.SelectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                                                        {
                                                                                                            return(true);
                                                                                                        }
                                                                                                        return(false); }))
                    {
                        i++;
                        continue;
                    }
                    if (e.PrimaryEmail == null)
                    {
                        continue;
                    }

                    Contact contact = new Contact();
                    contact.Index     = i;
                    contact.FirstName = e.Title;
                    contact.Email     = e.PrimaryEmail.Address;
                    result.Add(contact);
                    i++;
                }
            }
            else
            {
                foreach (Google.Contacts.Contact e in contacts.Entries)
                {
                    GetContact(i++, result, e);
                }

                this.totalCount = contacts.TotalResults;
            }

            return(result);
        }