コード例 #1
0
        static void TestGenericReader()
        {
            var csvFiles = new String[] {
                @"../TestData.Csv/csv-students.csv",
            };
            var csvReaderSettings = new CsvReaderSettings();

            csvReaderSettings.Encoding = System.Text.Encoding.UTF8;
            var dataResolver = new StudentResolver();

            foreach (var csvFile in csvFiles)
            {
                var recordCount = 0;
                var csvFilePath = ProcessCsvFile(csvFile);

                var startTime = DateTime.Now;
                using (var reader = CsvReader <Student> .Create(csvFilePath, csvReaderSettings, dataResolver))
                {
                    foreach (var student in reader)
                    {
                        ++recordCount;
                    }
                }
                var ellapsed = (DateTime.Now - startTime).TotalSeconds;

                Console.WriteLine("Count: {0}\tTime: {1}ms", recordCount, ellapsed);
                Console.WriteLine("======================");
            }
        }
コード例 #2
0
ファイル: Tests.cs プロジェクト: jbonfardeci/EasyCsv
        public void OutputTableDef()
        {
            string     outputPath = _root + "output_test_definition.txt";
            ICsvReader csv        = CsvReader.Create(path: _root + "example.csv", tableName: "TestTable", connectionString: _connectionString);
            bool       success    = csv.OutputTableDefinition(outputPath);
            string     error      = csv.Error;

            csv.Dispose();

            if (error != null)
            {
                throw new Exception(error);
            }

            Assert.IsTrue(success);
        }
コード例 #3
0
ファイル: Tests.cs プロジェクト: jbonfardeci/EasyCsv
        public void ImportCsv()
        {
            ICsvReader csv       = CsvReader.Create(path: _root + "example.csv", tableName: "TestTable", connectionString: _connectionString);
            long       rowsAdded = csv.ImportCsv();
            int        rowCount  = csv.DataTable.Rows.Count;
            string     error     = csv.Error;

            csv.Dispose();

            if (error != null)
            {
                throw new Exception(error);
            }

            Assert.IsTrue(rowsAdded == rowCount);
        }
コード例 #4
0
        static void TestSpecificReader()
        {
            var csvFiles = new String[] {
                //@"../TestData.Csv/csv-bigdata.csv",
                @"../TestData.Csv/csv-comma-delimited.csv",
                //@"../TestData.Csv/csv-lumentest2.csv",
                //@"../TestData.Csv/csv-lumentest3.csv",
                @"../TestData.Csv/csv-macintosh.csv",
                @"../TestData.Csv/csv-ms-dos.csv",
                @"../TestData.Csv/csv-ms-dos-complex.csv",
                //@"../TestData.Csv/csv-students.csv",
                //@"../TestData.Csv/longrowdata.csv",
            };

            var csvReaderSettings = new CsvReaderSettings();

            csvReaderSettings.IgnoreErrors   = true;
            csvReaderSettings.Encoding       = System.Text.Encoding.UTF8;
            csvReaderSettings.SkipEmptyLines = true;

            foreach (var csvFile in csvFiles)
            {
                var csvFilePath = ProcessCsvFile(csvFile);

                Int32 recordCount = 0, cellCount = 0;
                var   fileSize = new FileInfo(csvFilePath).Length;

                var startTime = DateTime.Now;
                using (var reader = CsvReader.Create(csvFilePath, csvReaderSettings))
                {
                    foreach (var data in reader)
                    {
                        ++recordCount;
                        cellCount += data.Count;
                    }
                }
                var ellapsed = (DateTime.Now - startTime).TotalSeconds;

                ellapsed = ellapsed == 0 ? 0.000003 : ellapsed;
                var speed = (fileSize / MB / ellapsed).ToString("0.00");
                Console.WriteLine("RC: {0,-9}CC: {1,-10}T(s): {2,-11}S:{3}M/s",
                                  recordCount, cellCount, ellapsed, speed);
                Console.WriteLine("======================");
            }
            Console.WriteLine();
        }