internal static CsvFile ReaderGetBasicCSV(IToolSetting parent = null, string id = "BasicCSV") { var readFile = new CsvFile(); readFile.ID = id; readFile.FileFormat.CommentLine = "#"; readFile.FileName = Path.Combine(FileSystemUtils.ExecutableDirectoryName() + @"\TestFiles", "BasicCSV.txt"); var examDateFld = readFile.ColumnAdd(new Column { Name = "ExamDate", DataType = DataType.DateTime }); Debug.Assert(examDateFld != null); examDateFld.ValueFormat.DateFormat = @"dd/MM/yyyy"; readFile.ColumnAdd(new Column { Name = "Score", DataType = DataType.Integer }); readFile.ColumnAdd(new Column { Name = "Proficiency", DataType = DataType.Numeric }); readFile.ColumnAdd(new Column { Name = "IsNativeLang", DataType = DataType.Boolean }); if (parent != null) { parent.Input.Add(readFile); } return(readFile); }
public void Init() { var m_ReadFile = new CsvFile { ID = "Read", FileName = Path.Combine(m_ApplicationDirectory, "BasicCSV.txt") }; var cf = m_ReadFile.ColumnAdd(new Column { Name = "ExamDate", DataType = DataType.DateTime }); cf.DateFormat = @"dd/MM/yyyy"; m_ReadFile.FileFormat.CommentLine = "#"; m_ReadFile.ColumnAdd(new Column { Name = "Score", DataType = DataType.Integer }); m_ReadFile.ColumnAdd(new Column { Name = "Proficiency", DataType = DataType.Numeric }); m_ReadFile.ColumnAdd(new Column { Name = "IsNativeLang", DataType = DataType.Boolean, Ignore = true }); mimicReader.AddSetting(m_ReadFile); ApplicationSetting.ToolSetting.Input.Clear(); ApplicationSetting.ToolSetting.Input.Add(m_ReadFile); }
public void FileFormatColumnFormatAddExisting() { var m_Column = new Column { Name = "Name" }; m_CsvFile.ColumnAdd(m_Column); Assert.AreEqual(2, m_CsvFile.Column.Count); }
public void Init() { CsvFile m_ReadFile = new CsvFile(); m_ReadFile.ID = "Read"; m_ReadFile.FileName = Path.Combine(m_ApplicationDirectory, "BasicCSV.txt"); m_ReadFile.FileFormat.FieldDelimiter = ","; var cf = m_ReadFile.ColumnAdd(new Column { Name = "ExamDate", DataType = DataType.DateTime }); cf.DateFormat = @"dd/MM/yyyy"; m_ReadFile.FileFormat.CommentLine = "#"; m_ReadFile.ColumnAdd(new Column { Name = "Score", DataType = DataType.Integer }); m_ReadFile.ColumnAdd(new Column { Name = "Proficiency", DataType = DataType.Numeric }); m_ReadFile.ColumnAdd(new Column { Name = "IsNativeLang", DataType = DataType.Boolean, Ignore = true }); ApplicationSetting.ToolSetting.Input.Add(m_ReadFile); mimicReader.AddSetting(m_ReadFile); m_WriteFile = new CsvFile(); m_WriteFile.ID = "Write"; m_WriteFile.SqlStatement = m_ReadFile.ID; var add = new Column(); add.Name = "ExamDate"; add.DataType = DataType.DateTime; add.DateFormat = @"MM/dd/yyyy"; add.TimePart = "ExamTime"; m_WriteFile.ColumnAdd(add); m_WriteFile.ColumnAdd(new Column { Name = "Proficiency", Ignore = true }); }
public void Init() { var m_ValueFormatGerman = new ValueFormat(); m_ValueFormatGerman.DataType = DataType.DateTime; m_ValueFormatGerman.DateFormat = @"dd/MM/yyyy"; m_ValueFormatGerman.DateSeparator = "."; m_ValueFormatGerman.DecimalSeparator = ","; m_ValueFormatGerman.False = @"Falsch"; m_ValueFormatGerman.GroupSeparator = "."; m_ValueFormatGerman.NumberFormat = "0.##"; m_ValueFormatGerman.TimeSeparator = ":"; m_ValueFormatGerman.True = @"Wahr"; var ff = new CsvFile(); m_Column.Name = "StartDate"; m_Column.Ignore = true; m_Column.ValueFormat = m_ValueFormatGerman; ff.ColumnAdd(m_Column); Assert.AreEqual("StartDate", m_Column.Name, "Name"); Assert.AreEqual(DataType.DateTime, m_Column.DataType, "DataType"); Assert.IsTrue(m_Column.Convert, "Convert"); Assert.IsTrue(m_Column.Ignore, "Ignore"); }
public void WriteAllFormats() { var pd = new MockProcessDisplay(); var writeFile = new CsvFile { ID = "Write", FileName = Path.Combine(m_ApplicationDirectory, "BasicCSVOut2.txt") }; FileSystemUtils.FileDelete(writeFile.FileName); var setting = Helper.ReaderGetAllFormats(ApplicationSetting.ToolSetting); mimicReader.AddSetting(setting); writeFile.SqlStatement = setting.ID; writeFile.FileFormat.FieldDelimiter = "|"; var cf = writeFile.ColumnAdd(new Column { Name = "DateTime", DataType = DataType.DateTime }); cf.DateFormat = "yyyyMMdd"; cf.TimePartFormat = @"hh:mm"; cf.TimePart = "Time"; var writer = new CsvFileWriter(writeFile, CancellationToken.None); writer.Progress += pd.SetProcess; var res = writer.Write(); Assert.IsTrue(FileSystemUtils.FileExists(writeFile.FileName)); Assert.AreEqual(1065, res, "Records"); }
public void SortColumnByName() { var setting = new CsvFile(); Assert.AreEqual(0, setting.Column.Count); setting.SortColumnByName(null); setting.SortColumnByName(new string[] { "Hello" }); setting.ColumnAdd(new Column() { Name = "BBB" }); setting.ColumnAdd(new Column() { Name = "AAA" }); Assert.AreEqual(2, setting.Column.Count); setting.SortColumnByName(new string[] { "BBB" }); Assert.AreEqual("BBB", setting.Column[0].Name); setting.SortColumnByName(new string[] { "AAA" }); Assert.AreEqual("AAA", setting.Column[0].Name); }
internal static CsvFile ReaderGetAllFormats(IToolSetting parent = null, string id = "AllFormats") { var readFile = new CsvFile { ID = id, FileName = Path.Combine(FileSystemUtils.ExecutableDirectoryName() + @"\TestFiles", "AllFormats.txt"), HasFieldHeader = true }; readFile.FileFormat.FieldDelimiter = "TAB"; var timeFld = readFile.ColumnAdd(new Column { Name = "DateTime", DataType = DataType.DateTime }); Debug.Assert(timeFld != null); timeFld.DateFormat = @"dd/MM/yyyy"; timeFld.TimePart = "Time"; timeFld.TimePartFormat = "HH:mm:ss"; readFile.ColumnAdd(new Column { Name = "Integer", DataType = DataType.Integer }); readFile.ColumnAdd(new Column { Name = "Numeric", DataType = DataType.Numeric }); var numericFld = readFile.GetColumn("Numeric"); Debug.Assert(numericFld != null); numericFld.DecimalSeparator = "."; var doubleFld = readFile.ColumnAdd(new Column { Name = "Double", DataType = DataType.Double }); Debug.Assert(doubleFld != null); doubleFld.DecimalSeparator = "."; readFile.ColumnAdd(new Column { Name = "Boolean", DataType = DataType.Boolean }); readFile.ColumnAdd(new Column { Name = "GUID", DataType = DataType.Guid }); readFile.ColumnAdd(new Column { Name = "Time", Ignore = true }); if (parent != null) { parent.Input.Add(readFile); } return(readFile); }
public void ReadPGP() { var setting = new CsvFile { HasFieldHeader = true, AlternateQuoting = true }; PGPKeyStorageTestHelper.SetApplicationSetting(); setting.FileName = "TestFiles\\BasicCSV.pgp"; setting.ColumnAdd(new Column { Name = "ExamDate", DataType = DataType.DateTime, DateFormat = @"dd/MM/yyyy" }); setting.ColumnAdd(new Column { Name = "ID", DataType = DataType.Integer }); setting.ColumnAdd(new Column { Name = "IsNativeLang", DataType = DataType.Boolean }); using (var test = new CsvFileReader(setting)) { test.Open(true, CancellationToken.None); int row = 0; while (test.Read()) { row++; } Assert.AreEqual(row, test.RecordNumber); Assert.AreEqual(7, row); } }
public void Init() { m_ValidSetting.FileName = Path.Combine(m_ApplicationDirectory, "BasicCSV.txt"); var cf = m_ValidSetting.ColumnAdd(new Column { DataType = DataType.DateTime, Name = "ExamDate" }); Assert.IsNotNull(cf); cf.DateFormat = @"dd/MM/yyyy"; m_ValidSetting.FileFormat.FieldDelimiter = ","; m_ValidSetting.FileFormat.CommentLine = "#"; m_ValidSetting.ColumnAdd(new Column { Name = "Score", DataType = DataType.Integer }); m_ValidSetting.ColumnAdd(new Column { Name = "Proficiency", DataType = DataType.Numeric }); m_ValidSetting.ColumnAdd(new Column { Name = "IsNativeLang", DataType = DataType.Boolean }); }
public void FormColumnUI() { var csvFile = new CsvFile(); csvFile.FileName = FileSystemUtils.ExecutableDirectoryName() + @"\TestFiles\BasicCSV.txt"; var col = new Column(); col.Name = "ExamDate"; col.DataType = DataType.DateTime; csvFile.ColumnAdd(col); using (var ctrl = new FormColumnUI(col, false, csvFile)) { ctrl.Show(); ctrl.Close(); } }
public void GetColumByFieldTest() { var csv = new CsvFile(); Assert.IsNull(csv.GetColumByField("Hello")); var col = new Column() { Name = "Column" }; csv.ColumnAdd(col); csv.Mapping.Add(new Mapping() { FileColumn = "Column", TemplateField = "Field" }); Assert.AreEqual(col, csv.GetColumByField("Field")); }
public void GetDateTimeTest() { var csvFile = new CsvFile { FileName = Path.Combine(m_ApplicationDirectory, "TestFile.txt"), CodePageId = 65001, FileFormat = { FieldDelimiter = "tab" } }; csvFile.ColumnAdd(new Column { Name = "Title", DataType = DataType.DateTime }); using (var test = new CsvFileReader(csvFile)) { test.Open(false, CancellationToken.None); test.Read(); test.GetDateTime(1); } }
public void IssueReader() { var basIssues = new CsvFile { TreatLFAsSpace = true, TryToSolveMoreColumns = true, AllowRowCombining = true, FileName = Path.Combine(m_ApplicationDirectory, "BadIssues.csv") }; basIssues.FileFormat.FieldDelimiter = "TAB"; basIssues.FileFormat.FieldQualifier = string.Empty; basIssues.ColumnAdd(new Column { DataType = DataType.DateTime, DateFormat = "yyyy/MM/dd", DateSeparator = "-", Name = "effectiveDate" }); basIssues.ColumnAdd(new Column { DataType = DataType.DateTime, DateFormat = "yyyy/MM/ddTHH:mm:ss", DateSeparator = "-", Name = "timestamp" }); basIssues.ColumnAdd(new Column { DataType = DataType.Integer, Name = "version" }); basIssues.ColumnAdd(new Column { DataType = DataType.Boolean, Name = "retrainingRequired" }); basIssues.ColumnAdd(new Column { DataType = DataType.Boolean, Name = "classroomTraining" }); basIssues.ColumnAdd(new Column { DataType = DataType.TextToHtml, Name = "webLink" }); var warningList = new RowErrorCollection(); using (var test = new CsvFileReader(basIssues)) { test.Warning += warningList.Add; test.Open(false, CancellationToken.None); // need 22 columns Assert.AreEqual(22, test.GetSchemaTable().Rows.Count()); // This should work test.Read(); Assert.AreEqual(0, warningList.CountRows); Assert.AreEqual("Eagle_sop020517", test.GetValue(0)); Assert.AreEqual("de-DE", test.GetValue(2)); // There are more columns test.Read(); Assert.AreEqual(1, warningList.CountRows); Assert.AreEqual("Eagle_SRD-0137699", test.GetValue(0)); Assert.AreEqual("de-DE", test.GetValue(2)); Assert.AreEqual(3, test.StartLineNumber); test.Read(); Assert.AreEqual("Eagle_600.364", test.GetValue(0)); test.Read(); Assert.AreEqual("Eagle_spt029698", test.GetValue(0)); test.Read(); Assert.AreEqual("Eagle_SRD-0137698", test.GetValue(0)); Assert.AreEqual(2, warningList.CountRows); test.Read(); Assert.AreEqual("Eagle_SRD-0138074", test.GetValue(0)); test.Read(); Assert.AreEqual("Eagle_SRD-0125563", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1004040002982", test.GetValue(0)); Assert.AreEqual(3, warningList.CountRows); test.Read(); Assert.AreEqual("doc_1004040002913", test.GetValue(0)); Assert.AreEqual(10, test.StartLineNumber); Assert.AreEqual(5, warningList.CountRows); test.Read(); Assert.AreEqual("doc_1003001000427", test.GetValue(0)); Assert.AreEqual(12, test.StartLineNumber); test.Read(); Assert.AreEqual("doc_1008017000611", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1004040000268", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1008011000554", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1003001000936", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1200000124471", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1200000134529", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1004040003504", test.GetValue(0)); test.Read(); Assert.AreEqual("doc_1200000016068", test.GetValue(0)); test.Read(); } }