private void ProcessVariables(IDictionary <string, string> variableLongNames, IDictionary <string, int> veryLongStrings, List <VariableRecord> variableRecords, List <ValueLabel> valueLabels) { var namesList = new SortedSet <byte[]>(new ByteArrayComparer()); foreach (var variable in _variables) { int dictionaryIndex = variableRecords.Count + 1; var records = VariableRecord.GetNeededVaraibles(variable, _options.HeaderEncoding, namesList, ref _longNameCounter, veryLongStrings); variableRecords.AddRange(records); // Check if a longNameVariableRecord is needed if (records[0].Name != variable.Name) { variableLongNames.Add(records[0].Name, variable.Name); } // TODO Avoid repeating the same valueLabels on the file // Add ValueLabels if necesary if (variable.ValueLabels != null && variable.ValueLabels.Any()) { var valueLabel = new ValueLabel(variable.ValueLabels.ToDictionary(p => BitConverter.GetBytes(p.Key), p => p.Value)); valueLabel.VariableIndex.Add(dictionaryIndex); valueLabels.Add(valueLabel); } } }
private void ProcessVariables(IDictionary <string, string> variableLongNames, IDictionary <string, int> veryLongStrings, List <VariableRecord> variableRecords, List <ValueLabel> valueLabels) { int longNameCounter = 0; var namesList = new SortedSet <byte[]>(new ByteArrayComparer()); var segmentsNamesList = new SortedList <byte[], int>(new ByteArrayComparer()); foreach (var variable in _variables) { int dictionaryIndex = variableRecords.Count + 1; var records = VariableRecord.GetNeededVariables(variable, _options.HeaderEncoding, namesList, ref longNameCounter, veryLongStrings, segmentsNamesList); variableRecords.AddRange(records); // Even if the variable name is the same, it still needs a long record indicator otherwise SPSS doesn't know how to handle it. variableLongNames.Add(records[0].Name, variable.Name); // TODO Avoid repeating the same valueLabels on the file // Add ValueLabels if necesary if (variable.ValueLabels != null && variable.ValueLabels.Any()) { var valueLabel = new ValueLabel(variable.ValueLabels.ToDictionary(p => BitConverter.GetBytes(p.Key), p => p.Value)); valueLabel.VariableIndex.Add(dictionaryIndex); valueLabels.Add(valueLabel); } } }