private async Task<int> GetPinPointsAsync() { List<Locations> Loc = new List<Locations>(); List<Locations> TempLoc = new List<Locations>(); foreach (AddressLine items in Addresses.ItemContainerGenerator.Items) { if (items.AddressLine1.Text == "Address Line 1") items.AddressLine1.Text = ""; if (items.City.Text == "City") items.City.Text = ""; if (items.ZIP.Text == "Zip Code") items.ZIP.Text = ""; Address tempAddress = new Address(items.AddressLine1.Text, items.City.Text, items.State.Text, items.ZIP.Text); Task<List<Locations>> TLoc = tempAddress.getLocations(); TempLoc = await TLoc; if (TempLoc.Count > 0) { Loc.Add(TempLoc[0]); } } if (Loc.Count != 0) { StaticMap_Request_Classes.StaticMap pinpointMap = await Task.Run(() => new StaticMap_Request_Classes.StaticMap(Loc)); MainMap = pinpointMap.map; MemoryStream ms = new MemoryStream(); await Task.Run(() =>MainMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)); ms.Position = 0; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); image.Source = bi; } return 1; }
//aarnold 4/9 //asynchronous method that will cause the data to be sent and receive asyn. //tsage 4/2 PDT I.B.1.h.(4) private async Task<List<Maneuver>> GetDataAsync(bool shortestTime, List<DirectionsRequest.Avoids> toAvoid, StaticMap_Request_Classes.StaticMap.MapType typeOfMap) { //aarnold 4/2 Project Dev Tree - II.E.1 and 2 Loading(); UserManeuvers.Clear(); Narrative.Clear(); List<Locations> Loc = new List<Locations>(); List<Locations> TempLoc = new List<Locations>(); foreach (AddressLine items in Addresses.ItemContainerGenerator.Items) { if (items.AddressLine1.Text == "Address Line 1") items.AddressLine1.Text = ""; if (items.City.Text == "City") items.City.Text = ""; if (items.ZIP.Text == "Zip Code") items.ZIP.Text = ""; Address tempAddress = new Address(items.AddressLine1.Text, items.City.Text, items.State.Text, items.ZIP.Text); Task<List<Locations>> TLoc = tempAddress.getLocations(); TempLoc = await TLoc; if (TempLoc.Count > 0) { Loc.Add(TempLoc[0]); } } //tsage end 4/2 Directions UserInput = new Directions(); if(Loc.Count != 0) if (shortestTime == true) { //aarnold 4/16 UserInput = await Task.Run(() =>DirectionsRequest.getDirections(Loc, typeOfMap, DirectionsRequest.RouteType.Fastest, DirectionsRequest.DrivingStyle.Normal, toAvoid)); } else { //aarnold 4/16 UserInput = await Task.Run(() =>DirectionsRequest.getDirections(Loc, typeOfMap, DirectionsRequest.RouteType.Shortest, DirectionsRequest.DrivingStyle.Normal, toAvoid)); } //end aarnold 4/2 if (UserInput.legs.Count != 0) { try { MainMap = UserInput.mainMap; MemoryStream ms = new MemoryStream(); await Task.Run(() => MainMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)); ms.Position = 0; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); image.Source = bi; } catch (System.Net.WebException e) { } } List<Maneuver> TempManeuvers = new List<Maneuver>(); List<Maneuver> Temp = new List<Maneuver>(); foreach (Leg items in UserInput.legs) { if (items.maneuvers.Count == 0) return TempManeuvers; Temp = items.maneuvers; foreach (var item in Temp) { TempManeuvers.Add(item); } } if (UserInput.legs.Count != 0) { Distance = UserInput.distance; Time = UserInput.formattedTime; } DistancePlace.Text = Convert.ToString(Distance); TotalTime.Text = Time; if (Loc.Count == 0 || Loc.Count == 1) TempManeuvers.Clear(); NotLoading(); return TempManeuvers; //foreach (var item in TempManeuvers) // UserManeuvers.Add(item); //Jyoder 3/12 //List<Locations> Loc = Locations.getLocations() //List<Locations> Loc1 = Locations.getLocations(AddressLine1.Text, City1.Text, State1.Text, ZIP1.Text); //List<Locations> Loc2 = Locations.getLocations(AddressLineOne.Text, City2.Text, State2.Text, ZIP2.Text); //Directions UserInput = Directions.getDirections(Loc1[0], Loc2[0]); //string test = UserInput.legs[0].maneuvers[3].getMap(); //List<Maneuver> TempManeuvers = UserInput.legs[0].maneuvers; //string var = TempManeuvers[0].iconUrl; //foreach (var item in TempManeuvers) // UserManeuvers.Add(item); //foreach (var items in UserManeuvers) // Narrative.Add(items.narrative); ////////////////////////////////// }
//aarnold start 4/9 private async void GetPinpoints_Click(object sender, RoutedEventArgs e) { //Causes the loading icon to appear Loading(); UserManeuvers.Clear(); List<Locations> Loc = new List<Locations>(); List<Locations> TempLoc = new List<Locations>(); foreach (AddressLine items in Addresses.ItemContainerGenerator.Items) { if (items.AddressLine1.Text == "Address Line 1") items.AddressLine1.Text = ""; if (items.City.Text == "City") items.City.Text = ""; if (items.ZIP.Text == "Zip Code") items.ZIP.Text = ""; Address tempAddress = new Address(items.AddressLine1.Text, items.City.Text, items.State.Text, items.ZIP.Text); Task<List<Locations>> TLoc = tempAddress.getLocations(); TempLoc = await TLoc; if (TempLoc.Count > 0) { Loc.Add(TempLoc[0]); } } if (Loc.Count != 0) { StaticMap_Request_Classes.StaticMap pinpointMap = await Task.Run(() =>new StaticMap_Request_Classes.StaticMap(Loc)); MainMap = pinpointMap.map; MemoryStream ms = new MemoryStream(); await Task.Run(() =>MainMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)); ms.Position = 0; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); image.Source = bi; } int a = await GetPinPointsAsync(); ////Causes theloading icon to diappear //NotLoading(); //UserManeuvers.Clear(); //Narrative.Clear(); NotLoading(); }