public List <Waypoint> GetWayppoints(GPS gps, string fileName) { return(Waypoints[gps].Where(t => t.FullFileName == fileName).FirstOrDefault().Waypoints); }
public EntityValidationResult ValidateGPS(GPS gps, bool isNew, string oldAssignedName = "", string oldCode = "", bool fromImport = false, bool fromArchive = false) { EntityValidationResult evr = new EntityValidationResult(); if (isNew && (gps.DeviceName == null || gps.DeviceName.Length < 5)) { evr.AddMessage("Device name cannot be empty and must be at least 5 letters long"); } if (isNew && (gps.Code == null || gps.Code.Length > 6)) { evr.AddMessage("Device code cannot be empty and must not exceed 6 letters long"); } if (gps.Brand == null || gps.Brand.Length == 0) { evr.AddMessage("Brand cannot be empty"); } if (gps.Model == null || gps.Model.Length == 0) { evr.AddMessage("Model cannot be empty"); } if (gps.Folder == null || gps.Folder.Length == 0) { evr.AddMessage("Folder cannot be empty"); } else if (!fromArchive && !fromImport && !Directory.Exists($"{gps.Device.Disks[0].Caption}\\{gps.Folder}")) { evr.AddMessage("GPX folder does not exist"); } if (!isNew && gps.DeviceName.Length > 0 && oldAssignedName != gps.DeviceName && GPSDeviceNameExist(gps.DeviceName)) { evr.AddMessage("Device name already used"); } if (!isNew && gps.Code.Length > 0 && oldCode != gps.Code && GPSCodeExist(gps.Code)) { evr.AddMessage("Device code already used"); } if (isNew && gps.Code != null && gps.Code.Length > 0 && GPSCodeExist(gps.Code)) { evr.AddMessage("Device code already used"); } if (isNew && gps.DeviceName != null && gps.DeviceName.Length > 0 && GPSDeviceNameExist(gps.DeviceName)) { evr.AddMessage("Device name already used"); } return(evr); }
//public List<Waypoint>ReadWaypointFromDeviceGPX1(DeviceGPX deviceGPX) //{ // List<Waypoint> wpts = new List<Waypoint>(); // using (XmlReader reader = XmlReader.Create(new StringReader(deviceGPX.GPX))) // { // while (reader.Read()) // { // if (reader.IsStartElement()) // { // if (reader.Name == "wpt") // { // Waypoint namedWaypoint = new Waypoint(); // namedWaypoint.Read(reader); // namedWaypoint.GPXFileName = Path.GetFileName(deviceGPX.Filename); // wpts.Add(namedWaypoint); // } // } // } // } // return wpts; //} public List <Waypoint> ReadWaypointsFromFile(DeviceGPX deviceGPX = null, bool waypointsOnly = false) { GPS gps = deviceGPX.GPS; string filename = deviceGPX.Filename; List <Waypoint> wpts = new List <Waypoint>(); using (XmlReader reader = XmlReader.Create(new StringReader(deviceGPX.GPX))) { while (reader.Read()) { if (reader.IsStartElement()) { if (reader.Name == "wpt") { Waypoint namedWaypoint = new Waypoint(); namedWaypoint.Read(reader); namedWaypoint.GPXFileName = Path.GetFileName(deviceGPX.Filename); wpts.Add(namedWaypoint); } } } } if (!waypointsOnly) { if (wpts.Count > 0) { GPSWaypointSet gws = new GPSWaypointSet { GPS = gps, FullFileName = filename, Waypoints = wpts }; if (Waypoints.Count == 0) { var list = new List <GPSWaypointSet>(); list.Add(gws); Waypoints.Add(gps, list); } else { if (Waypoints.ContainsKey(gps)) { if (Waypoints[gps].Where(t => t.FileName == gws.FileName).FirstOrDefault() == null) { Waypoints[gps].Add(gws); } } else { var list = new List <GPSWaypointSet>(); list.Add(gws); Waypoints.Add(gps, list); } } } } return(wpts); }
public GPS GetGPS(string deviceID) { CurrentEntity = GPSCollection.FirstOrDefault(n => n.DeviceID == deviceID); return(CurrentEntity); }
//public List<GPS>GetAvailableGPS() //{ //} public int ImportGPS(string xmlFile, out string message) { GPS gps = null; int importedCount = 0; string xml = File.OpenText(xmlFile).ReadToEnd(); message = Global.IsValidXMLFile(xmlFile); if (message != "Valid XML") { return(0); } using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { while (reader.Read()) { if (reader.IsStartElement()) { if (reader.Name == "GPSEdited") { gps = new GPS(); gps.Folder = ""; } switch (reader.Name) { case "DeviceID": gps.DeviceID = XMLValue(reader); break; case "DeviceName": gps.DeviceName = XMLValue(reader); break; case "Code": gps.Code = XMLValue(reader); break; case "Brand": gps.Brand = XMLValue(reader); break; case "Model": gps.Model = XMLValue(reader); break; case "Folder": gps.Folder = XMLValue(reader); break; } if (gps != null && gps.Folder.Length > 0 && GetGPSEx(gps.DeviceID) == null) { var validationResult = ValidateGPS(gps, isNew: true, fromImport: true); if (validationResult.ErrorMessage.Length == 0 && AddRecordToRepo(gps)) { importedCount++; gps = null; } } } } } return(importedCount); }
public bool Exists(GPS gps) { return(GPSCollection.Where(t => t.DeviceID == gps.DeviceID).FirstOrDefault() != null); }
public GPS GetGPSByName(string deviceName) { CurrentEntity = GPSCollection.FirstOrDefault(n => n.DeviceName == deviceName); return(CurrentEntity); }
public DeviceGPX GetDeviceGPX(GPS gps, DateTime month_year) { return(DeviceGPXCollection .Where(t => t.GPS.DeviceID == gps.DeviceID) .FirstOrDefault()); }
public List <DeviceGPX> GetAllDeviceWaypointGPX(GPS gps) { return(DeviceGPXCollection.Where(t => t.GPS.DeviceID == gps.DeviceID).ToList()); }
public DeviceGPX GetDeviceGPX(GPS gps) { return(DeviceGPXCollection .Where(t => t.GPS.DeviceID == gps.DeviceID) .FirstOrDefault()); }
public void RefreshArchivedGPXCollection(GPS gps) { ConvertDeviceGPXInArchiveToGPXFile(gps);; }
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); }
public TripEdited(GPS gps) { GPS = gps; DeviceID = GPS.DeviceID; Track = new Track(); }
public List <Trip> TripsUsingGPSByDate(GPS gps, DateTime date) { return(Entities.TripViewModel.TripCollection .Where(t => t.GPS.DeviceID == gps.DeviceID) .Where(t => t.DateTimeDeparture.Date == date.Date).ToList()); }