public HelperFile(LoadFileParserWorker parent, string filePath) { FilePath = filePath; RecordCount = 0; uint lineCount = 0; var isFirst = true; uint docNumber = 1; Index = new Dictionary <uint, uint>(); Data = new List <string>(); using (var sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { var columns = sr.ReadLine().Split(new[] { Delimiter }); lineCount++; if (columns.Length < 2) { continue; // Skip empty lines } if (columns.Length != 7) { var errorMessage = String.Format( "File {0} has unrecognized record at line {1}. 7 columns are expected, but {2} are found.", filePath, lineCount, columns.Length); parent.LogMessage(false, errorMessage); Tracer.Error(errorMessage); continue; } Data.Add(columns[2]); if (isFirst) { Index.Add(docNumber, RecordCount); docNumber++; isFirst = false; } else { if (columns[3].ToUpper().Trim() == Yes) { Index.Add(docNumber, RecordCount); docNumber++; } } RecordCount++; } } }
public HelperFileParser(LoadFileParserWorker parent, string filePath) { uint lineCount = 0; using (var sr = new StreamReader(filePath)) { var filePaths = new List <string>(); var keyData = string.Empty; var isFirstRecord = true; FileData = new Dictionary <string, List <string> >(); while (!sr.EndOfStream) { var columns = sr.ReadLine().Split(new[] { Delimiter }); lineCount++; if (columns.Length < 2) { continue; // Skip empty lines } if (columns.Length != 7) { var errorMessage = String.Format( "File {0} has unrecognized record at line {1}. 7 columns are expected, but {2} are found.", filePath, lineCount, columns.Length); parent.LogMessage(false, errorMessage); Tracer.Error(errorMessage); continue; } if (isFirstRecord) { keyData = columns[0]; //Mapping Field Key filePaths.Add(columns[2]); //File Path } if (columns[3].ToUpper().Trim() == Yes && !isFirstRecord) { if (FileData.ContainsKey(keyData)) { FileData[keyData].AddRange(filePaths); } else { FileData.Add(keyData, filePaths); } filePaths = new List <string>(); keyData = columns[0]; } if (!isFirstRecord) { filePaths.Add(columns[2]); } isFirstRecord = false; } //For Last records if (FileData.ContainsKey(keyData)) { FileData[keyData].AddRange(filePaths); } else { FileData.Add(keyData, filePaths); } } }
public HelperFile(LoadFileParserWorker parent, string filePath) { FilePath = filePath; RecordCount = 0; uint lineCount = 0; var isFirst = true; uint docNumber = 1; Index = new Dictionary<uint, uint>(); Data = new List<string>(); using (var sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { var columns = sr.ReadLine().Split(new[] {Delimiter}); lineCount++; if (columns.Length < 2) { continue; // Skip empty lines } if (columns.Length != 7) { var errorMessage = String.Format( "File {0} has unrecognized record at line {1}. 7 columns are expected, but {2} are found.", filePath, lineCount, columns.Length); parent.LogMessage(false, errorMessage); Tracer.Error(errorMessage); continue; } Data.Add(columns[2]); if (isFirst) { Index.Add(docNumber, RecordCount); docNumber++; isFirst = false; } else { if (columns[3].ToUpper().Trim() == Yes) { Index.Add(docNumber, RecordCount); docNumber++; } } RecordCount++; } } }
public HelperFileParser(LoadFileParserWorker parent, string filePath) { uint lineCount = 0; using (var sr = new StreamReader(filePath)) { var filePaths = new List<string>(); var keyData = string.Empty; var isFirstRecord = true; FileData = new Dictionary<string, List<string>>(); while (!sr.EndOfStream) { var columns = sr.ReadLine().Split(new[] { Delimiter }); lineCount++; if (columns.Length < 2) { continue; // Skip empty lines } if (columns.Length != 7) { var errorMessage = String.Format( "File {0} has unrecognized record at line {1}. 7 columns are expected, but {2} are found.", filePath, lineCount, columns.Length); parent.LogMessage(false, errorMessage); Tracer.Error(errorMessage); continue; } if (isFirstRecord) { keyData = columns[0]; //Mapping Field Key filePaths.Add(columns[2]); //File Path } if (columns[3].ToUpper().Trim() == Yes && !isFirstRecord) { if (FileData.ContainsKey(keyData)) { FileData[keyData].AddRange(filePaths); } else { FileData.Add(keyData, filePaths); } filePaths = new List<string>(); keyData = columns[0]; } if (!isFirstRecord) { filePaths.Add(columns[2]); } isFirstRecord = false; } //For Last records if (FileData.ContainsKey(keyData)) { FileData[keyData].AddRange(filePaths); } else { FileData.Add(keyData, filePaths); } } }