public static string GetCityIdByName(string countryId, string cityName) { Logger.LogMethod(countryId, cityName); string url = string.Format("{0}select_ajax.php?act=a_get_cities&country={1}&str={2}", HttpConnector.HTTPVKCOM, countryId, cityName); string responseString = HttpConnector.SendHttpWebRequestAndGetResponse(url, HttpMethod.GET) .ResponseText; List <VkCity> listVkCity = VkCityEx.ParseReponse(responseString); return(listVkCity[0].Id.ToString()); }
// This event handler is where the time-consuming work is done. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { Logger.LogMethod(); BackgroundWorker worker = sender as BackgroundWorker; Dictionary <string, string> args = e.Argument as Dictionary <string, string>; vkInv.Login = args["login"]; vkInv.Password = args["password"]; string countryId = args["countryId"]; string citiesList = args["citiesList"]; string groupId = args["groupId"]; string eventId = args["eventId"]; _bwStatus = "Logon"; worker.ReportProgress(0); vkInv.Logon(); _bwStatus = "Get cities list"; worker.ReportProgress(0); List <string> listCitiesId = VkCityEx.GetListOfCityIdByNames(countryId, citiesList, worker); if ((listCitiesId == null) || (listCitiesId.Count == 0)) { throw new ArgumentNullException(); } StatisticsAndReport.CityNames = citiesList; _bwStatus = "Get all users in the cities"; worker.ReportProgress(0); List <VkUser> usersInTheCity = new List <VkUser>(); foreach (string cityId in listCitiesId) { usersInTheCity.AddRange(vkInv.GetAllUsersInCity(groupId, countryId, cityId, worker)); } if (usersInTheCity.Count == 0) { throw new ArgumentNullException(); } StatisticsAndReport.UserCountInCity = usersInTheCity.Count; _bwStatus = "Get all group member for inventation"; worker.ReportProgress(0); List <VkUser> friends = vkInv.GetFriendsListForInventation(eventId, worker); if ((friends == null) || (friends.Count == 0)) { throw new ArgumentNullException(); } usersInTheCity = usersInTheCity.GetHasIdFrom(friends); _bwStatus = "Sending invites to users"; worker.ReportProgress(0); vkInv.InviteCycle(eventId, usersInTheCity, worker); worker.ReportProgress(100); StatisticsAndReport.ParseResultForReport(usersInTheCity); }