示例#1
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                StringBuilder log  = new StringBuilder();
                FileInfo      fi   = new FileInfo(path);
                SensorFile    file = new SensorFile("kml", fi.Name, DateTime.Now);
                file.Save();

                Dictionary <DateTime, CoordinatePoint> points = new Dictionary <DateTime, CoordinatePoint>();
                ExtractPoints(ref points, doc);

                foreach (DateTime dt in points.Keys)
                {
                    file.AddReading(dt, points[dt].Latitude.Value, points[dt].Longitude.Value, points[dt].HeightAboveGeoID, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                }

                boat.AddFile(file);
                return(file);
            }
            catch //(Exception e)
            {
                return(null);
            }
        }
示例#2
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                StringBuilder log = new StringBuilder();
                FileInfo fi = new FileInfo(path);
                SensorFile file = new SensorFile("kml", fi.Name, DateTime.Now);
                file.Save();

                Dictionary<DateTime, CoordinatePoint> points = new Dictionary<DateTime, CoordinatePoint>();
                ExtractPoints(ref points, doc);

                foreach (DateTime dt in points.Keys)
                {
                    file.AddReading(dt, points[dt].Latitude.Value, points[dt].Longitude.Value, points[dt].HeightAboveGeoID, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                }

                boat.AddFile(file);
                return file;
            }
            catch //(Exception e)
            {
                return null;
            }
        }
示例#3
0
        private void AutoImportGpsDataFileParameters(Race race)
        {
            int number = 0;

            foreach (string gpsDataFile in _gpsDataFileParameters)
            {
                try
                {
                    AmphibianSoftware.VisualSail.Data.Boat b = new AmphibianSoftware.VisualSail.Data.Boat();
                    b.BoatType = BoatType.FindAll()[0];
                    System.IO.FileInfo file = new System.IO.FileInfo(gpsDataFile);
                    if (file.Name.Contains("."))
                    {
                        b.Name = file.Name.Substring(0, file.Name.LastIndexOf("."));
                    }
                    else
                    {
                        b.Name = file.Name;
                    }
                    b.Color = ColorHelper.AutoColorPick(number).ToArgb();
                    number++;
                    b.Number = number.ToString();
                    b.Save();
                    if (System.IO.File.Exists(gpsDataFile))
                    {
                        AmphibianSoftware.VisualSail.Data.Import.FileImporter fi = AmphibianSoftware.VisualSail.Data.Import.FileImporter.DetectFileType(gpsDataFile);
                        //BusyDialogManager.Show("Importing Data");
                        SensorFile sf = fi.ImportFile(gpsDataFile, b);
                        sf.Save();
                        //BusyDialogManager.HideAll();
                    }
                    race.Boats.Add(b);
                }
                catch (Exception e)
                {
                    MessageBox.Show("A problem occured while loading " + gpsDataFile + "." + Environment.NewLine + e.Message);
                }
            }
            _gpsDataFileParameters.Clear();
            _gpsDataFileParameters = null;
        }
示例#4
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            StringBuilder log = new StringBuilder();

            char[] splitter = new char[] { ',' };

            FileInfo fi = new FileInfo(path);

            SensorFile file = new SensorFile("csv", fi.Name, DateTime.Now);

            file.Save();



            int          lineNumber = 1;
            StreamReader reader     = new StreamReader(path);
            bool         isFirst    = true;

            while (!reader.EndOfStream)
            {
                try
                {
                    string line = reader.ReadLine();
                    if ((_skipFirstRow && !isFirst) || !_skipFirstRow)
                    {
                        DateTime date          = DateTime.Now;
                        string   latDirection  = "";
                        string   longDirection = "";
                        string   heightUnit    = "";
                        string   speedUnit     = "";

                        string[] parts = line.Split(splitter);

                        if (parts.Length != _mappings.Count)
                        {
                            log.Append("Line " + lineNumber + " has an unexpected number of columns");
                        }

                        bool filtered = false;
                        foreach (int i in _allowedValues.Keys)
                        {
                            if (!_allowedValues[i].Contains(parts[i]))
                            {
                                filtered = true;
                                break;
                            }
                        }

                        if (!filtered)
                        {
                            SkipperDataSet.SensorReadingsRow reading = (SkipperDataSet.SensorReadingsRow)Persistance.Data.SensorReadings.NewRow();
                            for (int i = 0; i < parts.Length; i++)
                            {
                                if (Persistance.Data.SensorReadings.Columns.Contains(_mappings[i]))
                                {
                                    if (Persistance.Data.SensorReadings.Columns[_mappings[i]].DataType == typeof(double))
                                    {
                                        if (_mappings[i] == "latitude")
                                        {
                                            if (latDirection != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + latDirection);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else if (_mappings[i] == "longitude")
                                        {
                                            if (longDirection != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + longDirection);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else if (_mappings[i] == "altitude")
                                        {
                                            if (heightUnit != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + heightUnit);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else if (_mappings[i] == "speed")
                                        {
                                            if (speedUnit != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + speedUnit);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else
                                        {
                                            reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                        }
                                    }
                                    else if (Persistance.Data.SensorReadings.Columns[_mappings[i]].DataType == typeof(string))
                                    {
                                        reading[_mappings[i]] = parts[i];
                                    }
                                    else if (Persistance.Data.SensorReadings.Columns[_mappings[i]].DataType == typeof(DateTime))
                                    {
                                        date = DateTime.Parse(parts[i]);
                                        reading[_mappings[i]] = date;
                                    }
                                    else
                                    {
                                        throw new Exception("Unknown type");
                                    }
                                }
                                else
                                {
                                    if (_mappings[i] == "date")
                                    {
                                        int hours   = date.Hour;
                                        int minutes = date.Minute;
                                        int seconds = date.Second;
                                        int millis  = date.Millisecond;
                                        date = DateTime.Parse(parts[i]);
                                        date = date.Add(new TimeSpan(0, hours, minutes, seconds, millis));
                                        reading["datetime"] = date;
                                    }
                                    else if (_mappings[i] == "time")
                                    {
                                        int hours   = date.Hour;
                                        int minutes = date.Minute;
                                        int seconds = date.Second;
                                        int millis  = date.Millisecond;
                                        date = date.Subtract(new TimeSpan(0, hours, minutes, seconds, millis));
                                        date = date.Add(TimeSpan.Parse(parts[i]));
                                        reading["datetime"] = date;
                                    }
                                    else if (_mappings[i] == "n/s")
                                    {
                                        latDirection = parts[i].ToLower();
                                        if (reading["latitude"] != System.DBNull.Value)
                                        {
                                            reading["latitude"] = ConvertValueWithUnit(reading["latitude"] + " " + latDirection);
                                        }
                                    }
                                    else if (_mappings[i] == "e/w")
                                    {
                                        longDirection = parts[i].ToLower();
                                        if (reading["longitude"] != System.DBNull.Value)
                                        {
                                            reading["longitude"] = ConvertValueWithUnit(reading["longitude"] + " " + longDirection);
                                        }
                                    }
                                    else if (_mappings[i] == "height unit")
                                    {
                                        heightUnit = parts[i].ToLower();
                                        if (reading["altitude"] != System.DBNull.Value)
                                        {
                                            reading["altitude"] = ConvertValueWithUnit(reading["altitude"] + " " + heightUnit);
                                        }
                                    }
                                    else if (_mappings[i] == "speed unit")
                                    {
                                        speedUnit = parts[i].ToLower();
                                        if (reading["speed"] != System.DBNull.Value)
                                        {
                                            reading["speed"] = ConvertValueWithUnit(reading["speed"] + " " + speedUnit);
                                        }
                                    }
                                    else if (_mappings[i] == "")
                                    {
                                    }
                                    else
                                    {
                                        throw new Exception("invalid column mapping");
                                    }
                                }
                            }

                            file.AddReading(reading);
                        }
                    }
                    else
                    {
                        isFirst = false;
                    }
                }
                catch (Exception e)
                {
                    log.Append("Error loading line " + lineNumber + ". " + e.Message + Environment.NewLine);
                }
                lineNumber++;
            }
            reader.Close();
            if (log.Length > 0)
            {
                if (log.ToString().Length > 1000)
                {
                    log.Remove(1000, log.ToString().Length - 1000);
                }
                MessageBox.Show("Errors occured while loading the file" + Environment.NewLine + log.ToString());
            }
            boat.AddFile(file);


            return(file);
        }
示例#5
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                StringBuilder log  = new StringBuilder();
                FileInfo      fi   = new FileInfo(path);
                SensorFile    file = new SensorFile("gpx", fi.Name, DateTime.Now);
                file.Save();
                foreach (XmlNode gpx in doc.ChildNodes)
                {
                    if (gpx.Name == "gpx")
                    {
                        foreach (XmlNode wpt in gpx.ChildNodes)
                        {
                            /*if (wpt.Name == "wpt")
                             * {
                             *  double lat=0;
                             *  double lon=0;
                             *  double elevation=0;
                             *  DateTime time=DateTime.MinValue;
                             *  foreach (XmlAttribute attribute in wpt.Attributes)
                             *  {
                             *      if (attribute.Name == "lat")
                             *      {
                             *          lat = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                             *      }
                             *      if (attribute.Name == "lon")
                             *      {
                             *          lon = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                             *      }
                             *  }
                             *  foreach (XmlElement attribute in wpt.ChildNodes)
                             *  {
                             *      if (attribute.Name == "time")
                             *      {
                             *          string gpxTime = attribute.InnerText;
                             *          gpxTime=gpxTime.Replace('T', ' ');
                             *          gpxTime=gpxTime.Replace('Z', ' ');
                             *          time = DateTime.Parse(gpxTime);
                             *      }
                             *      if (attribute.Name == "ele")
                             *      {
                             *          elevation = double.Parse(attribute.InnerText, _numberCulture.NumberFormat);
                             *      }
                             *  }
                             *  file.AddReading(time, lat, lon, elevation, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                             * }*/
                            if (wpt.Name == "trk")
                            {
                                foreach (XmlNode seg in wpt.ChildNodes)
                                {
                                    if (seg.Name == "trkseg")
                                    {
                                        foreach (XmlNode trkpt in seg.ChildNodes)
                                        {
                                            if (trkpt.Name == "trkpt")
                                            {
                                                double   lat       = 0;
                                                double   lon       = 0;
                                                double   elevation = 0;
                                                DateTime time      = DateTime.MinValue;
                                                foreach (XmlAttribute attribute in trkpt.Attributes)
                                                {
                                                    if (attribute.Name == "lat")
                                                    {
                                                        lat = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                                    }
                                                    if (attribute.Name == "lon")
                                                    {
                                                        lon = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                                    }
                                                }
                                                foreach (XmlElement attribute in trkpt.ChildNodes)
                                                {
                                                    if (attribute.Name == "time")
                                                    {
                                                        string gpxTime = attribute.InnerText;
                                                        gpxTime = gpxTime.Replace('T', ' ');
                                                        gpxTime = gpxTime.Replace('Z', ' ');
                                                        time    = DateTime.Parse(gpxTime);
                                                    }
                                                    if (attribute.Name == "ele")
                                                    {
                                                        elevation = double.Parse(attribute.InnerText, _numberCulture.NumberFormat);
                                                    }
                                                }
                                                file.AddReading(time, lat, lon, elevation, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                boat.AddFile(file);
                return(file);
            }
            catch//(System.Xml.Schema.XmlSchemaException e)
            {
                return(null);
            }
        }
示例#6
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                StringBuilder log = new StringBuilder();
                FileInfo fi = new FileInfo(path);
                SensorFile file = new SensorFile("vcc",fi.Name, DateTime.Now);
                file.Save();
                int rowCount = 0;
                foreach (XmlNode vcc in doc.ChildNodes)
                {
                    foreach (XmlNode capturedTrack in vcc.ChildNodes)
                    {
                        if (capturedTrack.Name == "CapturedTrack")
                        {
                            foreach (XmlNode trackpoints in capturedTrack.ChildNodes)
                            {
                                if (trackpoints.Name == "Trackpoints")
                                {
                                    foreach (XmlNode trackpoint in trackpoints.ChildNodes)
                                    {
                                        double lat = 0;
                                        double lon = 0;
                                        DateTime time = DateTime.MinValue;
                                        double heading = 0;
                                        double speed = 0;

                                        foreach (XmlAttribute attribute in trackpoint.Attributes)
                                        {
                                            if (attribute.Name == "dateTime")
                                            {
                                                time = DateTime.Parse(attribute.Value).ToUniversalTime();
                                            }
                                            if (attribute.Name == "heading")
                                            {
                                                heading = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                            if (attribute.Name == "speed")
                                            {
                                                speed = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                            if (attribute.Name == "latitude")
                                            {
                                                lat = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                            if (attribute.Name == "longitude")
                                            {
                                                lon = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                        }
                                        file.AddReading(time, lat, lon, 0, speed, heading, 0, 0, 0, 0, 0, 0, 0);
                                        rowCount++;
                                    }
                                }
                            }
                        }
                    }
                }
                if (rowCount > 0)
                {
                    boat.AddFile(file);
                    return file;
                }
                else
                {
                    return null;
                }
            }
            catch// (System.Xml.Schema.XmlSchemaException e)
            {
                return null;
            }
        }
示例#7
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            StringBuilder log = new StringBuilder();
            char[] splitter = new char[] { ',' };

            FileInfo fi = new FileInfo(path);

            SensorFile file = new SensorFile("csv", fi.Name, DateTime.Now);
            file.Save();

            
            

            int lineNumber = 1;
            StreamReader reader = new StreamReader(path);
            bool isFirst = true;
            while (!reader.EndOfStream)
            {
                try
                {
                    string line = reader.ReadLine();
                    if ((_skipFirstRow && !isFirst) || !_skipFirstRow)
                    {
                        DateTime date=DateTime.Now;
                        string latDirection="";
                        string longDirection="";
                        string heightUnit="";
                        string speedUnit="";

                        string[] parts = line.Split(splitter);

                        if (parts.Length != _mappings.Count)
                        {
                            log.Append("Line " + lineNumber + " has an unexpected number of columns");
                        }

                        bool filtered = false;
                        foreach (int i in _allowedValues.Keys)
                        {
                            if (!_allowedValues[i].Contains(parts[i]))
                            {
                                filtered = true;
                                break;
                            }
                        }

                        if (!filtered)
                        {
                            SkipperDataSet.SensorReadingsRow reading = (SkipperDataSet.SensorReadingsRow)Persistance.Data.SensorReadings.NewRow();
                            for (int i = 0; i < parts.Length; i++)
                            {
                                if (Persistance.Data.SensorReadings.Columns.Contains(_mappings[i]))
                                {
                                    if (Persistance.Data.SensorReadings.Columns[_mappings[i]].DataType == typeof(double))
                                    {
                                        if (_mappings[i] == "latitude")
                                        {
                                            if (latDirection != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + latDirection);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else if (_mappings[i] == "longitude")
                                        {
                                            if (longDirection != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + longDirection);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else if (_mappings[i] == "altitude")
                                        {
                                            if (heightUnit != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + heightUnit);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else if (_mappings[i] == "speed")
                                        {
                                            if (speedUnit != "")
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i] + " " + speedUnit);
                                            }
                                            else
                                            {
                                                reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                            }
                                        }
                                        else
                                        {
                                            reading[_mappings[i]] = ConvertValueWithUnit(parts[i]);
                                        }
                                    }
                                    else if (Persistance.Data.SensorReadings.Columns[_mappings[i]].DataType == typeof(string))
                                    {
                                        reading[_mappings[i]] = parts[i];
                                    }
                                    else if (Persistance.Data.SensorReadings.Columns[_mappings[i]].DataType == typeof(DateTime))
                                    {
                                        date = DateTime.Parse(parts[i]);
                                        reading[_mappings[i]] = date;
                                    }
                                    else
                                    {
                                        throw new Exception("Unknown type");
                                    }
                                }
                                else
                                {
                                    if (_mappings[i] == "date")
                                    {
                                        int hours = date.Hour;
                                        int minutes = date.Minute;
                                        int seconds = date.Second;
                                        int millis = date.Millisecond;
                                        date = DateTime.Parse(parts[i]);
                                        date = date.Add(new TimeSpan(0, hours, minutes, seconds, millis));
                                        reading["datetime"] = date;
                                    }
                                    else if (_mappings[i] == "time")
                                    {
                                        int hours = date.Hour;
                                        int minutes = date.Minute;
                                        int seconds = date.Second;
                                        int millis = date.Millisecond;
                                        date = date.Subtract(new TimeSpan(0, hours, minutes, seconds, millis));
                                        date = date.Add(TimeSpan.Parse(parts[i]));
                                        reading["datetime"] = date;
                                    }
                                    else if (_mappings[i] == "n/s")
                                    {
                                        latDirection = parts[i].ToLower();
                                        if (reading["latitude"] != System.DBNull.Value)
                                        {
                                            reading["latitude"] = ConvertValueWithUnit(reading["latitude"] + " " + latDirection);
                                        }
                                    }
                                    else if (_mappings[i] == "e/w")
                                    {
                                        longDirection = parts[i].ToLower();
                                        if (reading["longitude"] != System.DBNull.Value)
                                        {
                                            reading["longitude"] = ConvertValueWithUnit(reading["longitude"] + " " + longDirection);
                                        }
                                    }
                                    else if (_mappings[i] == "height unit")
                                    {
                                        heightUnit = parts[i].ToLower();
                                        if (reading["altitude"] != System.DBNull.Value)
                                        {
                                            reading["altitude"] = ConvertValueWithUnit(reading["altitude"] + " " + heightUnit);
                                        }
                                    }
                                    else if (_mappings[i] == "speed unit")
                                    {
                                        speedUnit = parts[i].ToLower();
                                        if (reading["speed"] != System.DBNull.Value)
                                        {
                                            reading["speed"] = ConvertValueWithUnit(reading["speed"] + " " + speedUnit);
                                        }
                                    }
                                    else if (_mappings[i] == "")
                                    {
                                    }
                                    else
                                    {
                                        throw new Exception("invalid column mapping");
                                    }
                                }
                            }

                            file.AddReading(reading);
                        }
                    }
                    else
                    {
                        isFirst = false;
                    }
                }
                catch (Exception e)
                {
                    log.Append("Error loading line " + lineNumber + ". " + e.Message+Environment.NewLine);
                }
                lineNumber++;
            }
            reader.Close();
            if (log.Length > 0)
            {
                if(log.ToString().Length>1000)
                    log.Remove(1000, log.ToString().Length - 1000);
                MessageBox.Show("Errors occured while loading the file" + Environment.NewLine + log.ToString());
            }
            boat.AddFile(file);


            return file;
        }
示例#8
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                StringBuilder log  = new StringBuilder();
                FileInfo      fi   = new FileInfo(path);
                SensorFile    file = new SensorFile("vcc", fi.Name, DateTime.Now);
                file.Save();
                int rowCount = 0;
                foreach (XmlNode vcc in doc.ChildNodes)
                {
                    foreach (XmlNode capturedTrack in vcc.ChildNodes)
                    {
                        if (capturedTrack.Name == "CapturedTrack")
                        {
                            foreach (XmlNode trackpoints in capturedTrack.ChildNodes)
                            {
                                if (trackpoints.Name == "Trackpoints")
                                {
                                    foreach (XmlNode trackpoint in trackpoints.ChildNodes)
                                    {
                                        double   lat     = 0;
                                        double   lon     = 0;
                                        DateTime time    = DateTime.MinValue;
                                        double   heading = 0;
                                        double   speed   = 0;

                                        foreach (XmlAttribute attribute in trackpoint.Attributes)
                                        {
                                            if (attribute.Name == "dateTime")
                                            {
                                                time = DateTime.Parse(attribute.Value).ToUniversalTime();
                                            }
                                            if (attribute.Name == "heading")
                                            {
                                                heading = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                            if (attribute.Name == "speed")
                                            {
                                                speed = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                            if (attribute.Name == "latitude")
                                            {
                                                lat = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                            if (attribute.Name == "longitude")
                                            {
                                                lon = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                            }
                                        }
                                        file.AddReading(time, lat, lon, 0, speed, heading, 0, 0, 0, 0, 0, 0, 0);
                                        rowCount++;
                                    }
                                }
                            }
                        }
                    }
                }
                if (rowCount > 0)
                {
                    boat.AddFile(file);
                    return(file);
                }
                else
                {
                    return(null);
                }
            }
            catch// (System.Xml.Schema.XmlSchemaException e)
            {
                return(null);
            }
        }
示例#9
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            int line = 0;
            StringBuilder log = new StringBuilder();
            try
            {
                FileInfo fi = new FileInfo(path);
                SensorFile file = new SensorFile("nmea", fi.Name, DateTime.Now);
                file.Save();

                StreamReader reader = new StreamReader(path);
                Dictionary<string, Dictionary<string, string>> first=null;
                if (!reader.EndOfStream)
                {
                    while (first == null && !reader.EndOfStream)
                    {
                        try
                        {
                            string lineText = reader.ReadLine();
                            first = NmeaParser.Parse(lineText);
                        }
                        catch (NMEAIgnoredSentenceException) { }
                        catch (NMEAUnkownSentenceException) { }
                        catch (NMEAEmptySentenceException) { }
                        catch (Exception e)
                        {
                            log.Append("Line " + line + ": " + e.Message);
                            log.Append(Environment.NewLine);
                        }
                        line++;
                    }
                    while (!reader.EndOfStream)
                    {
                        try
                        {
                            Dictionary<string, Dictionary<string, string>> current = first;
                            bool newGroup = true;
                            double latitude = 0;
                            double longitude = 0;
                            double speed = 0;
                            double waterTemperature = 0;
                            double depth = 0;
                            double relativeWindSpeed = 0;
                            double relativeWindAngle = 0;
                            double heading = 0;
                            TimeSpan? time = null;
                            Exception groupException = null;
                            while (newGroup || (current.Keys.ElementAt(0) != first.Keys.ElementAt(0) && !reader.EndOfStream))
                            {
                                try
                                {


                                    //process current
                                    if (current.Keys.ElementAt(0) == "Global Positioning System Fix Data")
                                    {
                                        //time
                                        string timestring = current[current.Keys.ElementAt(0)]["Time"];
                                        char[] splitter = {'.'};
                                        string[] parts = timestring.Split(splitter);
                                        if (parts[0].Length == 6)
                                        {
                                            int hour = int.Parse(parts[0].Substring(0, 2));
                                            int minute = int.Parse(parts[0].Substring(2, 2));
                                            int second = int.Parse(parts[0].Substring(4, 2));
                                            int millisecond = 0;
                                            if (parts.Length > 1)
                                            {
                                                millisecond =
                                                    (int)
                                                        (double.Parse("0." + parts[1], _numberCulture.NumberFormat)*
                                                         1000.0);
                                            }
                                            time = new TimeSpan(0, hour, minute, second, millisecond);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }

                                        //latitude
                                        string latitudeString = current[current.Keys.ElementAt(0)]["Latitude"];
                                        string latitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Latitude Direction"];
                                        if (latitudeString.Length > 2)
                                        {
                                            int latdegrees = int.Parse(latitudeString.Substring(0, 2));
                                            double latminute = double.Parse(latitudeString.Substring(2),
                                                _numberCulture.NumberFormat);
                                            latitude = Coordinate.CoordinateToDouble(latdegrees, latminute, 0);
                                            if (latitudeDirectionString.ToLower() == "s")
                                            {
                                                latitude = -latitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Latitude format");
                                        }

                                        //longitude
                                        string longitudeString = current[current.Keys.ElementAt(0)]["Longitude"];
                                        string longitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Longitude Direction"];
                                        if (longitudeString.Length > 2)
                                        {
                                            int longdegrees = int.Parse(longitudeString.Substring(0, 3));
                                            double longminute = double.Parse(longitudeString.Substring(3),
                                                _numberCulture.NumberFormat);
                                            longitude = Coordinate.CoordinateToDouble(longdegrees, longminute, 0);
                                            if (longitudeDirectionString.ToLower() == "w")
                                            {
                                                longitude = -longitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Longitude format");
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Recommended Minimum Specific GPS/TRANSIT Data")
                                    {
                                        //time
                                        string timestring = current[current.Keys.ElementAt(0)]["Time of Fix"];
                                        char[] splitter = {'.'};
                                        string[] parts = timestring.Split(splitter);
                                        if (parts[0].Length == 6)
                                        {
                                            int hour = int.Parse(parts[0].Substring(0, 2));
                                            int minute = int.Parse(parts[0].Substring(2, 2));
                                            int second = int.Parse(parts[0].Substring(4, 2));
                                            time = new TimeSpan(0, hour, minute, second, 0);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }

                                        //latitude
                                        string latitudeString = current[current.Keys.ElementAt(0)]["Latitude"];
                                        string latitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Latitude Direction"];
                                        if (latitudeString.Length > 2)
                                        {
                                            int latdegrees = int.Parse(latitudeString.Substring(0, 2));
                                            double latminute = double.Parse(latitudeString.Substring(2),
                                                _numberCulture.NumberFormat);
                                            latitude = Coordinate.CoordinateToDouble(latdegrees, latminute, 0);
                                            if (latitudeDirectionString.ToLower() == "s")
                                            {
                                                latitude = -latitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Latitude format");
                                        }

                                        //longitude
                                        string longitudeString = current[current.Keys.ElementAt(0)]["Longitude"];
                                        string longitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Longitude Direction"];
                                        if (longitudeString.Length > 2)
                                        {
                                            int longdegrees = int.Parse(longitudeString.Substring(0, 3));
                                            double longminute = double.Parse(longitudeString.Substring(3),
                                                _numberCulture.NumberFormat);
                                            longitude = Coordinate.CoordinateToDouble(longdegrees, longminute, 0);
                                            if (longitudeDirectionString.ToLower() == "w")
                                            {
                                                longitude = -longitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Longitude format");
                                        }

                                        string speedString = current[current.Keys.ElementAt(0)]["Speed over ground"];
                                        double.TryParse(speedString, out speed);
                                        //speed = double.Parse(speedString, _numberCulture.NumberFormat);

                                        string datestring = current[current.Keys.ElementAt(0)]["Date of Fix"];
                                        if (datestring.Length == 6)
                                        {
                                            int day = int.Parse(datestring.Substring(0, 2));
                                            int month = int.Parse(datestring.Substring(2, 2));
                                            int year = 2000 + int.Parse(datestring.Substring(4, 2));
                                            DateTime dt = new DateTime(year, month, day);
                                            dt = ZeroTime(dt);
                                            StartDate = dt;
                                            time = new TimeSpan(0, time.Value.Hours, time.Value.Minutes,
                                                time.Value.Seconds, time.Value.Milliseconds);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Data and Time")
                                    {
                                        //time
                                        string timestring = current[current.Keys.ElementAt(0)]["Time"];
                                        char[] splitter = {'.'};
                                        string[] parts = timestring.Split(splitter);
                                        if (parts[0].Length == 6)
                                        {
                                            int hour = int.Parse(parts[0].Substring(0, 2));
                                            int minute = int.Parse(parts[0].Substring(2, 2));
                                            int second = int.Parse(parts[0].Substring(4, 2));
                                            int millisecond =
                                                (int)
                                                    (double.Parse("0." + parts[1], _numberCulture.NumberFormat)*
                                                     1000.0);
                                            int day = int.Parse(current[current.Keys.ElementAt(0)]["Day"]);
                                            int month = int.Parse(current[current.Keys.ElementAt(0)]["Month"]);
                                            int year = int.Parse(current[current.Keys.ElementAt(0)]["Year"]);
                                            DateTime dt = new DateTime(year, month, day);
                                            dt = ZeroTime(dt);
                                            StartDate = dt;
                                            time = new TimeSpan(0, hour, minute, second, millisecond);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Water Temperature")
                                    {
                                        string tempString = current[current.Keys.ElementAt(0)]["Water Temperature"];
                                        string tempUnitString =
                                            current[current.Keys.ElementAt(0)]["Water Temperature Unit"];
                                        waterTemperature = double.Parse(tempString, _numberCulture.NumberFormat);
                                        //convert fahrenheit to celsius
                                        if (tempUnitString.ToLower() == "f")
                                        {
                                            waterTemperature = (5.0/9.0)*(waterTemperature - 32.0);
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Depth")
                                    {
                                        string depthString = current[current.Keys.ElementAt(0)]["Depth"];
                                        depth = double.Parse(depthString, _numberCulture.NumberFormat);
                                    }
                                    else if (current.Keys.ElementAt(0) == "Wind Speed and Angle")
                                    {
                                        string windAngleString = current[current.Keys.ElementAt(0)]["Wind Angle"];
                                        string windspeedString = current[current.Keys.ElementAt(0)]["Wind Speed"];
                                        string windspeedUnitString =
                                            current[current.Keys.ElementAt(0)]["Wind Speed Unit"];
                                        relativeWindAngle = double.Parse(windAngleString,
                                            _numberCulture.NumberFormat);
                                        relativeWindSpeed =
                                            ConvertValueWithUnit(windspeedString + " " + windspeedUnitString);
                                    }
                                    else if (current.Keys.ElementAt(0) == "NovaSail")
                                    {
                                        string latitudeString = current[current.Keys.ElementAt(0)]["Latitude"];
                                        string longitudeString = current[current.Keys.ElementAt(0)]["Longitude"];
                                        string headingString = current[current.Keys.ElementAt(0)]["Heading"];
                                        string speedString = current[current.Keys.ElementAt(0)]["Speed"];
                                        string rollString = current[current.Keys.ElementAt(0)]["Roll"];
                                        string dayString = current[current.Keys.ElementAt(0)]["Day"];
                                        string monthString = current[current.Keys.ElementAt(0)]["Month"];
                                        string yearString = current[current.Keys.ElementAt(0)]["Year"];
                                        string hourString = current[current.Keys.ElementAt(0)]["Hour"];
                                        string minuteString = current[current.Keys.ElementAt(0)]["Minute"];
                                        string secondString = current[current.Keys.ElementAt(0)]["Second"];

                                        latitude = double.Parse(latitudeString, _numberCulture.NumberFormat);
                                        longitude = double.Parse(longitudeString, _numberCulture.NumberFormat);

                                        speed = double.Parse(speedString, _numberCulture.NumberFormat);
                                        heading = double.Parse(headingString, _numberCulture.NumberFormat);
                                        //roll
                                        DateTime dt = new DateTime(int.Parse(yearString), int.Parse(monthString),
                                            int.Parse(dayString));
                                        dt = ZeroTime(dt);
                                        StartDate = dt;
                                        time = new TimeSpan(0, int.Parse(hourString), int.Parse(minuteString),
                                            int.Parse(secondString), 0);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    groupException = ex;
                                }
                                line++;
                                string lineText = reader.ReadLine();
                                current = NmeaParser.Parse(lineText);
                                newGroup = false;
                            }
                            if (time != null && groupException==null)
                            {
                                file.AddReading(StartDate + time.Value, latitude, longitude, 0, speed, heading, depth, waterTemperature, 0, relativeWindAngle, relativeWindSpeed, 0, 0);
                            }
                            else
                            {
                                //log something?
                                log.Append("The date and time could not be determined at line " + line);
                                log.Append(Environment.NewLine);
                            }
                            first = current;
                        }
                        catch (NMEAIgnoredSentenceException) {}
                        catch (NMEAUnkownSentenceException) {}
                        catch (NMEAEmptySentenceException) {}
                        catch (Exception e)
                        {
                            log.Append("Line " + line + ": " + e.Message);
                            log.Append(Environment.NewLine);
                        }
                        
                    }
                   
                    boat.AddFile(file);
                    if (log.Length > 0)
                    {
                        if (log.ToString().Length > 1000)
                        {
                            MessageBox.Show(log.ToString().Substring(0, 1000));
                        }
                        else
                        {
                            MessageBox.Show(log.ToString());
                        }
                    }
                    return file;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
示例#10
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                StringBuilder log = new StringBuilder();
                FileInfo fi = new FileInfo(path);
                SensorFile file = new SensorFile("gpx", fi.Name, DateTime.Now);
                file.Save();
                foreach (XmlNode gpx in doc.ChildNodes)
                {
                    if (gpx.Name == "gpx")
                    {
                        foreach (XmlNode wpt in gpx.ChildNodes)
                        {
                            /*if (wpt.Name == "wpt")
                            {
                                double lat=0;
                                double lon=0;
                                double elevation=0;
                                DateTime time=DateTime.MinValue;
                                foreach (XmlAttribute attribute in wpt.Attributes)
                                {
                                    if (attribute.Name == "lat")
                                    {
                                        lat = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                    }
                                    if (attribute.Name == "lon")
                                    {
                                        lon = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                    }
                                }
                                foreach (XmlElement attribute in wpt.ChildNodes)
                                {
                                    if (attribute.Name == "time")
                                    {
                                        string gpxTime = attribute.InnerText;
                                        gpxTime=gpxTime.Replace('T', ' ');
                                        gpxTime=gpxTime.Replace('Z', ' ');
                                        time = DateTime.Parse(gpxTime);
                                    }
                                    if (attribute.Name == "ele")
                                    {
                                        elevation = double.Parse(attribute.InnerText, _numberCulture.NumberFormat);
                                    }
                                }
                                file.AddReading(time, lat, lon, elevation, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                            }*/
                            if (wpt.Name == "trk")
                            {
                                foreach (XmlNode seg in wpt.ChildNodes)
                                {
                                    if (seg.Name == "trkseg")
                                    {
                                        foreach (XmlNode trkpt in seg.ChildNodes)
                                        {
                                            if (trkpt.Name == "trkpt")
                                            {
                                                double lat = 0;
                                                double lon = 0;
                                                double elevation = 0;
                                                DateTime time = DateTime.MinValue;
                                                foreach (XmlAttribute attribute in trkpt.Attributes)
                                                {
                                                    if (attribute.Name == "lat")
                                                    {
                                                        lat = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                                    }
                                                    if (attribute.Name == "lon")
                                                    {
                                                        lon = double.Parse(attribute.Value, _numberCulture.NumberFormat);
                                                    }
                                                }
                                                foreach (XmlElement attribute in trkpt.ChildNodes)
                                                {
                                                    if (attribute.Name == "time")
                                                    {
                                                        string gpxTime = attribute.InnerText;
                                                        gpxTime = gpxTime.Replace('T', ' ');
                                                        gpxTime = gpxTime.Replace('Z', ' ');
                                                        time = DateTime.Parse(gpxTime);
                                                    }
                                                    if (attribute.Name == "ele")
                                                    {
                                                        elevation = double.Parse(attribute.InnerText, _numberCulture.NumberFormat);
                                                    }
                                                }
                                                file.AddReading(time, lat, lon, elevation, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                boat.AddFile(file);
                return file;
            }
            catch//(System.Xml.Schema.XmlSchemaException e)
            {
                return null;
            }
        }
示例#11
0
        public override SensorFile ImportFile(string path, Boat boat)
        {
            int           line = 0;
            StringBuilder log  = new StringBuilder();

            try
            {
                FileInfo   fi   = new FileInfo(path);
                SensorFile file = new SensorFile("nmea", fi.Name, DateTime.Now);
                file.Save();

                StreamReader reader = new StreamReader(path);
                Dictionary <string, Dictionary <string, string> > first = null;
                if (!reader.EndOfStream)
                {
                    while (first == null && !reader.EndOfStream)
                    {
                        try
                        {
                            string lineText = reader.ReadLine();
                            first = NmeaParser.Parse(lineText);
                        }
                        catch (NMEAIgnoredSentenceException) { }
                        catch (NMEAUnkownSentenceException) { }
                        catch (NMEAEmptySentenceException) { }
                        catch (Exception e)
                        {
                            log.Append("Line " + line + ": " + e.Message);
                            log.Append(Environment.NewLine);
                        }
                        line++;
                    }
                    while (!reader.EndOfStream)
                    {
                        try
                        {
                            Dictionary <string, Dictionary <string, string> > current = first;
                            bool      newGroup          = true;
                            double    latitude          = 0;
                            double    longitude         = 0;
                            double    speed             = 0;
                            double    waterTemperature  = 0;
                            double    depth             = 0;
                            double    relativeWindSpeed = 0;
                            double    relativeWindAngle = 0;
                            double    heading           = 0;
                            TimeSpan? time           = null;
                            Exception groupException = null;
                            while (newGroup || (current.Keys.ElementAt(0) != first.Keys.ElementAt(0) && !reader.EndOfStream))
                            {
                                try
                                {
                                    //process current
                                    if (current.Keys.ElementAt(0) == "Global Positioning System Fix Data")
                                    {
                                        //time
                                        string   timestring = current[current.Keys.ElementAt(0)]["Time"];
                                        char[]   splitter   = { '.' };
                                        string[] parts      = timestring.Split(splitter);
                                        if (parts[0].Length == 6)
                                        {
                                            int hour        = int.Parse(parts[0].Substring(0, 2));
                                            int minute      = int.Parse(parts[0].Substring(2, 2));
                                            int second      = int.Parse(parts[0].Substring(4, 2));
                                            int millisecond = 0;
                                            if (parts.Length > 1)
                                            {
                                                millisecond =
                                                    (int)
                                                    (double.Parse("0." + parts[1], _numberCulture.NumberFormat) *
                                                     1000.0);
                                            }
                                            time = new TimeSpan(0, hour, minute, second, millisecond);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }

                                        //latitude
                                        string latitudeString          = current[current.Keys.ElementAt(0)]["Latitude"];
                                        string latitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Latitude Direction"];
                                        if (latitudeString.Length > 2)
                                        {
                                            int    latdegrees = int.Parse(latitudeString.Substring(0, 2));
                                            double latminute  = double.Parse(latitudeString.Substring(2),
                                                                             _numberCulture.NumberFormat);
                                            latitude = Coordinate.CoordinateToDouble(latdegrees, latminute, 0);
                                            if (latitudeDirectionString.ToLower() == "s")
                                            {
                                                latitude = -latitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Latitude format");
                                        }

                                        //longitude
                                        string longitudeString          = current[current.Keys.ElementAt(0)]["Longitude"];
                                        string longitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Longitude Direction"];
                                        if (longitudeString.Length > 2)
                                        {
                                            int    longdegrees = int.Parse(longitudeString.Substring(0, 3));
                                            double longminute  = double.Parse(longitudeString.Substring(3),
                                                                              _numberCulture.NumberFormat);
                                            longitude = Coordinate.CoordinateToDouble(longdegrees, longminute, 0);
                                            if (longitudeDirectionString.ToLower() == "w")
                                            {
                                                longitude = -longitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Longitude format");
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Recommended Minimum Specific GPS/TRANSIT Data")
                                    {
                                        //time
                                        string   timestring = current[current.Keys.ElementAt(0)]["Time of Fix"];
                                        char[]   splitter   = { '.' };
                                        string[] parts      = timestring.Split(splitter);
                                        if (parts[0].Length == 6)
                                        {
                                            int hour   = int.Parse(parts[0].Substring(0, 2));
                                            int minute = int.Parse(parts[0].Substring(2, 2));
                                            int second = int.Parse(parts[0].Substring(4, 2));
                                            time = new TimeSpan(0, hour, minute, second, 0);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }

                                        //latitude
                                        string latitudeString          = current[current.Keys.ElementAt(0)]["Latitude"];
                                        string latitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Latitude Direction"];
                                        if (latitudeString.Length > 2)
                                        {
                                            int    latdegrees = int.Parse(latitudeString.Substring(0, 2));
                                            double latminute  = double.Parse(latitudeString.Substring(2),
                                                                             _numberCulture.NumberFormat);
                                            latitude = Coordinate.CoordinateToDouble(latdegrees, latminute, 0);
                                            if (latitudeDirectionString.ToLower() == "s")
                                            {
                                                latitude = -latitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Latitude format");
                                        }

                                        //longitude
                                        string longitudeString          = current[current.Keys.ElementAt(0)]["Longitude"];
                                        string longitudeDirectionString =
                                            current[current.Keys.ElementAt(0)]["Longitude Direction"];
                                        if (longitudeString.Length > 2)
                                        {
                                            int    longdegrees = int.Parse(longitudeString.Substring(0, 3));
                                            double longminute  = double.Parse(longitudeString.Substring(3),
                                                                              _numberCulture.NumberFormat);
                                            longitude = Coordinate.CoordinateToDouble(longdegrees, longminute, 0);
                                            if (longitudeDirectionString.ToLower() == "w")
                                            {
                                                longitude = -longitude;
                                            }
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Longitude format");
                                        }

                                        string speedString = current[current.Keys.ElementAt(0)]["Speed over ground"];
                                        double.TryParse(speedString, out speed);
                                        //speed = double.Parse(speedString, _numberCulture.NumberFormat);

                                        string datestring = current[current.Keys.ElementAt(0)]["Date of Fix"];
                                        if (datestring.Length == 6)
                                        {
                                            int      day   = int.Parse(datestring.Substring(0, 2));
                                            int      month = int.Parse(datestring.Substring(2, 2));
                                            int      year  = 2000 + int.Parse(datestring.Substring(4, 2));
                                            DateTime dt    = new DateTime(year, month, day);
                                            dt        = ZeroTime(dt);
                                            StartDate = dt;
                                            time      = new TimeSpan(0, time.Value.Hours, time.Value.Minutes,
                                                                     time.Value.Seconds, time.Value.Milliseconds);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Data and Time")
                                    {
                                        //time
                                        string   timestring = current[current.Keys.ElementAt(0)]["Time"];
                                        char[]   splitter   = { '.' };
                                        string[] parts      = timestring.Split(splitter);
                                        if (parts[0].Length == 6)
                                        {
                                            int hour        = int.Parse(parts[0].Substring(0, 2));
                                            int minute      = int.Parse(parts[0].Substring(2, 2));
                                            int second      = int.Parse(parts[0].Substring(4, 2));
                                            int millisecond =
                                                (int)
                                                (double.Parse("0." + parts[1], _numberCulture.NumberFormat) *
                                                 1000.0);
                                            int      day   = int.Parse(current[current.Keys.ElementAt(0)]["Day"]);
                                            int      month = int.Parse(current[current.Keys.ElementAt(0)]["Month"]);
                                            int      year  = int.Parse(current[current.Keys.ElementAt(0)]["Year"]);
                                            DateTime dt    = new DateTime(year, month, day);
                                            dt        = ZeroTime(dt);
                                            StartDate = dt;
                                            time      = new TimeSpan(0, hour, minute, second, millisecond);
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid Time Format");
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Water Temperature")
                                    {
                                        string tempString     = current[current.Keys.ElementAt(0)]["Water Temperature"];
                                        string tempUnitString =
                                            current[current.Keys.ElementAt(0)]["Water Temperature Unit"];
                                        waterTemperature = double.Parse(tempString, _numberCulture.NumberFormat);
                                        //convert fahrenheit to celsius
                                        if (tempUnitString.ToLower() == "f")
                                        {
                                            waterTemperature = (5.0 / 9.0) * (waterTemperature - 32.0);
                                        }
                                    }
                                    else if (current.Keys.ElementAt(0) == "Depth")
                                    {
                                        string depthString = current[current.Keys.ElementAt(0)]["Depth"];
                                        depth = double.Parse(depthString, _numberCulture.NumberFormat);
                                    }
                                    else if (current.Keys.ElementAt(0) == "Wind Speed and Angle")
                                    {
                                        string windAngleString     = current[current.Keys.ElementAt(0)]["Wind Angle"];
                                        string windspeedString     = current[current.Keys.ElementAt(0)]["Wind Speed"];
                                        string windspeedUnitString =
                                            current[current.Keys.ElementAt(0)]["Wind Speed Unit"];
                                        relativeWindAngle = double.Parse(windAngleString,
                                                                         _numberCulture.NumberFormat);
                                        relativeWindSpeed =
                                            ConvertValueWithUnit(windspeedString + " " + windspeedUnitString);
                                    }
                                    else if (current.Keys.ElementAt(0) == "NovaSail")
                                    {
                                        string latitudeString  = current[current.Keys.ElementAt(0)]["Latitude"];
                                        string longitudeString = current[current.Keys.ElementAt(0)]["Longitude"];
                                        string headingString   = current[current.Keys.ElementAt(0)]["Heading"];
                                        string speedString     = current[current.Keys.ElementAt(0)]["Speed"];
                                        string rollString      = current[current.Keys.ElementAt(0)]["Roll"];
                                        string dayString       = current[current.Keys.ElementAt(0)]["Day"];
                                        string monthString     = current[current.Keys.ElementAt(0)]["Month"];
                                        string yearString      = current[current.Keys.ElementAt(0)]["Year"];
                                        string hourString      = current[current.Keys.ElementAt(0)]["Hour"];
                                        string minuteString    = current[current.Keys.ElementAt(0)]["Minute"];
                                        string secondString    = current[current.Keys.ElementAt(0)]["Second"];

                                        latitude  = double.Parse(latitudeString, _numberCulture.NumberFormat);
                                        longitude = double.Parse(longitudeString, _numberCulture.NumberFormat);

                                        speed   = double.Parse(speedString, _numberCulture.NumberFormat);
                                        heading = double.Parse(headingString, _numberCulture.NumberFormat);
                                        //roll
                                        DateTime dt = new DateTime(int.Parse(yearString), int.Parse(monthString),
                                                                   int.Parse(dayString));
                                        dt        = ZeroTime(dt);
                                        StartDate = dt;
                                        time      = new TimeSpan(0, int.Parse(hourString), int.Parse(minuteString),
                                                                 int.Parse(secondString), 0);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    groupException = ex;
                                }
                                line++;
                                string lineText = reader.ReadLine();
                                current  = NmeaParser.Parse(lineText);
                                newGroup = false;
                            }
                            if (time != null && groupException == null)
                            {
                                file.AddReading(StartDate + time.Value, latitude, longitude, 0, speed, heading, depth, waterTemperature, 0, relativeWindAngle, relativeWindSpeed, 0, 0);
                            }
                            else
                            {
                                //log something?
                                log.Append("The date and time could not be determined at line " + line);
                                log.Append(Environment.NewLine);
                            }
                            first = current;
                        }
                        catch (NMEAIgnoredSentenceException) {}
                        catch (NMEAUnkownSentenceException) {}
                        catch (NMEAEmptySentenceException) {}
                        catch (Exception e)
                        {
                            log.Append("Line " + line + ": " + e.Message);
                            log.Append(Environment.NewLine);
                        }
                    }

                    boat.AddFile(file);
                    if (log.Length > 0)
                    {
                        if (log.ToString().Length > 1000)
                        {
                            MessageBox.Show(log.ToString().Substring(0, 1000));
                        }
                        else
                        {
                            MessageBox.Show(log.ToString());
                        }
                    }
                    return(file);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }