예제 #1
0
파일: Program.cs 프로젝트: GoGo228/HIREpo
        static void Main(string[] args)
        {
            var client = new RestClient("https://search-maps.yandex.ru/v1/?text=Банк, Дніпропетровськ, Україна&type=biz&lang=uk_Ua&apikey=f7f27aa0-8bf2-4d7d-9e80-fdab701a58c8&results=500");

            var request = new RestRequest("resource/" , Method.GET);
            /*
            client.ExecuteAsync(request, response =>
            {
                Console.WriteLine(response.Content);
            });*/
            //type=банк банкомат;

            int k=0;
            
            RepositoryHolder holder = new RepositoryHolder();
            var asyncHandle = client.ExecuteAsync<RootObject>(request, response =>
            {
                        
                        
                        for (int i = 0; i <= response.Data.features.Count-1; i++)
                        {                    
                          string[] buf = response.Data.features[i].properties.CompanyMetaData.address.Split(','); //разбиваем строку на массив слов, разделитель пробел

                            Char separator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator[0];
                            String Source = response.Data.features[i].geometry.coordinates[0].Replace(',', separator);
                            Double number = Convert.ToDouble(Source);
                            String Source2 = response.Data.features[i].geometry.coordinates[1].Replace(',', separator);
                            Double number2 = Convert.ToDouble(Source2);
                            holder.AdressRepository.Insert( new Entity.tbAdress() {
                                cLatitude = Source,
                                cLongitude = Source2,
                                cIdBank=1,
                                cAdressVal = response.Data.features[i].properties.CompanyMetaData.address,
                                cCity=buf[0],
                                cCountry="Україна",
                                cStreet=buf[1]+buf[2]});
                            holder.SaveChanges();
                        }
                    
            });
         
            Console.Read();
        }