private static void AddLineToResult(string csvLine, MemoryFaceIdToNameLookup result, FaceIdToNameCsvSourceSettings settings) { string[] entry = csvLine.Split(','); if (entry.Length < GetExpectedColumns(settings)) { string message = $"{settings.CsvFilePath} (line {GetCurrentLine(result, settings)}): " + " Expected {GetExpectedColumns(settings)} fields but found only {entry.Length}."; throw new ArgumentOutOfRangeException(nameof(settings), message); } result.dictionary.Add(Guid.Parse(entry[settings.FaceIdIndex]), entry[settings.NameIndex]); }
public static MemoryFaceIdToNameLookup FromCsvStream(TextReader csvReader, FaceIdToNameCsvSourceSettings settings) { Guard.Argument(csvReader, nameof(csvReader)).NotNull(); Guard.Argument(settings, nameof(settings)).NotNull(); Guard.Argument(settings.FaceIdIndex, nameof(settings.FaceIdIndex)).NotNegative(); Guard.Argument(settings.FaceIdIndex, nameof(settings.NameIndex)).NotNegative(); SkipHeaderRow(csvReader, settings); string csvLine; var result = new MemoryFaceIdToNameLookup(); while ((csvLine = csvReader.ReadLine()) != null) { AddLineToResult(csvLine, result, settings); } return(result); }
private static int GetCurrentLine(MemoryFaceIdToNameLookup result, FaceIdToNameCsvSourceSettings settings) { return(result.dictionary.Count + (settings.HasHeaderRow ? 1 : 0)); }