Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 public void Add(GPXFile file)
 {
     if (file == null)
     {
         throw new ArgumentNullException("Error: The argument is Null");
     }
     GPXFileCollection.Add(file);
 }
Exemplo n.º 4
0
 public List<WaypointLocalTime> GetWaypoints(GPXFile wayppointFile)
 {
     if (wayppointFile.TrackCount == 0 && wayppointFile.NamedWaypointsInLocalTime.Count > 0)
     {
         return wayppointFile.NamedWaypointsInLocalTime;
     }
     return null;
 }
Exemplo n.º 5
0
        public GPXFile ConvertToGPXFile(DeviceGPX deviceGPX)
        {
            GPXFile gpxFile = new GPXFile(deviceGPX.Filename);

            gpxFile.GPS = deviceGPX.GPS;
            gpxFile.ComputeStats(deviceGPX);
            gpxFile.XML = deviceGPX.GPX;
            return(gpxFile);
        }
Exemplo n.º 6
0
 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);
     }
 }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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++;
            }
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
 public bool Contains(GPXFile file)
 {
     return(GPXFileCollection
            .Where(t => t.GPS.DeviceID == file.GPS.DeviceID)
            .Where(t => t.FileName == file.FileName).FirstOrDefault() != null);
 }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }