public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUSEnglish() { // Arrange CsvFileDescription fileDescription_namesUs = new CsvFileDescription { SeparatorChar = ',', IgnoreUnknownColumns = true, UseFieldIndexForReadingData = true, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; string testInput = "AAAAAAAA,__,34.184,05/23/08" + Environment.NewLine + "BBBBBBBB,__,10.311,05/12/12" + Environment.NewLine + "CCCCCCCC,__,12.000,12/23/08"; var expected = new[] { new ProductDataSpecificFieldIndex { Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23), }, new ProductDataSpecificFieldIndex { Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12), }, new ProductDataSpecificFieldIndex { Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23), } }; AssertRead(testInput, fileDescription_namesUs, expected); }
public void GoodFileNoSeparatorCharUseOutputFormatForParsingUSEnglish() { // Arrange CsvFileDescription fileDescription_namesUs = new CsvFileDescription { NoSeparatorChar = true, UseOutputFormatForParsingCsvValue = true, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; const string testInput = @"AAAAAAAA34.18405/23/08 BBBBBBBB10.31105/12/12 CCCCCCCC12.00012/23/08"; var expected = new[] { new ProductDataCharLength { Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23), } }; // Act and Assert AssertRead(testInput, fileDescription_namesUs, expected); }
public void GoodFileUsingOutputFormatForParsingDatesCharUSEnglish() { CsvFileDescription fileDescription_namesUs = new CsvFileDescription { SeparatorChar = ';', FirstLineHasColumnNames = false, UseOutputFormatForParsingCsvValue = true, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; string testInput = "AAAAAAAA;052308" + Environment.NewLine + "BBBBBBBB;051212" + Environment.NewLine + "CCCCCCCC;122308"; var expected = new[] { new ProductDataParsingOutputFormat { Name = "AAAAAAAA", StartDate = new DateTime(2008, 5, 23), }, new ProductDataParsingOutputFormat { Name = "BBBBBBBB", StartDate = new DateTime(2012, 5, 12), }, new ProductDataParsingOutputFormat { Name = "CCCCCCCC", StartDate = new DateTime(2008, 12, 23), } }; AssertRead(testInput, fileDescription_namesUs, expected); }
public void TestInitialize() { _description = new CsvFileDescription { SeparatorChar = ',', FirstLineHasColumnNames = true, IgnoreUnknownColumns = true, }; _input = @"Id,Name,Last Name,Age,City 1,John,Doe,15,Washington 2,Jane,Doe,20,New York "; Expected = new[] { new Person { Name = "John", LastName = "Doe", Age = 15 }, new Person { Name = "Jane", LastName = "Doe", Age = 20 } }; _stream = _input.GetStreamReader(); _dataAccess = new FileDataAccess(_stream, _description); _reader = _dataAccess.ReadDataPreparation<Person>(null); _dataAccess.Row = new DataRow(); }
public void GoodFileNoSeparatorCharUSEnglish() { // Arrange CsvFileDescription fileDescription_namesUs = new CsvFileDescription { NoSeparatorChar = true, UseOutputFormatForParsingCsvValue = false, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; const string testInput = @"AAAAAAAA34.18405/23/08 BBBBBBBB10.31105/12/12 CCCCCCCC12.00012/23/08"; var expected = new[] { new ProductDataCharLength { Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23), } }; // Act and Assert FileDataAccess dataAccess = new FileDataAccess(testInput.GetStreamReader(), fileDescription_namesUs); RowReader<ProductDataCharLength> reader = dataAccess.ReadDataPreparation<ProductDataCharLength>(null); dataAccess.Row = new DataRow(); FieldMapperReading<ProductDataCharLength> fm = new FieldMapperReading<ProductDataCharLength>( fileDescription_namesUs, null, false); List<int> charLengths = fm.GetCharLengths(); Assert.AreEqual(charLengths.Count, 3); bool firstRow = true; List<ProductDataCharLength> actual=new List<ProductDataCharLength>(); while (dataAccess.Cs.ReadRow(dataAccess.Row, charLengths)) { if ((dataAccess.Row.Count == 1) && ((dataAccess.Row[0].Value == null) || (string.IsNullOrEmpty(dataAccess.Row[0].Value.Trim())))) { continue; } bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, firstRow); if (readingResult) { actual.Add(reader.Obj); } firstRow = false; } AssertCollectionsEqual(actual, expected); }
public Task<int> ImportStat(StreamReader reader, CsvFileDescription fileDescriptionNamesUs) { return Task.Run(() => { List<PreciseCoverage4GCsv> csvInfos = new List<PreciseCoverage4GCsv>(); csvInfos.AddRange(CsvContext.Read<PreciseCoverage4GCsv>(reader, fileDescriptionNamesUs)); int count = cellStatService.Save(csvInfos); _timeTownStatService.Save(csvInfos); return count; }); }
public void GoodFileCommaDelimitedWithTrailingSeparatorChars() { // Arrange CsvFileDescription fileDescription_namesUs = new CsvFileDescription { SeparatorChar = ',', // default is ',' FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, // default is false FileCultureName = "en-US", // default is the current culture IgnoreTrailingSeparatorChar = true }; const string testInput = @"Name, Weight, StartDate, LaunchTime, NbrAvailable,Onsale,ShopsAvailable, Code, Price, Description, moonbuggy, 34.184, 5/23/08, 5-May-2009 4:11 pm, 1205, true, ""Paris, New York"", 1F, $540.12, newly launched product, ""mouse trap"",45E-5, 1/2/1985, ""7 August 1988, 0:00 am"", ""4,030"", FALSE, ""This field has a newline"", 100, ""$78,300"", ""This field has quotes(""""), and two newlines and a quoted """"string"""""" dog house, ""45,230,990"",29 Feb 2004, , -56, True,"""", FF10, ""12,008"","; var expected = new[] { new ProductData { Name = "moonbuggy", Weight = 34.184, StartDate = new DateTime(2008, 5, 23), LaunchTime = new DateTime(2009, 5, 5, 16, 11, 0), NbrAvailable = 1205, Onsale = true, ShopsAvailable = "Paris, New York", HexProductCode = 31, RetailPrice = 540.12M, Description = "newly launched product" }, new ProductData { Name = "mouse trap", Weight = 45E-5, StartDate = new DateTime(1985, 1, 2), LaunchTime = new DateTime(1988, 8, 7, 0, 0, 0), NbrAvailable = 4030, Onsale = false, ShopsAvailable = @"This field has a newline", HexProductCode = 256, RetailPrice = 78300M, Description = @"This field has quotes(""), and two newlines and a quoted ""string""" }, new ProductData { Name = "dog house", Weight = 45230990, StartDate = new DateTime(2004, 2, 29), LaunchTime = default(DateTime), NbrAvailable = -56, Onsale = true, ShopsAvailable = "", HexProductCode = 65296, RetailPrice = 12008M, Description = null } }; // Act and Assert AssertRead(testInput, fileDescription_namesUs, expected); }
public void TestInitialize() { _fileDescriptionNamesUs = new CsvFileDescription { SeparatorChar = '\t', IgnoreUnknownColumns = true, FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, // default is false FileCultureName = "en-US" // default is the current culture }; _testInput = @"Index Time Longitude Latitude eNodeBID SectorID Cell ID PCI RSRP (dBm) SINR (dB) PDSCH BLER WideBand CQI MCS Average UL /s MCS Average DL /s PDCP Throughput DL (bps) PDCP Throughput UL (bps) Event Message Type 0 13:58:08:359 -9999 -9999 491308 48 49130848 276 -102.18 10.10 9.60 10 17 14 10749096 223680 Inherit Params Set(Event)"; }
public void GoodFileCommaDelimitedNamesInFirstLineNLnl() { // Arrange List<ProductData> dataRows_Test = new List<ProductData> { new ProductData { RetailPrice = 4.59M, Name = "Wooden toy", StartDate = new DateTime(2008, 2, 1), NbrAvailable = 67 }, new ProductData { Onsale = true, Weight = 4.03, ShopsAvailable = "Ashfield", Description = "" }, new ProductData { Name = "Metal box", LaunchTime = new DateTime(2009, 11, 5, 4, 50, 0), Description = "Great\nproduct" } }; CsvFileDescription fileDescription_namesNl2 = new CsvFileDescription { SeparatorChar = ',', FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, TextEncoding = Encoding.Unicode, FileCultureName = "nl-Nl" // default is the current culture }; string expected = @"Name,StartDate,LaunchTime,Weight,ShopsAvailable,Code,Price,Onsale,Description,NbrAvailable,UnusedField Wooden toy,1-2-2008,01 jan 00:00:00,""000,000"",,0,""€ 4,59"",False,,67, ,1-1-0001,01 jan 00:00:00,""004,030"",Ashfield,0,""€ 0,00"",True,"""",0, Metal box,1-1-0001,05 nov 04:50:00,""000,000"",,0,""€ 0,00"",False,""Great product"",0, "; // Act and Assert AssertWrite(dataRows_Test, fileDescription_namesNl2, expected); }
public void GoodFileTabDelimitedNoNamesInFirstLineNLnl() { // Arrange CsvFileDescription fileDescription_nonamesNl = new CsvFileDescription { SeparatorChar = '\t', // tab character FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, FileCultureName = "nl-NL" // default is the current culture }; const string testInput = "moonbuggy\t 23/5/08\t 5-Mei-2009 16:11 pm\t 34.184\t \"Paris, New York\"\t 1F\t €540,12\t true\t newly launched product\n\"mouse trap\"\t 2/1/1985\t \"7 Augustus 1988\t 0:00\"\t45E-5\t \"This field has\na newline\"\t 100\t \"€78.300\"\t FALSE\t \"This field has quotes(\"\"), and\r\ntwo newlines\r\nand a quoted \"\"string\"\"\"\r\ndog house\t29 Feb 2004\t \t \"45.230.990\"\t\"\"\t FF10\t \"12.008\"\t True"; var expected = new[] { new ProductData { Name = "moonbuggy", Weight = 34184, StartDate = new DateTime(2008, 5, 23), LaunchTime = new DateTime(2009, 5, 5, 16, 11, 0), NbrAvailable = 0, Onsale = true, ShopsAvailable = "Paris, New York", HexProductCode = 31, RetailPrice = 540.12M, Description = "newly launched product" }, new ProductData { Name = "mouse trap", Weight = 45E-5, StartDate = new DateTime(1985, 1, 2), LaunchTime = new DateTime(1988, 8, 7, 0, 0, 0), NbrAvailable = 0, Onsale = false, ShopsAvailable = @"This field has a newline", HexProductCode = 256, RetailPrice = 78300M, Description = @"This field has quotes(""), and two newlines and a quoted ""string""" }, new ProductData { Name = "dog house", Weight = 45230990, StartDate = new DateTime(2004, 2, 29), LaunchTime = default(DateTime), NbrAvailable = 0, Onsale = true, ShopsAvailable = "", HexProductCode = 65296, RetailPrice = 12008M, Description = null } }; // Act and Assert AssertRead(Util.NormalizeString(testInput), fileDescription_nonamesNl, expected); }
public Task<int> ImportStat(StreamReader reader, CsvFileDescription fileDescriptionNamesUs) { return Task.Run(() => { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10*(_approximateTopnsImport + 1); i++) { string content = reader.ReadLine(); if (!string.IsNullOrEmpty(content)) { sb.Append(content + "\n"); } } string testInput = sb.ToString(); List<TopDrop2GCellCsv> stats = CsvContext.ReadString<TopDrop2GCellCsv>(testInput, fileDescriptionNamesUs).ToList(); return _service.ImportStats(stats, _approximateTopnsImport*10, Date); }); }
public void TestInitialize() { fileDescription_namesUs = new CsvFileDescription { SeparatorChar = '\t', IgnoreUnknownColumns = true, FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, // default is false FileCultureName = "en-US" // default is the current culture }; testInput = @"Index Time Longitude Latitude eNodeBID SectorID PCI SINR (dB) RSRP (dBm) WideBand CQI MCS Average DL /s PDCP Throughput DL (bps) Event Message Type 0 16:04:05:328 -9999 -9999 488507 2 278 13.10 -97.75 8 10 13075264 Inherit Params Set(Event) 1 16:04:05:328 -9999 -9999 488507 2 278 13.10 -97.75 11 10 13075264 LTE LL1 PUCCH CSF log 2 16:04:05:328 -9999 -9999 488507 2 278 13.10 -97.75 11 10 13075264 LTE ML1 PUSCH power control 3 16:04:05:328 -9999 -9999 488507 2 278 13.10 -97.75 11 10 13075264 LTE LL1 PCFICH decoding results 4 16:04:05:328 -9999 -9999 488507 2 278 13.10 -97.75 11 10 13075264 RRC Connection ReconfigurationLTE Handover Request; LTE ML1 PUCCH power control 5 16:04:05:328 -9999 -9999 488507 2 278 13.10 -97.75 11 10 13075264 LTE ML1 Uplink PKT build indication 6 16:04:05:328 -9999 -9999 488507 2 278 19.40 -97.06 11 10 13075264 LTE_Cell_List 7 16:04:05:390 -9999 -9999 488507 2 278 19.40 -97.06 11 10 13075264 LTE LL1 PSS results 8 16:04:05:390 -9999 -9999 488507 2 278 19.40 -97.06 11 10 13075264 LTE LL1 SSS results 9 16:04:05:453 -9999 -9999 488507 2 278 19.40 -97.06 11 10 13075264 LTE ML1 Uplink PKT build indication 10 16:04:05:531 -9999 -9999 488507 2 278 19.40 -97.06 11 10 13075264 LTE ML1 Uplink PKT build indication 11 16:04:05:531 114.298796666667 22.6054766666667 488507 2 278 16.20 -95.93 11 10 13075264 FTP Download Connect StartFTP Download Connect Success; LTE_Cell_List 12 16:04:05:718 114.298793809524 22.605475 488507 2 278 16.20 -95.93 11 10 13075264 FTP Download Login SuccessFTP Download Reset Support; LTE ML1 Uplink PKT build indication 13 16:04:05:781 114.298790952381 22.6054733333333 488507 2 278 16.20 -95.93 11 10 13075264 LTE ML1 Uplink PKT build indication 14 16:04:05:781 114.298788095238 22.6054716666667 488507 2 278 15.10 -96.68 11 10 13075264 LTE_Cell_List 15 16:04:05:843 114.298785238095 22.60547 488507 2 278 15.10 -96.68 8 10 13075264 LTE LL1 PUCCH CSF log 16 16:04:05:843 114.298782380952 22.6054683333333 488507 2 278 15.10 -96.68 8 10 13075264 LTE LL1 PCFICH decoding results 17 16:04:05:843 114.29877952381 22.6054666666667 488507 2 278 15.10 -96.68 8 10 13075264 FTP Download Send RETR LTE ML1 Uplink PKT build indication 18 16:04:05:906 114.298776666667 22.605465 488507 2 278 15.10 -96.68 8 10 13075264 LTE ML1 Uplink PKT build indication 19 16:04:05:906 114.298773809524 22.6054633333333 488507 2 278 15.10 -96.68 8 10 13075264 LTE LL1 PSS results 20 16:04:05:906 114.298770952381 22.6054616666667 488507 2 278 15.10 -96.68 8 10 13075264 FTP Download First Data LTE LL1 SSS results 21 16:04:05:968 114.298768095238 22.60546 488507 2 278 19.20 -96.93 8 10 13075264 LTE_Cell_List 22 16:04:06:031 114.298765238095 22.6054583333333 488507 2 278 19.20 -96.93 8 10 13075264 LTE ML1 PUCCH power control 23 16:04:06:031 114.298762380952 22.6054566666667 488507 2 278 19.20 -96.93 8 10 13075264 LTE ML1 Uplink PKT build indication 24 16:04:06:031 114.29875952381 22.605455 488507 2 278 19.20 -96.93 8 10 13075264 LTE ML1 PUSCH power control 25 16:04:06:031 114.298756666667 22.6054533333333 488507 2 278 19.20 -96.93 8 10 13075264 LTE ML1 Uplink PKT build indication"; originalLogs = CsvContext.ReadString<LogRecord>(testInput, fileDescription_namesUs).ToList(); }
public void TestInitialize() { _description = new CsvFileDescription { SeparatorChar = ',', FirstLineHasColumnNames = true, IgnoreUnknownColumns = true, }; _input = @"Id,Name,Last Name,Age,City 1,John,Doe,15,Washington"; byte[] stringAsByteArray = Encoding.UTF8.GetBytes(_input); Stream stream = new MemoryStream(stringAsByteArray); _sr = new StreamReader(stream, Encoding.UTF8); _dataAccess = new FileDataAccess(_sr, _description); _cs = new CsvStream(_sr, null, _description.SeparatorChar, _description.IgnoreTrailingSeparatorChar); _row = new DataRow(); _fm = new FieldMapperReading<Person>(_description, null, false); _ae = new AggregatedException(typeof(Person).ToString(), null, _description.MaximumNbrExceptions); _reader = new RowReader<Person>(_description, _ae); }
public Task<int> ImportStat(StreamReader reader, CsvFileDescription fileDescriptionNamesUs) { throw new NotImplementedException(); }
public ActionResult ExportStat(string fileName) { IEnumerable<MrsCellDateView> results = RutraceStatContainer.MrsStats; if (results == null) { return Redirect("Import"); } string absoluFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "uploads/", fileName); CsvFileDescription fileDescription = new CsvFileDescription { SeparatorChar = ',', FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = true, TextEncoding = Encoding.GetEncoding("GB2312") }; CsvContext.Write(results, absoluFilePath, fileDescription); return File(new FileStream(absoluFilePath, FileMode.Open), "application/octet-stream", Server.UrlEncode(fileName)); }
protected void HugelandDescriptionInitialize() { fileDescription_namesUs = new CsvFileDescription { SeparatorChar = ',', IgnoreUnknownColumns = true, FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, // default is false FileCultureName = "en-US" // default is the current culture }; }