public async static Task<FlightPlanViewModel> CreateAsync(FlightPlan flightPlan) { var fpvm = new FlightPlanViewModel(App.DataSourceManager); fpvm.flightPlan = flightPlan; await fpvm.LoadWaypoints(); return fpvm; }
public static FlightPlan FromString(string s, IAirportDirectory directory) { var retval = new FlightPlan(); if(string.IsNullOrWhiteSpace(s)) { throw new ArgumentException("s"); } var wpTable = s.Split(Separator); retval.Waypoints = wpTable.Select(wp => directory.GetAirportData(wp)); return retval; }
public static FlightPlan FromString(string s, IAirportDirectory directory) { var retval = new FlightPlan(); if (string.IsNullOrWhiteSpace(s)) { throw new ArgumentException("s"); } var wpTable = s.Split(Separator); retval.Waypoints = wpTable.Select(wp => directory.GetAirportData(wp)); return(retval); }
public async Task LoadAsync() { var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder; StorageFile fpFile = null; bool fileCreationNeeded = false; var plans = new List <FlightPlan>(); try { fpFile = await roamingFolder.GetFileAsync(FlightPlanSource.FileName); using (var stream = await fpFile.OpenStreamForReadAsync()) { using (var reader = new StreamReader(stream)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { plans.Add(FlightPlan.FromString(line, this.airportDirectory)); } } } } this.FlightPlans = plans; } catch (FileNotFoundException) { Debug.WriteLine("No flight plans file. Creating one."); fileCreationNeeded = true; } if (fileCreationNeeded) { fpFile = await roamingFolder.CreateFileAsync(FlightPlanSource.FileName); } }