Skip to content

Commit fc5d316

Browse files
authored
Merge pull request #2286 from BEXIS2/rc
Rc
2 parents e26bc4f + c9badc1 commit fc5d316

File tree

15 files changed

+389
-433
lines changed

15 files changed

+389
-433
lines changed

Components/IO/BExIS.IO.Tests/Transform/Input/AsciiReaderTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,29 @@ public void rowToList_RowAsQuotesAndSeperatorInQuotes_ReturnExpectedListOfString
121121
Assert.That(values, Is.EquivalentTo(expectedOutcome));
122122
}
123123

124+
[Test]
125+
public void rowToList_RowAsOneVariablewithQuotesAndSeperatorInQuotes_ReturnExpectedListOfStrings()
126+
{
127+
//Arrange
128+
string row = "V1,V2,'V3,V4'";
129+
List<string> expectedOutcome = new List<string> { "V1", "V2", "V3,V4" };
130+
131+
AsciiFileReaderInfo info = new AsciiFileReaderInfo();
132+
info.Seperator = TextSeperator.comma;
133+
134+
AsciiReader reader = new AsciiReader(new StructuredDataStructure(), info);
135+
136+
//Act
137+
138+
List<string> values = reader.rowToList(row,
139+
AsciiFileReaderInfo.GetSeperator(TextSeperator.comma));
140+
141+
//Assert
142+
Assert.That(values.Count, Is.EqualTo(expectedOutcome.Count));
143+
Assert.That(values, Is.EquivalentTo(expectedOutcome));
144+
}
145+
146+
124147
[Test]
125148
public void ValidateRow_runNotValid_LimitErrors()
126149
{

Components/IO/BExIS.IO.Tests/Transform/Input/StructureAnalyzerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void SuggestSystemTypes_Valid_ResultWithCorrectTypes(int n)
249249
StructureAnalyser structureAnalyser = new StructureAnalyser();
250250

251251
//Act
252-
var result = structureAnalyser.SuggestSystemTypes(rows.GetRange(0, n), TextSeperator.semicolon, DecimalCharacter.comma, new List<string>());
252+
var result = structureAnalyser.SuggestSystemTypes(rows.GetRange(0, n),TextMarker.doubleQuotes, TextSeperator.semicolon, DecimalCharacter.comma, new List<string>());
253253

254254
//Assert
255255
Assert.NotNull(result);
@@ -294,7 +294,7 @@ public void SuggestSystemTypes_WithTestData_ResultWithCorrectTypes()
294294
StructureAnalyser structureAnalyser = new StructureAnalyser();
295295

296296
//Act
297-
var result = structureAnalyser.SuggestSystemTypes(rows, TextSeperator.semicolon, DecimalCharacter.comma, new List<string>());
297+
var result = structureAnalyser.SuggestSystemTypes(rows, TextMarker.doubleQuotes, TextSeperator.semicolon, DecimalCharacter.comma, new List<string>());
298298

299299
//Assert
300300
Assert.NotNull(result);
@@ -321,7 +321,7 @@ public void SuggestSystemTypes_ValidDateTypes_ResultWithCorrectTypes(int n)
321321
dateValues.Add("2022-12-24"); // yyyy-MM-dd
322322

323323
//Act
324-
var result = structureAnalyser.SuggestSystemTypes(rows.GetRange(0, n), TextSeperator.semicolon, DecimalCharacter.comma, new List<string>());
324+
var result = structureAnalyser.SuggestSystemTypes(rows.GetRange(0, n), TextMarker.doubleQuotes, TextSeperator.semicolon, DecimalCharacter.comma, new List<string>());
325325

326326
//Assert
327327
Assert.NotNull(result);
@@ -334,7 +334,7 @@ public void SuggestSystemTypes_ValidWithMissingValues_ResultWithCorrectTypes()
334334
StructureAnalyser structureAnalyser = new StructureAnalyser();
335335

336336
//Act
337-
var result = structureAnalyser.SuggestSystemTypes(rowWithMissingValues, TextSeperator.semicolon, DecimalCharacter.comma, missingValueList);
337+
var result = structureAnalyser.SuggestSystemTypes(rowWithMissingValues, TextMarker.doubleQuotes, TextSeperator.semicolon, DecimalCharacter.comma, missingValueList);
338338

339339
//Assert
340340
Assert.NotNull(result);

Components/IO/BExIS.IO.Transform.Input/AsciiReader.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,28 @@ public List<string> rowToList(string line, char seperator)
988988
return line.Split(seperator).ToList();
989989
}
990990

991+
/// <summary>
992+
/// Convert a row as a string to a list of strings based on offset,seperator and textmarker
993+
/// </summary>
994+
/// <remarks></remarks>
995+
/// <seealso cref=""/>
996+
/// <param name="line">Row as a string</param>
997+
/// <param name="seperator">Character used as TextSeparator</param>
998+
/// <param name="textMarker">Character used as TextMarker</param>
999+
/// <param name="offset">offset to skip values from begin</param>
1000+
/// <returns>List of values</returns>
1001+
public List<string> RowToList(string line, char seperator, char textMarker, int offset = 0)
1002+
{
1003+
List<string> tempRow = new List<string>();
1004+
1005+
tempRow = new List<string>();
1006+
tempRow = TextMarkerHandling(line, seperator,textMarker);
1007+
1008+
//if a offset is marked in the file reader information the offset needs to skip from the complete string array
1009+
return tempRow.Skip(offset).ToList();
1010+
//return line.Split(seperator).ToList();
1011+
}
1012+
9911013
private List<string> values;
9921014
private List<string> temp;
9931015

Components/IO/BExIS.IO.Transform.Input/StructureAnalyser.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,20 @@ public List<string> GetRandowRows(List<string> rows, int numberOfRows)
457457
throw new NotImplementedException();
458458
}
459459

460-
public Dictionary<int, Type> SuggestSystemTypes(List<string> rows, TextSeperator delimeter, DecimalCharacter decimalCharacter, List<string> missingValues)
460+
public Dictionary<int, Type> SuggestSystemTypes(List<string> rows,TextMarker textMarker, TextSeperator delimeter, DecimalCharacter decimalCharacter, List<string> missingValues)
461461
{
462462
Dictionary<int, List<Type>> source = new Dictionary<int, List<Type>>();
463463
Dictionary<int, Type> result = new Dictionary<int, Type>();
464464

465465
// get type checks
466466
checks = getDataTypeChecks(decimalCharacter);
467467

468+
// validate input
469+
AsciiFileReaderInfo info = new AsciiFileReaderInfo();
470+
info.Seperator = delimeter;
471+
info.TextMarker = textMarker;
472+
AsciiReader reader = new AsciiReader(new StructuredDataStructure(), info);
473+
468474
// create dictionary with types per column
469475
char seperator = AsciiFileReaderInfo.GetSeperator(delimeter);
470476
int numberOfRow = rows.First().Split(seperator).Count();
@@ -477,8 +483,11 @@ public Dictionary<int, Type> SuggestSystemTypes(List<string> rows, TextSeperator
477483
// go throw each row
478484
foreach (var row in rows)
479485
{
486+
//
487+
var cells = reader.rowToList(row, seperator);
488+
480489
//split row based on sepeartor
481-
foreach (var cell in row.Split(seperator).Select((x, i) => new { Value = x, Index = i }))
490+
foreach (var cell in cells.Select((x, i) => new { Value = x, Index = i }))
482491
{
483492
//update possible list of types by check the value against the existing list
484493
source[cell.Index] = checkValue(cell.Value, source[cell.Index], missingValues);

0 commit comments

Comments
 (0)