public void TestCalculateStatistics_AllAssetTracks() { // set up string[] trackFilenames = { "waypoints.kml", "track_linestring.kmz", "tracks.gpx", "tracks.kmz", "85QA3ET1.igc", }; // run foreach (string trackFilename in trackFilenames) { string filename = Path.Combine(UnitTestHelper.TestAssetsPath, trackFilename); var geoDataFile = GeoLoader.LoadGeoDataFile(filename); var trackList = geoDataFile.GetTrackList(); for (int trackIndex = 0; trackIndex < trackList.Count; trackIndex++) { var track = geoDataFile.LoadTrack(trackIndex); if (track != null) { track.CalculateStatistics(); // check Assert.IsNotNull(track.Id, "track ID must not be null"); } } } }
/// <summary> /// Opens file from given stream. /// </summary> /// <param name="stream">stream object</param> /// <param name="filename"> /// filename; extension of filename is used to determine file type /// </param> /// <returns>task to wait on</returns> public static async Task OpenFileAsync(Stream stream, string filename) { if (Path.GetExtension(filename).ToLowerInvariant() == ".czml") { await ImportLayerFile(stream, filename); return; } if (Path.GetExtension(filename).ToLowerInvariant() == ".txt") { await ImportOpenAirAirspaceFile(stream, filename); return; } try { var geoDataFile = GeoLoader.LoadGeoDataFile(stream, filename); bool hasTracks = geoDataFile.GetTrackList().Any(); if (geoDataFile.HasLocations() && !hasTracks) { await ImportLocationListAsync(geoDataFile.LoadLocationList()); return; } if (!geoDataFile.HasLocations() && hasTracks) { await SelectAndImportTrackAsync(geoDataFile); return; } if (!geoDataFile.HasLocations() && !hasTracks) { await App.Current.MainPage.DisplayAlert( Constants.AppTitle, "No locations or tracks were found in the file", "OK"); return; } // file has both locations and tracks; ask user await AskUserImportLocationsOrTracks(geoDataFile); } catch (Exception ex) { App.LogError(ex); await App.Current.MainPage.DisplayAlert( Constants.AppTitle, "Error while opening file: " + ex.Message, "OK"); } }
public void TestLoadGeoDataFile_NonExistentFile() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "waypoints.abc"); // run + check Assert.ThrowsException <FileNotFoundException>(() => GeoLoader.LoadGeoDataFile(filename), "must throw exception"); }
public void TestLoadGeoDataFile_InvalidFileExtension() { // set up string filename = "waypoints.abc"; var stream = new MemoryStream(new byte[] { 42 }); // run + check Assert.ThrowsException <ArgumentException>(() => GeoLoader.LoadGeoDataFile(stream, filename), "must throw exception"); }
public void TestKml21File() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "kml21.kml"); // run var kmlFile = GeoLoader.LoadGeoDataFile(filename); // check Assert.IsTrue(kmlFile.HasLocations(), "file must have a location"); }
public void TestLoadGetDataFileIgc() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "85QA3ET1.igc"); // run var igcFile = GeoLoader.LoadGeoDataFile(filename); // check Assert.IsNotNull(igcFile, "loaded geo data file must not be null"); }
public void TestLoadGetDataFileGpx() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "tracks.gpx"); // run var gpxFile = GeoLoader.LoadGeoDataFile(filename); // check Assert.IsNotNull(gpxFile, "loaded geo data file must not be null"); }
public void TestLoadGetDataFileKml() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "waypoints.kml"); // run var kmlFile = GeoLoader.LoadGeoDataFile(filename); // check Assert.IsNotNull(kmlFile, "loaded geo data file must not be null"); }
public void TestGetTrackList() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "track_linestring.kmz"); var kmlFile = GeoLoader.LoadGeoDataFile(filename); // run var trackList = kmlFile.GetTrackList(); // check Assert.IsTrue(trackList.Any(), "track list must contain any tracks"); }
public void TestFileWithoutPlacemarks() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "tracks.kmz"); var kmlFile = GeoLoader.LoadGeoDataFile(filename); // run var locationList = kmlFile.LoadLocationList(); // check Assert.IsFalse(kmlFile.HasLocations(), "kml file must not contain locations"); Assert.IsFalse(locationList.Any(), "loaded location list must not contain locations"); }
public void TestLoadLocationListKmz() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "waypoints.kmz"); var kmlFile = GeoLoader.LoadGeoDataFile(filename); // run Assert.IsTrue(kmlFile.HasLocations(), "kml file must contain locations"); var locationList = kmlFile.LoadLocationList(); // check Assert.IsTrue(locationList.Any(), "loaded location list must contain locations"); }
public void TestLoadTrack() { // set up string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "track_linestring.kmz"); var kmlFile = GeoLoader.LoadGeoDataFile(filename); // run var track0 = kmlFile.LoadTrack(0); var track1 = kmlFile.LoadTrack(1); // check Assert.IsTrue(track0.TrackPoints.Any(), "track points list must not be empty"); Assert.IsTrue(track1.TrackPoints.Any(), "track points list must not be empty"); }
/// <summary> /// Opens and load location list from given stream object /// </summary> /// <param name="stream">stream object</param> /// <param name="filename"> /// filename; extension of filename is used to determine file type /// </param> /// <returns>task to wait on</returns> public static async Task OpenLocationListAsync(Stream stream, string filename) { await CloseWaitingPopupPageAsync(); waitingDialog = new WaitingPopupPage("Importing locations..."); try { await waitingDialog.ShowAsync(); var geoDataFile = GeoLoader.LoadGeoDataFile(stream, filename); var locationList = geoDataFile.HasLocations() ? geoDataFile.LoadLocationList() : null; if (locationList == null || !locationList.Any()) { await App.Current.MainPage.DisplayAlert( Constants.AppTitle, "No locations were found in the file", "OK"); return; } await ImportLocationListAsync(locationList); } catch (Exception ex) { App.LogError(ex); await App.Current.MainPage.DisplayAlert( Constants.AppTitle, "Error while loading locations: " + ex.Message, "OK"); return; } finally { await CloseWaitingPopupPageAsync(); } }
/// <summary> /// Opens and loads track from given stream object /// </summary> /// <param name="stream">stream object</param> /// <param name="filename"> /// filename; extension of filename is used to determine file type /// </param> /// <returns>true when loading track was successful, false when not</returns> public static async Task <bool> OpenTrackAsync(Stream stream, string filename) { waitingDialog = new WaitingPopupPage("Importing track..."); try { await waitingDialog.ShowAsync(); var geoDataFile = GeoLoader.LoadGeoDataFile(stream, filename); bool hasTracks = geoDataFile.GetTrackList().Any(); if (!hasTracks) { await App.Current.MainPage.DisplayAlert( Constants.AppTitle, "No tracks were found in the file", "OK"); return(false); } return(await SelectAndImportTrackAsync(geoDataFile)); } catch (Exception ex) { App.LogError(ex); await App.Current.MainPage.DisplayAlert( Constants.AppTitle, $"Error while loading track: {ex.Message}", "OK"); } finally { await CloseWaitingPopupPageAsync(); } return(false); }