public IExternalDataReader GetReader(String format, Encoding enc, String fileName)
        {
            if (format == null)
            {
                format = "auto";
            }
            else
            {
                format = format.ToLowerInvariant();
            }
            if (format == "auto")
            {
                fileName = fileName.ToLowerInvariant();
                if (fileName.EndsWith(".dbf"))
                {
                    format = "dbf";
                }
                else if (fileName.EndsWith(".csv"))
                {
                    format = "csv";
                }
                else if (fileName.EndsWith(".xml"))
                {
                    format = "xml";
                }
            }
            switch (format)
            {
            case "dbf":
                var dataFileDbf = new DataFile()
                {
                    Encoding = enc
                };
                return(new DbfReader(dataFileDbf));

            case "csv":
                var dataFileCsv = new DataFile()
                {
                    Encoding = enc
                };
                return(new CsvReader(dataFileCsv));

            case "xml":
                var dataFileXml = new DataFile();
                return(new XmlReader(dataFileXml));
            }
            return(null);
        }
Esempio n. 2
0
        public void CsvReadSimpleFile()
        {
            var f   = new DataFile();
            var rdr = new CsvReader(f);

            using (var file = File.Open("../../testfiles/simple.csv", FileMode.Open))
            {
                rdr.Read(file);
            }

            var wrt = new CsvWriter(f);

            using (var file = File.Create("../../testfiles/output.csv"))
            {
                wrt.Write(file);
            }

            ProviderTools.CompareFiles("../../testfiles/simple.csv", "../../testfiles/output.csv");
        }
Esempio n. 3
0
        public void DbfReadSimpleFile()
        {
            var f = new DataFile()
            {
                Encoding = Encoding.GetEncoding(866)
            };
            var rdr = new DbfReader(f);

            using (var file = File.Open("../../testfiles/simple.dbf", FileMode.Open))
            {
                rdr.Read(file);
            }

            var wrt = new DbfWriter(f);

            using (var file = File.Open("../../testfiles/output.dbf", FileMode.OpenOrCreate | FileMode.Truncate))
            {
                wrt.Write(file);
            }

            ProviderTools.CompareFiles("../../testfiles/simple.dbf", "../../testfiles/output.dbf");
        }
Esempio n. 4
0
        public void XmlReadSimpleFile()
        {
            var f   = new DataFile();
            var rdr = new XmlReader(f);

            using (var file = File.Open("../../testfiles/simple.xml", FileMode.Open))
            {
                rdr.Read(file);
            }

            var wrt = new XmlWriter(f);

            f.Encoding      = Encoding.GetEncoding(1251);
            wrt.RootElement = "ROWDATA";
            wrt.RowElement  = "ROW";

            using (var file = File.Create("../../testfiles/output.xml"))
            {
                wrt.Write(file);
            }

            ProviderTools.CompareFiles("../../testfiles/simple.xml", "../../testfiles/output.xml");
        }
Esempio n. 5
0
        public void DbfReadAutoEncoding()
        {
            var f = new DataFile()
            {
                Encoding = null                 // AUTO
            };

            var rdr = new DbfReader(f);

            using (var file = File.Open("../../testfiles/ENCODING.dbf", FileMode.Open))
            {
                rdr.Read(file);
            }

            var wrt = new DbfWriter(f);

            using (var file = File.Open("../../testfiles/output.dbf", FileMode.OpenOrCreate | FileMode.Truncate))
            {
                wrt.Write(file);
            }

            ProviderTools.CompareFiles("../../testfiles/ENCODING.dbf", "../../testfiles/output.dbf");
        }