internal VeryLongStringRecord(InfoRecord record) { if (record.SubType != 14 || record.ItemSize != 1) { throw new UnexpectedFileFormatException(); } this.record = record; this.LongStringDictionary = new Dictionary <string, string>(); // Not very efficient, but for now the best way I can come up with // without sacrificing the Inforecords-design. var originalBytes = this.record.Items.Where(item => item[0] != 0).Select(item => item[0]).ToArray(); var dictionaryString = Encoding.ASCII.GetString(originalBytes); // split on tabs: var entries = dictionaryString.Split('\t'); foreach (var entry in entries) { if (!string.IsNullOrEmpty(entry.Trim())) { var values = entry.Split('='); if (values.Length >= 2) { this.LongStringDictionary.Add(values[0], values[1]); } } } }
internal VariableDisplayParameterRecord(InfoRecord record, int variableCount) { if (record.SubType != 11 || record.ItemSize != 4) throw new UnexpectedFileFormatException(); this.record = record; var infoList = new List<VariableDisplayInfo>(); // Record can either have 2 or 3 fields per variable: int fieldCount = this.record.ItemCount / variableCount; int currentItemIndex = 0; for (int variableIndex = 0; variableIndex < variableCount; variableIndex++) { var info = new VariableDisplayInfo(); for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) { var value = BitConverter.ToInt32(this.record.Items[currentItemIndex++], 0); // Measurement type: if (fieldIndex == 0) { if (value == 1) { info.MeasurementType = MeasurementType.Nominal; } else if (value == 2) { info.MeasurementType = MeasurementType.Ordinal; } else if (value == 3) { info.MeasurementType = MeasurementType.Scale; } else { // Default option: info.MeasurementType = MeasurementType.Nominal; } } // Width: if (fieldIndex == 1) { info.Width = value; } // Alignment: if (fieldIndex == 2) { info.Alignment = (Alignment)value; } } infoList.Add(info); } this.VariableDisplayEntries = new VariableDisplayInfoCollection(infoList); }
internal MachineFloatingPointInfoRecord(InfoRecord record) { if (record.SubType != 4 || record.ItemSize != 8 || record.ItemCount != 3) { throw new UnexpectedFileFormatException(); } this.record = record; }
public static InfoRecord ParseNextRecord(BinaryReader reader) { var record = new InfoRecord { SubType = reader.ReadInt32(), ItemSize = reader.ReadInt32(), ItemCount = reader.ReadInt32(), Items = new Collection <byte[]>() }; for (int i = 0; i < record.ItemCount; i++) { record.Items.Add(reader.ReadBytes(record.ItemSize)); } return(record); }
public static InfoRecord ParseNextRecord(BinaryReader reader) { var record = new InfoRecord(); record.SubType = reader.ReadInt32(); record.ItemSize = reader.ReadInt32(); record.ItemCount = reader.ReadInt32(); record.Items = new Collection<byte[]>(); for (int i = 0; i < record.ItemCount; i++) { record.Items.Add(reader.ReadBytes(record.ItemSize)); } return record; }
internal LongVariableNamesRecord(InfoRecord record) { if (record.SubType != 13 || record.ItemSize != 1) throw new UnexpectedFileFormatException(); this.record = record; this.LongNameDictionary = new Dictionary<string, string>(); // Not very efficient, but for now the best way I can come up with // without sacrificing the Inforecords-design. var originalBytes = (from item in this.record.Items select item[0]).ToArray(); var dictionaryString = Encoding.ASCII.GetString(originalBytes); // split on tabs: var entries = dictionaryString.Split('\t'); foreach (var entry in entries) { var values = entry.Split('='); this.LongNameDictionary.Add(values[0], values[1]); } }
internal LongVariableNamesRecord(InfoRecord record) { if (record.SubType != 13 || record.ItemSize != 1) { throw new UnexpectedFileFormatException(); } this.record = record; this.LongNameDictionary = new Dictionary <string, string>(); // Not very efficient, but for now the best way I can come up with // without sacrificing the Inforecords-design. var originalBytes = (from item in this.record.Items select item[0]).ToArray(); var dictionaryString = Encoding.ASCII.GetString(originalBytes); // split on tabs: var entries = dictionaryString.Split('\t'); foreach (var entry in entries) { var values = entry.Split('='); this.LongNameDictionary.Add(values[0], values[1]); } }
internal MachineIntegerInfoRecord(InfoRecord record) { if (record.SubType != 3 || record.ItemSize != 4 || record.ItemCount != 8) throw new UnexpectedFileFormatException(); this.record = record; }
internal VariableDisplayParameterRecord(InfoRecord record, int variableCount) { if (record.SubType != 11 || record.ItemSize != 4) { throw new UnexpectedFileFormatException(); } this.record = record; var infoList = new List <VariableDisplayInfo>(); // Record can either have 2 or 3 fields per variable: int fieldCount = this.record.ItemCount / variableCount; int currentItemIndex = 0; for (int variableIndex = 0; variableIndex < variableCount; variableIndex++) { var info = new VariableDisplayInfo(); for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) { var value = BitConverter.ToInt32(this.record.Items[currentItemIndex++], 0); // Measurement type: if (fieldIndex == 0) { if (value == 1) { info.MeasurementType = MeasurementType.Nominal; } else if (value == 2) { info.MeasurementType = MeasurementType.Ordinal; } else if (value == 3) { info.MeasurementType = MeasurementType.Scale; } else { // Default option: info.MeasurementType = MeasurementType.Nominal; } } // Width: if (fieldIndex == 1) { info.Width = value; } // Alignment: if (fieldIndex == 2) { info.Alignment = (Alignment)value; } } infoList.Add(info); } this.VariableDisplayEntries = new VariableDisplayInfoCollection(infoList); }
internal MachineFloatingPointInfoRecord(InfoRecord record) { if (record.SubType != 4 || record.ItemSize != 8 || record.ItemCount != 3) throw new UnexpectedFileFormatException(); this.record = record; }