private async void Page_Loaded(object sender, RoutedEventArgs e) { VehicleRootObject results = await VehicleResult.GetVehicleResult(vehicleId); //string r = results.Results[0].FrontCrashDriversideRating; //convert to int Int32.TryParse(results.Results[0].FrontCrashDriversideRating, out fcdrR); Int32.TryParse(results.Results[0].FrontCrashPassengersideRating, out fcprR); Int32.TryParse(results.Results[0].SideCrashDriversideRating, out scdrR); Int32.TryParse(results.Results[0].SideCrashPassengersideRating, out scprR); Int32.TryParse(results.Results[0].RolloverRating2, out rollR); // set ratings ctx to data from api this.fcdrRating.DataContext = new RatingViewModel() { RatingValue = fcdrR }; this.fcprRating.DataContext = new RatingViewModel() { RatingValue = fcprR }; this.scdrRating.DataContext = new RatingViewModel() { RatingValue = scdrR }; this.scprRating.DataContext = new RatingViewModel() { RatingValue = scprR }; this.rollRating.DataContext = new RatingViewModel() { RatingValue = rollR }; TxtBoxDesc.Text = results.Results[0].VehicleDescription; TxtBoxFcdr.Text = "Front crash driver side rating: "; TxtBoxFcpr.Text = "Front crash passenger side rating: "; TxtBoxScdr.Text = "Side crash driver side rating: "; TxtBoxScpr.Text = "Side crash passenger side rating: "; TxtBoxRoll.Text = "Rollover rating: "; TxtBoxComplaints.Text = results.Results[0].ComplaintsCount.ToString(); TxtBoxRecalls.Text = results.Results[0].InvestigationCount.ToString(); if (results.Results[0].SideCrashPicture != null) { ImgCarCrash.Source = new BitmapImage(new Uri(results.Results[0].SideCrashPicture)); Debug.WriteLine("in if"); } else { //ImgCarCrash.Source = new BitmapImage(new Uri("ms-appx:///Assets/img/default.jpg")); Debug.WriteLine("in else"); Debug.WriteLine("URL: " + results.Results[0].SideCrashPicture); } }
//returns dictionary of vehicle statuses private async Task <Dictionary <int, Vehicle> > getVehicleStatusesAsync() { string url = "http://feeds.transloc.com/3/vehicle_statuses.jsonp" + "?agencies={0}" + "&callback=?"; Dictionary <int, Vehicle> vehicles = new Dictionary <int, Vehicle>(); string queryUrl = string.Format(url, agency); string translocResult = await client.GetStringAsync(queryUrl); translocResult = translocResult.Substring(2, translocResult.Length - 4); VehicleRootObject apiData = JsonConvert.DeserializeObject <VehicleRootObject>(translocResult); if (apiData != null) { foreach (Vehicle v in apiData.vehicles) { vehicles.Add(v.id, v); } } return(vehicles); }