public void LoadSession(TextReader reader) { var commandLines = new List <string>(); var line = reader.ReadLine(); if (line != _fileHeader) { commandLines.Add(reader.ReadToEnd()); } else { line = reader.ReadLine(); if (line != "") { throw new ApplicationException("Invalid file format"); } line = reader.ReadLine(); if (line != _commandLineHeader) { throw new ApplicationException("Invalid file format"); } var builder = new StringBuilder(); while (true) { line = reader.ReadLine(); if (line == null) { break; } if (line == _commandLineHeader) { // Remove newline at end of code. if (builder.Length >= 2) { builder.Remove(builder.Length - 2, 2); } commandLines.Add(builder.ToString()); builder.Clear(); } else { builder.AppendLine(line); } } if (builder.Length >= 2) { builder.Remove(builder.Length - 2, 2); } commandLines.Add(builder.ToString()); } _sessionViewModel.Clear(false); foreach (var c in commandLines) { var r = CreateNewRoundtrip(true); r.ViewModel.WriteCommandLine(c); } _sessionViewModel.IsTextChanged = false; }