Exemplo n.º 1
0
        public List <VkUser> GetFriendsListForInventation(string eventId, BackgroundWorker bw = null)
        {
            Logger.LogMethod();
            List <VkUser> vkUsersInTheGroupTotal = new List <VkUser>();
            List <VkUser> vkUsersInTheGroupSubSet;
            int           offset       = 0;
            decimal       workProgerss = 0m;

            do
            {
                string url = string.Format("{0}friends",
                                           HttpConnector.HTTPVKCOM);

                Thread.Sleep(HttpConnector.TIMEOUT);
                HttpWebResponseEx resp = HttpConnector.SendHttpWebRequestAndGetResponse(url, HttpMethod.POST,
                                                                                        requestBody: string.Format("act=get_section_friends&al=1&gid={0}&offset={1}&section=members&sugg_rev=0", eventId, offset));
                string responseString = resp.ResponseText;
                vkUsersInTheGroupSubSet = VkUserEx.ParseFriendsList(responseString);
                offset += vkUsersInTheGroupSubSet.Count;
                vkUsersInTheGroupTotal.AddRange(vkUsersInTheGroupSubSet);
                workProgerss += 0.25m;
                if (bw != null)
                {
                    bw.ReportProgress((int)workProgerss);
                }
            } while (vkUsersInTheGroupSubSet.Count != 0);

            return(vkUsersInTheGroupTotal);
        }
Exemplo n.º 2
0
        public List <VkUser> GetAllUsersInCity(string groupId, string countryId, string cityId, BackgroundWorker bw = null)
        {
            Logger.LogMethod(groupId, countryId, cityId, bw);

            AlSearchEngine alSearchEngine = new AlSearchEngine();

            int totalUserCount = 0;

            List <VkUser> vkUsersInTheCity = new List <VkUser>();
            List <VkUser> vkUsersSubset;

            string baseUrl = string.Format("{0}al_search.php",
                                           HttpConnector.HTTPVKCOM);

            int    offset;
            bool   hasMore;
            string postBody;

            do
            {
                offset  = 0;
                hasMore = false;

                do
                {
                    postBody = string.Format("al=1&c%5Bcity%5D={0}&c%5Bcountry%5D={1}&c%5Bgroup%5D={2}&c%5Bname%5D=1&c%5Bphoto%5D=1&c%5Bsection%5D=people", cityId, countryId, groupId)
                               + alSearchEngine.GetSearchUrlAddition(offset);

                    Thread.Sleep(HttpConnector.TIMEOUT);
                    HttpWebResponseEx resp = HttpConnector.SendHttpWebRequestAndGetResponse(baseUrl, HttpMethod.POST,
                                                                                            requestBody: postBody);

                    string responseString = resp.ResponseText;

                    if (alSearchEngine.IsFirstStep() && (offset == 0))
                    {
                        totalUserCount = VkUserEx.AlSearchGetSummaryUserCount(responseString);
                    }

                    if (totalUserCount == 0)
                    {
                        break;
                    }

                    vkUsersSubset    = VkUserEx.AlSearchParsePeopleRow(responseString);
                    vkUsersInTheCity = vkUsersInTheCity.Union(vkUsersSubset, new VkUserComparer()).ToList();

                    hasMore = VkUserEx.AlSearchParseHasMore(responseString);
                    offset  = VkUserEx.AlSearchParseOffset(responseString);

                    if (bw != null)
                    {
                        bw.ReportProgress(vkUsersInTheCity.Count * 100 / totalUserCount);
                    }
                } while (hasMore && offset > 0 && offset < 1000);
            } while (alSearchEngine.NextStep(offset));

            vkUsersInTheCity.SetCityIdToAllUsers(cityId);

            List <VkUser> allUsers = new List <VkUser>();

            allUsers.AddRange(vkUsersInTheCity);

            return(allUsers);
        }