コード例 #1
0
        public void EndGetAllStations(IAsyncResult result)
        {
            try
            {
                using (WebResponse response = _stationsRequest.EndGetResponse(result))
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream);
                        string       json   = reader.ReadToEnd();
                        MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(json));
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(City));

                        City city = (City)serializer.ReadObject(stream);
                        if (city != null)
                        {
                            ObservableCollection <BikeStationViewModel> collection = new ObservableCollection <BikeStationViewModel>();

                            for (int i = 0; i < city.Stations.Count; i++)
                            {
                                //stations[i] = new BikeStation(stationsCollection[i])
                                var bikeStation = new BikeStationViewModel(city.Stations[i]);
                                //give them id - just to easy up manipulation
                                bikeStation.Id = i;
                                collection.Add(bikeStation);
                            }

                            this.Stations = collection;
                            if (_showAllWhenLoaded)
                            {
                                this.FromNearStations = collection;
                            }
                        }
                    }
                }
                IsMessage = false;
            }
            catch (Exception ex)
            {
                IsMessage = true;
                Message   = AppResources.Message_UnspecifiedError;
            }
        }
コード例 #2
0
        public void EndGetAllStations(IAsyncResult result)
        {
            try
            {
                using (WebResponse response = _stationsRequest.EndGetResponse(result))
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {

                        StreamReader reader = new StreamReader(responseStream);
                        string json = reader.ReadToEnd();
                        MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(json));
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(City));

                        City city = (City)serializer.ReadObject(stream);
                        if (city != null)
                        {
                            ObservableCollection<BikeStationViewModel> collection = new ObservableCollection<BikeStationViewModel>();

                            for (int i = 0; i < city.Stations.Count; i++)
                            {
                                //stations[i] = new BikeStation(stationsCollection[i])
                                var bikeStation = new BikeStationViewModel(city.Stations[i]);
                                //give them id - just to easy up manipulation
                                bikeStation.Id = i;
                                collection.Add(bikeStation);
                            }

                            this.Stations = collection;
                            if (_showAllWhenLoaded)
                            {
                                this.FromNearStations = collection;
                            }
                        }
                    }
                }
                IsMessage = false;
            }
            catch (Exception ex)
            {
                IsMessage = true;
                Message = AppResources.Message_UnspecifiedError;
            }
        }