コード例 #1
0
 /// <summary>
 /// получение данных геолокации в асинхронном режиме
 /// </summary>
 /// <param name="searchQuery"></param>
 /// <param name="completeAction"></param>
 public void GetAvialableGeoLocationsAsync(string searchQuery, Action <IEnumerable <GeoLocationBase>, Exception> completeAction)
 {
     if (this._contentWebClient != null)
     {
         return;
     }
     this._contentWebClient = new OsmGeoLocationsInfoClient(this.prepareSearchUrl(searchQuery), completeAction);
     this._contentWebClient.DownloadXmlAsyncUtf8();
     this._contentWebClient.DownloadStringCompleted += cwc_DownloadStringCompleted;
 }
コード例 #2
0
        /// <summary>
        /// обработка получения данных геолокации в асинх режиме
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cwc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            OsmGeoLocationsInfoClient osmGeoClient = sender as OsmGeoLocationsInfoClient;

            try {
                if (!e.Cancelled)
                {
                    string xml = e.Result;
                    //парсим данные
                    IEnumerable <GeoLocationBase> geoLocations = this._geoParser.ParseXmlGeoData(xml);
                    osmGeoClient.CompleteAction(geoLocations, null);
                }
            }
            catch (Exception ex) {
                osmGeoClient.CompleteAction(null, ex);
            }
            finally {
                osmGeoClient.Dispose();
                this._contentWebClient = null;
            }

            // return geoLocations.Cast<T>();
        }