Ejemplo n.º 1
0
        private List <Friend> GetGmailContacts(int page, List <int> selectedIndexs)
        {
            int            pageSize = 10;
            List <Friend>  friends  = new List <Friend>();
            MembershipUser mu       = Membership.GetUser();
            RegisteredUser user     = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));

            if (Session["GMailToken"] == null)
            {
                String token = Request.QueryString["token"];
                Session["GMailToken"] = AuthSubUtil.exchangeForSessionToken(token, null).ToString();
            }

            GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cp", "testingFADE");
            RequestSettings        rs          = new RequestSettings("testingFADE", (String)Session["GMailToken"]);

            rs.AutoPaging = true;
            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Contact> contacts = cr.GetContacts();
            int            i        = 1;

            if (page > 0)
            {
                foreach (Contact e in contacts.Entries)
                {
                    if (i < (page * pageSize) - 9)
                    {
                        i++;
                        continue;
                    }
                    if (i > (page * pageSize))
                    {
                        break;
                    }
                    if (e.PrimaryEmail == null)
                    {
                        continue;
                    }
                    Friend friend = new Friend();
                    friend.FirstName    = e.Title;
                    friend.EmailAddress = e.PrimaryEmail.Address;
                    friend.InvitedBy    = user;
                    friends.Add(friend);
                    i++;
                }
                ViewData["Pages"] = Common.Paging(contacts.TotalResults, page, pageSize, 10);
            }
            else if (selectedIndexs != null)
            {
                foreach (Contact e in contacts.Entries)
                {
                    if (!selectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                      {
                                                                          return(true);
                                                                      }
                                                                      return(false); }))
                    {
                        i++;
                        continue;
                    }
                    Friend friend = new Friend();
                    friend.FirstName    = e.Title;
                    friend.EmailAddress = e.PrimaryEmail.Address;
                    friend.InvitedBy    = user;
                    friends.Add(friend);
                    i++;
                }
            }

            return(friends);
        }