public void StartParse(CsvSettings settings) { StartSomething(() => Parse(settings, new DiagnosticTimer(), PluginBase.CurrentScintillaGateway.GetAllText(), NotepadPPGateway.GetCurrentBufferId())); }
private void Parse(CsvSettings csvSettings, DiagnosticTimer watch, string text, IntPtr bufferId) { var data = csvSettings.Parse(text); watch.Checkpoint("Parse"); var columnTypes = new CsvColumnTypes(data, csvSettings); try { Main.DataStorage.SaveData(bufferId, data, columnTypes); } catch (Exception ex) { this.ErrorMessage("Error when saving data to database:\n" + ex.Message); return; } watch.Checkpoint("Saved to DB"); this.UiThread(() => txbQuery.Text = "SELECT * FROM THIS"); Execute(bufferId, watch); var diagnostic = watch.LastCheckpoint("Resize"); Trace.TraceInformation(diagnostic); if (Main.Settings.DebugMode) { this.Message(diagnostic); } }
/// <summary> /// Generates Intraday Report for current date and save report to the file based on provided settings. /// </summary> /// <param name="reportSettings"></param> /// <param name="csvSettings"></param> /// <returns></returns> public async Task <string> GenerateIntradayReportAsync(ReportSettings reportSettings, CsvSettings csvSettings) { string reportFilePath = null; try { _logger.Info("Intraday Report generation was started."); DateTime utcReportDate = DateTime.UtcNow; reportFilePath = GenerateReportFilePath(utcReportDate, reportSettings); using (var fileStream = File.Create(reportFilePath)) { await this.GenerateIntradayReportAsync(utcReportDate, csvSettings, fileStream); } _logger.InfoFormat("Intraday Report was generated successfully. File: {0}", reportFilePath); return(reportFilePath); } catch (Exception ex) { _logger.ErrorFormat("Intraday Report generation failed. File: {0}", ex, reportFilePath); throw; } }
public void CsvContainer_SourceListIsValidAndSettingsParameterIsNull_RelevantSettingsParameterAsExpected() { List <List <String> > content = new List <List <String> >() { new List <String>() { "11", "12" }, new List <String>() { "21", "22" }, new List <String>() { "31", "32" }, }; CsvSettings settings = null; CsvContainer instance = new CsvContainer(content, settings); Assert.That(instance.Culture, Is.EqualTo(CultureInfo.CurrentUICulture)); Assert.That(instance.Mappings, Is.InstanceOf <CsvMappings>()); Assert.That(instance.Heading, Is.False); Assert.That(instance.Exactly, Is.False); }
public void Load_FileDoesNotExist_ThrowsFileNotFoundException() { String filename = @"c:\temp\missing-file.csv"; CsvSettings settings = null; Assert.Throws <FileNotFoundException>(() => { CsvImporter <TestClassBase> .Load(filename, settings); }); }
public void Load_DataConversionSucceeds_ResultIsAsExpected() { String content = "Label,Enabled,Number,Currency\r\n" + "Label-1,true,42,\"1,234\"\r\n" + "Label-2,true,42,\"1,234\"\r\n"; CsvSettings settings = new CsvSettings(); List <TestClass4> expected = new List <TestClass4>() { new TestClass4() { Label = "Label-1", Enabled = true, Number = 42, Currency = 1.234m, }, new TestClass4() { Label = "Label-2", Enabled = true, Number = 42, Currency = 1.234m, }, }; using (MemoryStream stream = new MemoryStream(settings.Encoding.GetBytes(content))) { List <TestClass4> actual = CsvImporter <TestClass4> .Load(stream, settings).ToList(); Assert.AreEqual(expected, actual); } }
public void Load_StreamIsNull_ThrowsArgumentNullException() { Stream stream = null; CsvSettings settings = null; Assert.Throws <ArgumentNullException>(() => { CsvImporter <TestClassBase> .Load(stream, settings); }); }
public void Read_StreamIsNull_ThrowsArgumentNullException() { Stream stream = null; CsvSettings settings = null; Assert.Throws <ArgumentNullException>(() => { CsvReader.Read(stream, settings); }); }
public void Sort_DifferentParameters_ResultAsExpected(Int32 column, Boolean heading, SortOrder order, String expected) { List <List <String> > content = new List <List <String> >() { new List <String>() { "HA", "HB", "HC" }, new List <String>() { "11", "12", "13" }, new List <String>() { "21", "22", "23", "24" }, new List <String>() { "31", "32" }, }; CsvSettings settings = new CsvSettings() { Heading = heading }; CsvContainer container = new CsvContainer(content, settings); container.Sort(column, order); Assert.That(this.GetActualContent(container), Is.EqualTo(expected)); }
public void ReadTable_No_Exception_Is_Thrown_When_Read_File_With_All_Products() { var settings = new CsvSettings("", @"../../../../Tmp/corelation_table.csv"); var reader = ReaderFactory.CreateReader(settings); Assert.DoesNotThrow(() => reader.ReadTable(TableType.Correlation)); }
public void Construction_ApplyDefaultValues_ResultIsEqual() { String expected = "Separator: \",\", Encoding: \"utf-8\", Heading: \"True\", Textual: \"False\", Exactly: \"False\", Culture: \"de-DE\", Mappings: TrueValue: \"true\", FalseValue: \"false\", NullValue: \"\", TrueValues: [\"true\", \"1\", \"y\", \"yes\"], FalseValues: [\"false\", \"0\", \"n\", \"no\"], NullValues: [\"<null>\"]"; CsvSettings settings = new CsvSettings(); Assert.AreEqual(expected, settings.ToString()); }
public void Sort_HeaderOrderButHeaderIsInvalid_ThrowsNothing([Values(null, "", " ", "invalid")] String header) { List <List <String> > content = new List <List <String> >() { new List <String>() { "HA", "HB", "HC" }, new List <String>() { "11", "12", "13" }, new List <String>() { "21", "22", "23", "24" }, new List <String>() { "31", "32" }, }; CsvSettings settings = new CsvSettings() { Heading = true }; CsvContainer container = new CsvContainer(content, settings); Assert.That(() => container.Sort(header, SortOrder.Ascending), Throws.Nothing); }
public void CreateReader_Returns_CsvReader_When_CsvSettings_Are_Passed_As_Parameter() { var settings = new CsvSettings("", ""); var reader = ReaderFactory.CreateReader(settings); Assert.IsInstanceOf <CsvReader>(reader); }
public void CsvContainer_SourceListIsValidAndSettingsParameterIsValid_RelevantSettingsParameterAsExpected() { List <List <String> > content = new List <List <String> >() { new List <String>() { "11", "12" }, new List <String>() { "21", "22" }, new List <String>() { "31", "32" }, }; CsvSettings settings = new CsvSettings() { Culture = CultureInfo.InvariantCulture, Mappings = new CsvMappings(), Heading = true, Exactly = true, }; CsvContainer instance = new CsvContainer(content, settings); Assert.That(instance.Culture, Is.SameAs(settings.Culture)); Assert.That(instance.Mappings, Is.SameAs(settings.Mappings)); Assert.That(instance.Heading, Is.True); Assert.That(instance.Exactly, Is.True); }
public void ReadProducts_Returns_Collection_Of_3_Products() { var settings = new CsvSettings(@"../../../Tmp/products.csv", ""); var reader = ReaderFactory.CreateReader(settings); var expected = new List <Product> { new Product() { Id = 1, ProductName = "Rogale impulsowe 18", CategoryId = 15, CategoryName = "Słodycze", AveragePrice = 2.69m }, new Product() { Id = 2, ProductName = "Znicze, wkłady 219", CategoryId = 5, CategoryName = "Niespożywcze", AveragePrice = 4.14m }, new Product() { Id = 3, ProductName = "Nabiał REG 161", CategoryId = 17, CategoryName = "Spożywka świeża", AveragePrice = 1.98m } }; var actual = reader.ReadProducts().ToList(); Assert.Multiple(() => { Assert.AreEqual(3, actual.Count()); CollectionAssert.AreEquivalent(expected, actual); }); }
public void Read_FileDoesNotExist_ThrowsFileNotFoundException() { String filename = @"c:\temp\missing-file.csv"; CsvSettings settings = null; Assert.Throws <FileNotFoundException>(() => { CsvReader.Read(filename, settings); }); }
public void Read_ColumnCountMismatch_ResultAsExpected() { String content = "Label,Enabled,Number,Currency\r\n" + "Label-1,true,42,\"1,234\"\r\n" + "Label-2,false,23\r\n"; CsvSettings settings = new CsvSettings() { Heading = true }; using (MemoryStream stream = new MemoryStream(settings.Encoding.GetBytes(content))) { CsvContainer actual = CsvReader.Read(stream, settings); Assert.That(actual.GetValue <String>("label", 0), Is.EqualTo("Label-1")); Assert.That(actual.GetValue <String>("label", 1), Is.EqualTo("Label-2")); Assert.That(actual.GetValue <Boolean>("ENABLED", 0), Is.EqualTo(true)); Assert.That(actual.GetValue <Boolean>("ENABLED", 1), Is.EqualTo(false)); Assert.That(actual.GetValue <Int32>("NumBER", 0), Is.EqualTo(42)); Assert.That(actual.GetValue <Int32>("NumBER", 1), Is.EqualTo(23)); Assert.That(actual.GetValue <Double>("Currency", 0), Is.EqualTo(1.234)); Assert.That(actual.GetValue <Double>("Currency", 1), Is.EqualTo(null)); } }
public void Can_generate_csv() { var data = new List <string[]> { new[] { "A number", "another number here", "#¤%i" }, new[] { "1", "2", "3" }, new[] { "2", "12", "14" }, new[] { "3", "12", "13" }, new[] { "4", "2", "3" } }; var csvSettings = new CsvSettings(',') { HasHeader = true }; var ctypes = new CsvColumnTypes(data, csvSettings); var tableName = this.DataStorage.SaveData(new IntPtr(10), data, ctypes); var result = this.DataStorage.ExecuteQueryToDataTable("SELECT * FROM " + tableName, new IntPtr(10)); Assert.AreEqual("Anumber", result.Columns[0].ColumnName); string csv; using (var memStream = new MemoryStream()) { var lookup = this.DataStorage.GetUnsafeColumnMaps(new IntPtr(10)); csvSettings.GenerateToStream(result, memStream, lookup); csv = Encoding.UTF8.GetString(memStream.GetBuffer()); } Assert.IsTrue(csv.StartsWith("A number,another number here,#¤%i")); }
public void Serialize_CsvSettingsIsNull_ResultIsEmpty() { CsvSettings settings = null; CsvContainer container = new CsvContainer(1, 1); Assert.That(container.Serialize(settings), Is.Empty); }
public void Serialize_ParametersValid_ResultAsExpected() { String expected = "HA,HB,HC,\r\n11,12,13,\r\n21,22,23,24\r\n31,32,,\r\n"; List <List <String> > content = new List <List <String> >() { new List <String>() { "HA", "HB", "HC" }, new List <String>() { "11", "12", "13" }, new List <String>() { "21", "22", "23", "24" }, new List <String>() { "31", "32" }, }; CsvSettings settings = new CsvSettings(); CsvContainer container = new CsvContainer(content); String actual = container.Serialize(settings); Assert.That(actual, Is.EqualTo(expected)); }
public void Separator_ValidValues_ResultIsEqual(Char separator) { CsvSettings settings = new CsvSettings { Separator = separator }; Assert.AreEqual(separator, settings.Separator); }
private static Product[] FetchProducts() { var settings = new CsvSettings(@"C:\Windows\LeadPrototype\products.csv", ""); var reader = ReaderFactory.CreateReader(settings); var products = reader.ReadProducts().ToArray(); return(products); }
public void Load_SettingsAreNull_ThrowsArgumentNullException() { using (Stream stream = new MemoryStream()) { CsvSettings settings = null; Assert.Throws <ArgumentNullException>(() => { CsvImporter <TestClassBase> .Load(stream, settings); }); } }
public void Read_SettingsAreNull_ThrowsArgumentNullException() { using (Stream stream = new MemoryStream()) { CsvSettings settings = null; Assert.Throws <ArgumentNullException>(() => { CsvReader.Read(stream, settings); }); } }
// Constructor //------------------------------------------------------------------------------------------------------------------------------- public PokemonContext( DbContextOptions <PokemonContext> options, IOptions <ConnectionStrings> connectionstrings, IOptions <CsvSettings> csvSettings, IMapper mapper) : base(options) { _connectionStrings = connectionstrings.Value; _csvSettings = csvSettings.Value; _mapper = mapper; }
public ParseSettings(CsvSettings csvSettings) : this() { txbSep.Text = csvSettings.Separator.ToString(); txbQuoteChar.Text = csvSettings.TextQualifier.ToString(); txbCommentChar.Text = csvSettings.CommentCharacter.ToString(); hasHeaderCheckbox.CheckState = csvSettings.HasHeader.ToCheckboxState(); FixedWidthCheckbox.Checked = csvSettings.FieldWidths != null; }
public ParseSettings(CsvSettings csvSettings) : this() { this.txbSep.Text = csvSettings.Separator.ToString(); this.useQuotesCheckBox.Checked = csvSettings.UseQuotes; this.txbCommentChar.Text = csvSettings.CommentCharacter.ToString(); this.hasHeaderCheckbox.CheckState = csvSettings.HasHeader.ToCheckboxState(); this.FixedWidthCheckbox.Checked = csvSettings.FieldWidths != null; }
public void Write_UsingDefaultSettingsButMappingsSomeDataInvalid_ResultIsAsExpected() { String expected = "\uFEFFLabel,Enabled,Number,Currency\r\n" + "Void,Nope,100,\"1,234\"\r\n" + "Label-2,Yeah,100,\"2,345\"\r\n" + "Void,Nope,100,\"3,456\"\r\n" + "Label-4,Yeah,100,\"4,567\"\r\n" + "Void,Nope,100,\"5,678\"\r\n" + "Label-6,Yeah,100,\"6,789\"\r\n"; MemoryStream stream = new MemoryStream(); CsvSettings settings = new CsvSettings() { Mappings = new CsvMappings() { TrueValue = "Yeah", FalseValue = "Nope", NullValue = "Void" }, }; List <List <Object> > values = new List <List <Object> >() { new List <Object>() { "Label", "Enabled", "Number", "Currency", }, new List <Object>() { null, false, 100, 1.234m, }, new List <Object>() { "Label-2", true, 100, 2.345m, }, new List <Object>() { null, false, 100, 3.456m, }, new List <Object>() { "Label-4", true, 100, 4.567m, }, new List <Object>() { null, false, 100, 5.678m, }, new List <Object>() { "Label-6", true, 100, 6.789m, }, }; CsvWriter.Write(values, stream, settings); String actual = Encoding.UTF8.GetString(stream.ToArray()); Assert.That(actual, Is.EqualTo(expected)); }
// Constructor //------------------------------------------------------------------------------------------------------------------------------- public CsvContext(CsvSettings csvSettings) { _csvSettings = csvSettings; _csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) { HasHeaderRecord = true, Delimiter = "\t" }; }
public void SetUp() { var settings = new CsvSettings(@"../../../Tmp/products.csv", @"../../../Tmp/products_corr_no_header.csv"); var reader = ReaderFactory.CreateReader(settings); _products = reader.ReadProducts().ToList(); _correlationTable = (CorrelationTable)reader.ReadTable(TableType.Correlation); ((CsvSettings)reader.Settings).PathToTable = @"../../../Tmp/substitutes.csv"; _substitutesTable = (SubstitutesTable)reader.ReadTable(TableType.Substitutes); }
public void TestNonDefaultRowDelimiterReading() { var settings = new CsvSettings() { RowDelimiter = "|" }; // also note, that it is single-char, not double char like default. const String csv = "1,2,3|4,\"| as data\",\n\r as data|7"; using (var parser = new CsvParser(csv, settings)) { String[][] rows = parser.ReadToEnd(); Assert.AreEqual(3, rows.Length, "Incorrect number of rows"); CollectionAssert.AreEqual(rows[0], new string[] { "1", "2", "3" }); CollectionAssert.AreEqual(rows[1], new string[] { "4", "| as data", "\n\r as data" }); CollectionAssert.AreEqual(rows[2], new string[] { "7" }); } }
public void TestNonDefaultFieldDelimiterReading() { var settings = new CsvSettings() { FieldDelimiter = '\t' }; const String csv = @"1 2 3 4 "" as data"" , as data 7"; using (var parser = new CsvParser(csv, settings)) { String[][] rows = parser.ReadToEnd(); Assert.AreEqual(3, rows.Length, "Incorrect number of rows"); CollectionAssert.AreEqual(rows[0], new string[] { "1", "2", "3" }); CollectionAssert.AreEqual(rows[1], new string[] { "4", " as data", ", as data" }); CollectionAssert.AreEqual(rows[2], new string[] { "7" }); } }
public void TestNonDefaultQuotingCharacterReading() { var settings = new CsvSettings() { QuotingCharacter = '\'' }; const String csv = @"1,2,3 4,''' as data',"" as data 7"; using (var parser = new CsvParser(csv, settings)) { String[][] rows = parser.ReadToEnd(); Assert.AreEqual(3, rows.Length, "Incorrect number of rows"); CollectionAssert.AreEqual(rows[0], new string[] { "1", "2", "3" }); CollectionAssert.AreEqual(rows[1], new string[] { "4", "' as data", "\" as data" }); CollectionAssert.AreEqual(rows[2], new string[] { "7" }); } }
public CsvBuilder(CsvSettings settings, Stream output) : this() { Settings = settings; Output = output; }