internal SearchLocationsCompletedEventArgs(Exception error, Boolean cancelled, Object userState, ItemViewModel station) : base(error, cancelled, userState) { #region Initialize the state. if (station != null) { m_station = station; } #endregion }
public void SelectStation(ItemViewModel station) { MessageBox.Show("Haltestelle " + station.StationName + " ausgewählt."); }
/// <summary> /// ACTIONS /// </summary> /// <param name="station"></param> public void SelectStation(ItemViewModel station) { if (SearchSource.Equals("DepartureView")) { queryVM.StationId = station.Location.Id; navigationService.UriFor<DepartureViewModel>().WithParam(x => x.DepartureField, station.StationName + ", " + station.City + "$" + station.Location.Id).Navigate(); } else if (SearchSource.Equals("Departure")) { queryVM.From = station.Location; navigationService.UriFor<SearchViewModel>().WithParam(x => x.DepartureField, station.StationName + ", " + station.City + "$" + station.Location.Id).Navigate(); } else { queryVM.From = station.Location; navigationService.UriFor<SearchViewModel>().WithParam(x => x.ArrivalField, station.StationName + ", " + station.City + "$" + station.Location.Id).Navigate(); } }
/// <summary> /// Handle the first response returned from the async request /// </summary> /// <param name="asyncResult"></param> private void HandleCoordResponse(IAsyncResult asyncResult) ///now this is background { // get the state information QueryUpdateState queryUpdateState = (QueryUpdateState)asyncResult.AsyncState; HttpWebRequest getStationsRequest = (HttpWebRequest)queryUpdateState.AsyncRequest; // end the async request queryUpdateState.AsyncResponse = (HttpWebResponse)getStationsRequest.EndGetResponse(asyncResult); string status = queryUpdateState.AsyncResponse.StatusDescription; HttpStatusCode statusCode = queryUpdateState.AsyncResponse.StatusCode; Stream streamResult; try { // get the stream containing the response from the async call streamResult = queryUpdateState.AsyncResponse.GetResponseStream(); // load the XML XElement xmlStationsResponse = XElement.Load(streamResult); XElement originElem = xmlStationsResponse.Descendants("coordInfoItemList").FirstOrDefault(); if (originElem != null) { List<ItemViewModel> stations = new List<ItemViewModel>(); foreach (var xmlStation in originElem.Descendants("coordInfoItem")) { if (xmlStation.HasAttributes) { var station = new ItemViewModel(); station.SelectionBorderThickness = new Thickness(0); station.City = xmlStation.Attribute("locality").Value; station.StationName = xmlStation.Attribute("name").Value; int id = -1; if (xmlStation.Attribute("id") != null) id = int.Parse(xmlStation.Attribute("id").Value); int distance = -1; if (xmlStation.Attribute("distance") != null) distance = int.Parse(xmlStation.Attribute("distance").Value); int lon = -1, lat = -1; XElement coordElem = xmlStation.Descendants("itdCoordinateString").FirstOrDefault(); if (coordElem != null) { string[] coordString = coordElem.Value.Split(','); if (coordString.Length == 2) { lon = int.Parse(coordString[0]); lat = int.Parse(coordString[1]); } } station.Location = new Location(LocationType.STATION, id, lat, lon); station.Distance = distance + "m"; stations.Add(station); } } OnSearchNearbyLocationsCompleted(new SearchLocationsCompletedEventArgs(null, false, "nearbyItems", stations)); } } catch (FormatException fe) { throw new Exception("Fehler bei GetResponseStream()", fe.InnerException); // there was some kind of error processing the response from the web // additional error handling would normally be added here } }
/// <summary> /// Handle the found stations response returned from the async request /// </summary> /// <param name="asyncResult"></param> private void AsyncResponseLoadStations(IAsyncResult asyncResult) ///now this is background { // get the state information QueryUpdateState queryUpdateState = (QueryUpdateState)asyncResult.AsyncState; HttpWebRequest getStationsRequest = (HttpWebRequest)queryUpdateState.AsyncRequest; // end the async request queryUpdateState.AsyncResponse = (HttpWebResponse)getStationsRequest.EndGetResponse(asyncResult); Stream streamResult; try { // get the stream containing the response from the async call streamResult = queryUpdateState.AsyncResponse.GetResponseStream(); // load the XML XElement xmlStationsResponse = XElement.Load(streamResult); XElement originElem = xmlStationsResponse.Descendants("itdOdv").Where(elem => elem.Attribute("usage").Value.Equals("origin")).FirstOrDefault(); List<ItemViewModel> stations = new List<ItemViewModel>(); foreach (var xmlStation in originElem.Descendants("odvNameElem")) { if (xmlStation.HasAttributes) { var station = new ItemViewModel(); station.SelectionBorderThickness = new Thickness(0); station.City = xmlStation.Attribute("locality").Value; station.StationName = xmlStation.Attribute("objectName").Value; Location loc = new Location(LocationType.STATION, int.Parse(xmlStation.Attribute("id").Value)); station.Location = loc; //temp.ThumbNailImage = new BitmapImage(new Uri("Images/Haltestelle.gif")); stations.Add(station); } } OnSearchNearbyLocationsCompleted(new SearchLocationsCompletedEventArgs(null, false, "items", stations)); } catch (FormatException fe) { throw new Exception("Fehler bei GetResponseStream()", fe.InnerException); // there was some kind of error processing the response from the web // additional error handling would normally be added here } //long applicationCurrentMemoryUsage = (long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage"); }
public void SelectStation(ItemViewModel station) { if (StationSelected != null) StationSelected(station, EventArgs.Empty); }