public List <WaypointLocalTime> GetWaypointsMatch(GPXFile trackFile, out List <GPXFile> gpxFiles) { gpxFiles = new List <GPXFile>(); var thisList = new List <WaypointLocalTime>(); foreach (var g in GPXFileCollection .Where(t => t.GPXFileType == GPXFileType.Waypoint) .Where(t => t.GPS.DeviceID == trackFile.GPS.DeviceID) ) { foreach (var wpt in g.NamedWaypointsInLocalTime) { if (wpt.Time >= trackFile.DateRangeStart && wpt.Time <= trackFile.DateRangeEnd) { thisList.Add(wpt); if (!gpxFiles.Contains(g)) { gpxFiles.Add(g); } } } } return(thisList); }
private void GPXFileCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { int newIndex = e.NewStartingIndex; GPXFile newFile = GPXFileCollection[newIndex]; CurrentEntity = newFile; } break; case NotifyCollectionChangedAction.Remove: { //List<GPS> tempListOfRemovedItems = e.OldItems.OfType<GPS>().ToList(); //GPSes.Delete(tempListOfRemovedItems[0].Code); } break; case NotifyCollectionChangedAction.Replace: { //List<GPS> tempList = e.NewItems.OfType<GPS>().ToList(); //GPSes.Update(tempList[0]); // As the IDs are unique, only one row will be effected hence first index only } break; } }
public void Add(GPXFile file) { if (file == null) { throw new ArgumentNullException("Error: The argument is Null"); } GPXFileCollection.Add(file); }
public List<WaypointLocalTime> GetWaypoints(GPXFile wayppointFile) { if (wayppointFile.TrackCount == 0 && wayppointFile.NamedWaypointsInLocalTime.Count > 0) { return wayppointFile.NamedWaypointsInLocalTime; } return null; }
public GPXFile ConvertToGPXFile(DeviceGPX deviceGPX) { GPXFile gpxFile = new GPXFile(deviceGPX.Filename); gpxFile.GPS = deviceGPX.GPS; gpxFile.ComputeStats(deviceGPX); gpxFile.XML = deviceGPX.GPX; return(gpxFile); }
private void AddToDictionary(GPS gps, GPXFile gpxFile) { if (!ArchivedGPXFiles.Keys.Contains(gps)) { ArchivedGPXFiles.Add(gps, new List<GPXFile>()); } if (ArchivedGPXFiles[gps].FirstOrDefault(t => t.FileName == gpxFile.FileName) == null) { ArchivedGPXFiles[gps].Add(gpxFile); } }
/// <summary> /// Saves gpx files in device to database /// </summary> /// <param name="device"></param> public bool SaveDeviceGPXToRepository(DetectedDevice device) { bool successSave = false; foreach (var file in Entities.GPXFileViewModel.GetGPXFilesFromGPS(device)) { string content; using (StreamReader sr = File.OpenText(file.FullName)) { content = sr.ReadToEnd(); content = AddGPSSourceToGPX(content, device.GPS); var gpxFileName = Path.GetFileName(file.FullName); var dwg = GetDeviceGPX(device.GPS, gpxFileName); GPXFile gpxFile = Entities.GPXFileViewModel.GetFile(device.GPS, gpxFileName); var gpxType = gpxFile.GPXFileType == GPXFileType.Track ? "track" : "waypoint"; if (dwg == null) { successSave = AddRecordToRepo( new DeviceGPX { GPS = device.GPS, Filename = gpxFileName, GPX = content, RowID = NextRecordNumber, MD5 = CreateMD5(content), GPXType = gpxType, TimeRangeStart = gpxFile.DateRangeStart, TimeRangeEnd = gpxFile.DateRangeEnd } ); } else { var deviceMD5 = CreateMD5(content); if (CreateMD5(dwg.GPX) != deviceMD5) { successSave = UpdateRecordInRepo(new DeviceGPX { GPS = dwg.GPS, GPX = content, Filename = dwg.Filename, RowID = dwg.RowID, MD5 = deviceMD5, GPXType = gpxType, TimeRangeStart = gpxFile.DateRangeStart, TimeRangeEnd = gpxFile.DateRangeEnd }); } } } } return(successSave); }
public GPXFile ConvertToGPXFile(DeviceGPX deviceGPX) { if (deviceGPX != null) { GPXFile gpxFile = new GPXFile(deviceGPX.Filename); gpxFile.RowID = deviceGPX.RowID; gpxFile.GPS = deviceGPX.GPS; gpxFile.ComputeStats(deviceGPX); gpxFile.XML = deviceGPX.GPX; return(gpxFile); } return(null); }
public void Update(GPXFile file) { if (file.FileName == null) { throw new Exception("Error: File name cannot be null"); } int index = 0; while (index < GPXFileCollection.Count) { if (GPXFileCollection[index].FileName == file.FileName) { GPXFileCollection[index] = file; break; } index++; } }
public bool AddRecordToRepo(DeviceGPX gpx) { int oldCount = DeviceGPXCollection.Count; if (gpx == null) throw new ArgumentNullException("Error: The argument is Null"); DeviceGPXCollection.Add(gpx); if (_editSuccess) { GPXFile gpxFile = Entities.GPXFileViewModel.GetFile(gpx.GPS, gpx.Filename); if (gpxFile == null) { gpxFile = new GPXFile(gpx.Filename) { GPS = gpx.GPS, XML = gpx.GPX }; gpxFile.ComputeStats(gpx); Entities.GPXFileViewModel.Add(gpxFile); } AddToDictionary(gpx.GPS, gpxFile); } return DeviceGPXCollection.Count > oldCount; }
public void GetFilesFromDevice(DetectedDevice device) { if (!_gpsFinishedReadingFiles.Contains(device.GPS)) { var gpxFolder = $"{device.Disks[0].Caption }\\{ device.GPS.Folder}"; if (Directory.Exists(gpxFolder)) { List <FileInfo> myFiles = new DirectoryInfo(gpxFolder) .EnumerateFiles() .Where(f => f.Extension == ".gpx").ToList(); foreach (var file in myFiles) { string xml = File.OpenText(file.FullName).ReadToEnd(); DeviceGPX dg = new DeviceGPX { GPX = xml, Filename = file.Name, GPS = device.GPS }; Entities.WaypointViewModel.ReadWaypointsFromFile(dg); GPXFile gf = new GPXFile(file) { GPS = device.GPS, DriveName = device.Disks[0].Caption, XML = xml }; if (!Contains(gf)) { Add(gf); gf.ComputeStats(); } } } _gpsFinishedReadingFiles.Add(device.GPS); } }
public bool Contains(GPXFile file) { return(GPXFileCollection .Where(t => t.GPS.DeviceID == file.GPS.DeviceID) .Where(t => t.FileName == file.FileName).FirstOrDefault() != null); }
private static int ImportGPX(string folder, GPS in_gps = null, bool first = false, int startYear = 2019) { if (first) { _count = 0; } GPS gps = null; GPS current_gps = null; var files = Directory.GetFiles(folder).Select(s => new FileInfo(s)); if (files.Any()) { foreach (var file in files) { if (file.Extension.ToLower() == ".gpx") { var folderName = System.IO.Path.GetFileName(folder); if (ImportGPSData.GPSNameStart.Length > 0) { gps = Entities.GPSViewModel.GetGPS($"{ImportGPSData.GPSNameStart} {GetNumericPartOfFolderName(folderName)}"); } else { gps = Entities.GPSViewModel.GetGPSByName(folderName); } if (gps != null) { current_gps = gps; } else if (gps == null && in_gps != null) { current_gps = in_gps; } if (current_gps != null) { GPXFile g = new GPXFile(file); g.GPS = current_gps; if (g.ComputeStats()) { if (g.DateRangeStart.Year >= startYear) { DeviceGPX d = new DeviceGPX { Filename = file.Name, GPS = current_gps, GPX = g.XML, GPXType = g.GPXFileType == GPXFileType.Track ? "track" : "waypoint", RowID = Entities.DeviceGPXViewModel.NextRecordNumber, MD5 = CreateMD5(g.XML), TimeRangeStart = g.DateRangeStart, TimeRangeEnd = g.DateRangeEnd }; string fileProcessed = $@"{current_gps.DeviceName}:{file.FullName}"; DeviceGPX saved = Entities.DeviceGPXViewModel.GetDeviceGPX(d); if (saved == null) { if (Entities.DeviceGPXViewModel.AddRecordToRepo(d)) { _count++; fileProcessed += " (ADDED)"; } } else { if (saved.MD5 != d.MD5 && d.TimeRangeEnd > saved.TimeRangeEnd) { Entities.DeviceGPXViewModel.UpdateRecordInRepo(d); fileProcessed += " (MODIFIED ADDED)"; } else { fileProcessed += " (DUPLICATE)"; } } Console.WriteLine(fileProcessed); } else { Logger.Log($"GPX year for {file.FullName} is less than {startYear}"); } } else { Logger.Log($"Error in computing stats for {file.FullName}"); } } } } } foreach (var dir in Directory.GetDirectories(folder)) { ImportGPX(dir, current_gps); } return(_count); }
private static int ImportGPXByFolder(string folder, GPS in_gps = null, bool?first = false, int yearStartProcess = 2019) { if ((bool)first) { Logger.LogType = LogType.ImportGPXfFromFolder; _count = 0; _gpxCount = 0; } GPS gps = null; GPS current_gps = null; if (in_gps != null) { gps = in_gps; current_gps = in_gps; } //Logger.Log($"processing folder: {folder}"); var folderName = System.IO.Path.GetFileName(folder); //if (ImportGPSData.GPSNameStart.Length > 0) //{ string result = GetNumericPartOfFolderName(folderName); if (result.Length > 0) { int numericPart = int.Parse(result); if (numericPart >= ImportGPSData.StartGPSNumbering && numericPart <= ImportGPSData.EndGPSNumbering) { gps = Entities.GPSViewModel.GetGPS($"{ImportGPSData.GPSNameStart} {GetNumericPartOfFolderName(folderName)}"); } else { return(0); } } //int numericPart = int.Parse(GetNumericPartOfFolderName(folderName)); //} //else //{ // gps = Entities.GPSViewModel.GetGPSByName(folderName); //} if (gps != null) { current_gps = gps; } else if (gps == null && in_gps != null) { current_gps = in_gps; } var files = Directory.GetFiles(folder).Select(s => new FileInfo(s)); if (files.Any()) { foreach (var file in files) { if (file.Extension.ToLower() == ".gpx") { //var folderName = System.IO.Path.GetFileName(folder); //if(ImportGPSData.GPSNameStart.Length>0) //{ // string result = GetNumericPartOfFolderName(folderName); // if (result.Length > 0) // { // int numericPart = int.Parse(result); // if (numericPart >= ImportGPSData.StartGPSNumbering && numericPart <= ImportGPSData.EndGPSNumbering) // { // gps = Entities.GPSViewModel.GetGPS($"{ImportGPSData.GPSNameStart} {GetNumericPartOfFolderName(folderName)}"); // } // else // { // return 0; // } // } // //int numericPart = int.Parse(GetNumericPartOfFolderName(folderName)); //} //else { // gps = Entities.GPSViewModel.GetGPSByName(folderName); //} //if (gps != null) //{ // current_gps = gps; //} //else if (gps == null && in_gps != null) //{ // current_gps = in_gps; //} if (current_gps != null) { _gpxCount++; GPXFile g = new GPXFile(file); g.GPS = current_gps; if (g.ComputeStats()) { if (g.DateRangeStart.Year >= yearStartProcess) { DeviceGPX d = new DeviceGPX { Filename = file.Name, GPS = current_gps, GPX = g.XML, GPXType = g.GPXFileType == GPXFileType.Track ? "track" : "waypoint", RowID = Entities.DeviceGPXViewModel.NextRecordNumber, MD5 = CreateMD5(g.XML), TimeRangeStart = g.DateRangeStart, TimeRangeEnd = g.DateRangeEnd }; string fileProcessed = $@"{current_gps.DeviceName}:{file.FullName}"; DeviceGPX saved = Entities.DeviceGPXViewModel.GetDeviceGPX(d); if (saved == null) { if (Entities.DeviceGPXViewModel.AddRecordToRepo(d)) { _count++; fileProcessed += " (ADDED)"; EventHandler <ImportGPXEventArg> importEvent = ImportGPXEvent; if (importEvent != null) { ImportGPXEventArg e = new ImportGPXEventArg { Intent = "gpx saved", GPS = current_gps, ImportedCount = _count, GPXFileName = file.Name }; importEvent(null, e); } } } else { if (saved.MD5 != d.MD5 && d.TimeRangeEnd > saved.TimeRangeEnd) { if (Entities.DeviceGPXViewModel.UpdateRecordInRepo(d)) { EventHandler <ImportGPXEventArg> importEvent = ImportGPXEvent; if (importEvent != null) { ImportGPXEventArg e = new ImportGPXEventArg { Intent = "gpx file modified", GPS = current_gps, ImportedCount = _count, GPXFileName = file.Name }; importEvent(null, e); } } fileProcessed += " (MODIFIED ADDED)"; } else { EventHandler <ImportGPXEventArg> importEvent = ImportGPXEvent; if (importEvent != null) { ImportGPXEventArg e = new ImportGPXEventArg { Intent = "gpx file duplicate", GPS = current_gps, ImportedCount = _count, GPXFileName = file.Name }; importEvent(null, e); } fileProcessed += " (DUPLICATE)"; } } //Console.WriteLine(fileProcessed); Logger.Log(fileProcessed); } else { Logger.Log($"GPX file {file.FullName} time is {g.DateRangeEnd.ToString("MMM-dd-yyyy")} and is not saved"); } } else { Logger.Log($"Error computing stats for GPX file {file.FullName} and is not saved"); } } } } } foreach (var dir in Directory.GetDirectories(folder)) { ImportGPXByFolder(dir, current_gps); } return(_count); }
public int ImportGPX(string folder, GPS in_gps = null, bool first = false) { if (first) { _count = 0; } GPS gps = null; GPS current_gps = null; var files = Directory.GetFiles(folder).Select(s => new FileInfo(s)); if (files.Any()) { foreach (var file in files) { if (file.Extension.ToLower() == ".gpx") { var folderName = Path.GetFileName(folder); gps = Entities.GPSViewModel.GetGPSByName(folderName); if (gps != null) { current_gps = gps; } else if (gps == null && in_gps != null) { current_gps = in_gps; } if (current_gps != null) { GPXFile g = new GPXFile(file); g.GPS = current_gps; g.ComputeStats(); DeviceGPX d = new DeviceGPX { Filename = file.Name, GPS = current_gps, GPX = g.XML, GPXType = g.GPXFileType == GPXFileType.Track ? "track" : "waypoint", RowID = NextRecordNumber, MD5 = CreateMD5(g.XML), TimeRangeStart = g.DateRangeStart, TimeRangeEnd = g.DateRangeEnd }; string fileProcessed = $@"{current_gps.DeviceName}:{file.FullName}"; DeviceGPX saved = GetDeviceGPX(d); if (saved == null) { if (AddRecordToRepo(d)) { _count++; fileProcessed += " (ADDED)"; } } else { if (saved.MD5 != d.MD5 && d.TimeRangeEnd > saved.TimeRangeEnd) { UpdateRecordInRepo(d); fileProcessed += " (MODIFIED ADDED)"; } else { fileProcessed += " (DUPLICATE)"; } } Console.WriteLine(fileProcessed); } } } } foreach (var dir in Directory.GetDirectories(folder)) { ImportGPX(dir, current_gps); } return(_count); }