protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back) return; panorama.Title = NavigationContext.QueryString["Plecare"] + "-"; if (NavigationContext.QueryString.ContainsKey("Via")) panorama.Title += NavigationContext.QueryString["Via"] + "-"; panorama.Title += NavigationContext.QueryString["Sosire"]; Ruta = RouteResultsPage.Rute.ElementAt(Int32.Parse(NavigationContext.QueryString["Index"])); InfoStack.DataContext = Ruta; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back) return; PageTitle.Text = NavigationContext.QueryString["Plecare"] + "-"; if (NavigationContext.QueryString.ContainsKey("Via")) PageTitle.Text += NavigationContext.QueryString["Via"] + "-"; PageTitle.Text += NavigationContext.QueryString["Sosire"]; Ruta = RouteResultsPage.Rute.ElementAt(Int32.Parse(NavigationContext.QueryString["Index"])); DataContext = this; Services = new List<ServiceType>(Ruta.Trenuri.Count); foreach (var tren in Ruta.Trenuri) Services.Add(ServiceType.Clasa2); ActivateLoading(); var webClient = new WebClient(); webClient.DownloadStringCompleted += webClient_DownloadStringCompleted; webClient.DownloadStringAsync(new Uri(Ruta.Pret.Url)); }
private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { var root = XDocument.Parse(e.Result, LoadOptions.None).Element("Rute"); foreach (var rutaInfo in root.Elements("Ruta")) { var ruta = new Ruta(); ruta.Trenuri = new List<Tren>(); ruta.Pret = new Pret(); ruta.Sinteza = new Sinteza(); if (rutaInfo.Element("Pret").Value.Trim() == "Da") ruta.Pret.Url = baseUri + rutaInfo.Element("Pret").Attribute("ref").Value; ruta.Sinteza.Distanta = rutaInfo.Element("Sinteza").Attribute("km").Value; ruta.Sinteza.Durata = rutaInfo.Element("Sinteza").Attribute("min").Value; foreach (var trenInfo in rutaInfo.Elements("Tren")) { var tren = new Tren(); tren.EstePrivat = trenInfo.Attribute("tip").Value.Trim() == "Prt"; tren.ITren = new InfoTren { Tip = trenInfo.Element("Itren").Attribute("tip").Value.Trim(), Url = baseUri + "/" + trenInfo.Element("Itren").Attribute("ref").Value.Trim(), Numar = trenInfo.Element("Itren").Attribute("nr").Value.Trim() }; tren.Servicii = trenInfo.Element("Servicii").Value.Trim().Split(' ').Select(t => { switch (t) { case "b": return ServiceType.Clasa1; case "c": return ServiceType.Cuseta; case "e": return ServiceType.Dormitor; case "a": default: return ServiceType.Clasa2; } }).ToList(); tren.Plecare = new Gara { Nume = trenInfo.Element("Plecare").Attribute("sta").Value.Trim(), Ora = trenInfo.Element("Plecare").Attribute("ora").Value.Trim(), Url = baseUri + trenInfo.Element("Plecare").Attribute("ref").Value.Trim() }; tren.Sosire = new Gara { Nume = trenInfo.Element("Sosire").Attribute("sta").Value.Trim(), Ora = trenInfo.Element("Sosire").Attribute("ora").Value.Trim(), Url = baseUri + trenInfo.Element("Sosire").Attribute("ref").Value.Trim() }; tren.Asteptare = trenInfo.Element("Asteptare").Attribute("min").Value; var restrictii = trenInfo.Element("Restrictii").Element("Are"); if (restrictii != null) tren.Restrictie = new Restrictie { Url = baseUri + restrictii.Attribute("ref").Value.Trim() }; else tren.Restrictie = new Restrictie(); var firma = trenInfo.Element("Operator"); if (firma != null) tren.Operator = new Operator { Nume = firma.Attribute("nume").Value.Trim(), Url = firma.Attribute("ref").Value.Trim() }; else tren.Operator = new Operator { Nume = "SNTFC 'CFR Calatori' SA", Url = "http://www.cfrcalatori.ro" }; ruta.Trenuri.Add(tren); } foreach (var tren in ruta.Trenuri) { if (tren.EstePrivat) { ruta.ContinePrivat = true; ruta.Firma = tren.Operator.Nume; } } if (!ruta.ContinePrivat) ruta.Firma = "SNTFC 'CFR Calatori' SA"; ruta.EsteDirect = ruta.Trenuri.Count == 1; ruta.OraPlecare = ruta.Trenuri.First().Plecare.Ora; ruta.OraSosire = ruta.Trenuri.Last().Sosire.Ora; Rute.Add(ruta); } if (Rute.Count == 0) { RuteNegasite.Visibility = Visibility.Visible; } DeactivateLoading(); }