static int TaskWorker4Info(GpxFile gpx, GpxInfos[] infos, int idx, CancellationTokenSource cancel, IProgress <string> progress) { TaskProgress4Info(string.Format("ermittle Infos zu {0} ...", gpx.Filename)); infos[idx] = new GpxInfos(gpx); TaskProgress4Info(string.Format("Infos zu {0} ermittelt", gpx.Filename)); return(0); }
/// <summary> /// gibt Infos für eine GPX-Datei aus /// </summary> /// <param name="info"></param> static void ShowInfoOnStdOut(GpxInfos info) { Console.WriteLine("Datei '{0}'", info.Filename); Console.WriteLine("{0} Waypoint/s", info.WaypointCount); for (int i = 0; i < info.WaypointCount; i++) { Console.WriteLine(" Waypoint {0}: {1}", i + 1, info.Waypointname[i]); } Console.WriteLine("{0} Route/n", info.RouteCount); for (int i = 0; i < info.RouteCount; i++) { Console.WriteLine(" Waypoint {0}: {1}", i + 1, info.Routename[i]); } Console.WriteLine("{0} Track/s", info.TrackCount); for (int t = 0; t < info.TrackCount; t++) { GpxInfos.TrackInfo ti = info.Tracks[t]; Console.WriteLine(" Track {0}: {1}", t + 1, ti.Trackname); for (int s = 0; s < info.Tracks[t].SegmentCount; s++) { GpxInfos.TrackInfo.SegmentInfo si = ti.Segment[s]; Console.Write(" Segment {0}: {1} Punkte, {2:N3}km", s + 1, si.PointCount, si.Length / 1000); if (si.Minheight != double.MaxValue) { Console.Write(", Höhe {0:F0} .. {1:F0}m, Anstieg {2:F0}, Abstieg {3:F0}", si.Minheight, si.Maxheight, si.Descent, si.Ascent); } if (si.AverageSpeed > 0) { Console.Write(", Durchschnittsgeschw. {0:F1}km/h", si.AverageSpeed * 3.6); } Console.WriteLine(); } } }
/// <summary> /// liest (und fügt die Dateien zusammen) und zeigt ev. Infos der Dateien an /// </summary> /// <param name="Inputfiles">Liste der Eingabedateien</param> /// <param name="destfile">Name der Zieldatei</param> /// <param name="showinfo">Dateiinfos anzeigen</param> /// <param name="simplify">GPX vereinfachen</param> /// <param name="gpxcreator">Creator der neuen Datei</param> /// <returns></returns> static GpxFileSpecial ReadAndMergeGpxfiles(List <string> Inputfiles, string destfile, bool showinfo, bool simplify, string gpxcreator) { GpxFileSpecial gpxfile = null; if (Inputfiles.Count == 1) { gpxfile = new GpxFileSpecial(Inputfiles[0]) { InternalGpx = simplify ? GpxFile.InternalGpxForm.OnlyPoorGpx : GpxFile.InternalGpxForm.NormalAndPoor }; gpxfile.Read(); if (showinfo) { ShowInfoOnStdOut(new GpxInfos(gpxfile, true)); } } else // > 1, dann implizit GpxFile.InternalGpxForm.OnlyPoorGpx bilden { gpxfiles = new GpxFile[Inputfiles.Count]; TaskQueue tq = new TaskQueue(); IProgress <string> progress = new Progress <string>(TaskProgress4Read); for (int i = 0; i < Inputfiles.Count; i++) { tq.StartTask(Inputfiles[i], i, TaskWorker4Read, progress, null); } tq.Wait4EmptyQueue(); if (tq.ExeptionMessage != "") { throw new Exception(tq.ExeptionMessage); } if (showinfo) { GpxInfos[] infos = new GpxInfos[gpxfiles.Length]; progress = new Progress <string>(TaskProgress4Info); for (int i = 0; i < gpxfiles.Length; i++) { tq.StartTask(gpxfiles[i], infos, i, TaskWorker4Info, progress, null); } tq.Wait4EmptyQueue(); if (tq.ExeptionMessage != "") { throw new Exception(tq.ExeptionMessage); } for (int i = 0; i < infos.Length; i++) { ShowInfoOnStdOut(infos[i]); } } // alle Dateien zusammenfügen if (destfile.Length > 0) { gpxfile = new GpxFileSpecial(Inputfiles[0], gpxcreator) { InternalGpx = GpxFile.InternalGpxForm.OnlyPoorGpx }; // nur Name der 1. Datei, aber nicht einlesen ! for (int i = 0; i < Inputfiles.Count; i++) { Console.Error.WriteLine("füge Daten aus {0} ein", Inputfiles[i]); gpxfile.Concat(gpxfiles[i]); } } } return(gpxfile); }