Пример #1
0
        public ProcessPoint Get(ProcessPoint point)
        {
            WebClientExtended client = new WebClientExtended();

            if (Convert.ToBoolean(ConfigurationManager.AppSettings["isProxy"]))
            {
                string Host            = ConfigurationManager.AppSettings["ProxyHost"];
                int    Port            = Convert.ToInt32(ConfigurationManager.AppSettings["ProxyPort"]);
                System.Net.WebProxy wp = new System.Net.WebProxy(Host, Port);
                client.Proxy = wp;
            }

            string ep  = string.Format(ConfigurationManager.AppSettings["OSMApiPath"]);
            string url = string.Format("{0}{1}&format=xml&addressdetails=1", ep, point.SourceAddress);

            string st = System.Text.Encoding.UTF8.GetString(client.DownloadData(url));

            XmlSerializer serializer = new XmlSerializer(typeof(Searchresults));

            using (TextReader tr = new StringReader(st))
            {
                Searchresults result = (Searchresults)serializer.Deserialize(tr);
                if (result.Place != null)
                {
                    point.Coordinate       = new Coordinate(result.Place.Lat, result.Place.Lon);
                    point.FormattedAddress = result.Place.Display_name;
                    point.SetSearchEngineStatus("OK");
                    point.Conteiner    = (object)result.Place;
                    point.SearchEngine = SearchEngine.Osm;
                }
                else
                {
                    point.SetSearchEngineStatus("ZERO_RESULTS");
                }

                XmlSerializer smr = new XmlSerializer(typeof(Searchresults));
                using (StringWriter tw = new StringWriter())
                {
                    smr.Serialize(tw, result);
                    point.Xml = tw.ToString();
                }


                point.Save(hdb);

                return(point);
            }
        }
Пример #2
0
        public void Get(ProcessPoint point)
        {
            WebClientExtended client = new WebClientExtended();

            if (Convert.ToBoolean(ConfigurationManager.AppSettings["isProxy"]))
            {
                string Host            = ConfigurationManager.AppSettings["ProxyHost"];
                int    Port            = Convert.ToInt32(ConfigurationManager.AppSettings["ProxyPort"]);
                System.Net.WebProxy wp = new System.Net.WebProxy(Host, Port);
                client.Proxy = wp;
            }

            string ep  = string.Format(ConfigurationManager.AppSettings["OSMApiPath"]);
            string url = string.Format("{0}{1}&format=xml", ep, point.SourceAddress);

            string        st         = System.Text.Encoding.UTF8.GetString(client.DownloadData(url));
            XmlSerializer serializer = new XmlSerializer(typeof(Searchresults));

            using (TextReader tr = new StringReader(st))
            {
                Searchresults result = (Searchresults)serializer.Deserialize(tr);
            }
        }