/// <summary> /// Gets a high level representation of the first table in the file. /// </summary> /// <param name="ignoreErrors">If true, the reader will not throw an exception when it encounters unexpected data.</param> /// <returns></returns> public Table BuildTable(bool ignoreErrors = false) { var tableNameDefinitions = TpsFile.GetTableNameRecords(); var tableDefinitions = TpsFile.GetTableDefinitions(ignoreErrors: ignoreErrors); var firstTableDefinition = tableDefinitions.First(); var dataRecords = GatherDataRecords(firstTableDefinition.Key, firstTableDefinition.Value, ignoreErrors); var memoRecords = GatherMemoRecords(firstTableDefinition.Key, firstTableDefinition.Value, ignoreErrors); IEnumerable <(int recordNumber, IReadOnlyDictionary <string, TpsObject> nameValuePairs)> unifiedRecords = Enumerable.Concat(dataRecords, memoRecords) .GroupBy(numberNVPairs => numberNVPairs.recordNumber) .Select(groupedNumberNVPairs => ( recordNumber: groupedNumberNVPairs.Key, nameValuePairs: (IReadOnlyDictionary <string, TpsObject>)groupedNumberNVPairs .SelectMany(pair => pair.nameValuePairs) .ToDictionary(kv => kv.Key, kv => kv.Value))); var rows = unifiedRecords.Select(r => new Row(r.recordNumber, r.nameValuePairs)); string tableName = tableNameDefinitions .First(n => n.TableNumber == firstTableDefinition.Key).Header.Name; var table = new Table(tableName, rows); return(table); }
/// <summary> /// Gets a high level representation of the first table in the file. /// </summary> /// <param name="ignoreErrors">If true, the reader will not throw an exception when it encounters unexpected data.</param> /// <returns></returns> public Table BuildTable(bool ignoreErrors = false) { var tableNameDefinitions = TpsFile.GetTableNameRecords(); var tableDefinitions = TpsFile.GetTableDefinitions(ignoreErrors: ignoreErrors); var firstTableDefinition = tableDefinitions.First(); var dataRecords = GatherDataRecords(firstTableDefinition.Key, firstTableDefinition.Value, ignoreErrors); var memoRecords = GatherMemoRecords(firstTableDefinition.Key, firstTableDefinition.Value, ignoreErrors); var unifiedRecords = new Dictionary <int, Dictionary <string, TpsObject> >(); foreach (var dataKvp in dataRecords) { unifiedRecords.Add(dataKvp.Key, dataKvp.Value.ToDictionary(pair => pair.Key, pair => pair.Value)); } foreach (var memoRecord in memoRecords) { int recordNumber = memoRecord.Key; var dataNameValues = dataRecords[recordNumber]; foreach (var memoNameValue in memoRecord.Value) { unifiedRecords[recordNumber].Add(memoNameValue.Key, memoNameValue.Value); } } var rows = unifiedRecords.Select(r => new Row(DeserializerContext, r.Key, r.Value)); string tableName = tableNameDefinitions .First(n => n.TableNumber == firstTableDefinition.Key).Header.Name; var table = new Table(tableName, rows); return(table); }