Esempio n. 1
0
        public static FileImporter DetectFileType(string path)
        {
            if (path.ToLower().EndsWith(".sail"))
            {
                throw new Exception(@".sail files cannot be imported, use ""open"" instead.");
            }
            else if (path.ToLower().EndsWith(".gpx") /*&& ValidateXmlWithSchema(path, GpxImporter.GpxXsdUrl,GpxImporter.GpxXsdPath)*/)
            {
                GpxImporter gi = new GpxImporter();
                return(gi);
            }
            else if (path.ToLower().EndsWith(".kml") /*&& ValidateXmlWithSchema(path, KmlImporter.KmlXsdUrl, KmlImporter.KmlXsdPath)*/)
            {
                KmlImporter ki = new KmlImporter();
                return(ki);
            }
            else if (path.ToLower().EndsWith(".vcc"))
            {
                VccImporter vi = new VccImporter();
                return(vi);
            }
            else
            {
                StreamReader reader    = new StreamReader(path);
                string       firstLine = reader.ReadLine();
                reader.Close();

                if (firstLine.Contains(","))
                {
                    //possibly a csv format
                    char[]   splitter = new char[] { ',' };
                    string[] parts    = firstLine.Split(splitter);

                    if (parts[0].StartsWith("$") || parts[0].StartsWith("!"))
                    {
                        NmeaImporter ni = new NmeaImporter();
                        return(ni);
                    }
                    else
                    {
                        //csv format
                        List <string>    mappings = CsvImporter.AutoDetectColumnMappings(parts);
                        ColumnAssignment ca       = new ColumnAssignment(mappings, path);
                        ca.ShowDialog();
                        mappings = ca.ColumnMappings;
                        ColumnFilter cf = new ColumnFilter(ca.Filters, path, ca.SkipFirstRow);
                        CsvImporter  ci = new CsvImporter(mappings, cf.FilterValues, ca.SkipFirstRow);
                        return(ci);
                    }
                }
                else
                {
                    throw new Exception("Format Could not be determined");
                }
            }
        }
Esempio n. 2
0
        public static FileImporter DetectFileType(string path)
        {
            if (path.ToLower().EndsWith(".sail"))
            {
                throw new Exception(@".sail files cannot be imported, use ""open"" instead.");
            }
            else if (path.ToLower().EndsWith(".gpx") /*&& ValidateXmlWithSchema(path, GpxImporter.GpxXsdUrl,GpxImporter.GpxXsdPath)*/)
            {
                GpxImporter gi = new GpxImporter();
                return gi;
            }
            else if (path.ToLower().EndsWith(".kml") /*&& ValidateXmlWithSchema(path, KmlImporter.KmlXsdUrl, KmlImporter.KmlXsdPath)*/)
            {
                KmlImporter ki = new KmlImporter();
                return ki;
            }
            else if (path.ToLower().EndsWith(".vcc"))
            {
                VccImporter vi = new VccImporter();
                return vi;
            }
            else
            {
                StreamReader reader = new StreamReader(path);
                string firstLine = reader.ReadLine();
                reader.Close();

                if (firstLine.Contains(","))
                {
                    //possibly a csv format
                    char[] splitter = new char[] { ',' };
                    string[] parts = firstLine.Split(splitter);

                    if (parts[0].StartsWith("$")||parts[0].StartsWith("!"))
                    {
                        NmeaImporter ni = new NmeaImporter();
                        return ni;
                    }
                    else
                    {
                        //csv format
                        List<string> mappings = CsvImporter.AutoDetectColumnMappings(parts);
                        ColumnAssignment ca = new ColumnAssignment(mappings, path);
                        ca.ShowDialog();
                        mappings = ca.ColumnMappings;
                        ColumnFilter cf = new ColumnFilter(ca.Filters, path, ca.SkipFirstRow);
                        CsvImporter ci = new CsvImporter(mappings, cf.FilterValues, ca.SkipFirstRow);
                        return ci;
                    }
                }
                else
                {
                    throw new Exception("Format Could not be determined");
                }
            }
        }