public Cortege<BindContoller<StringId>, LogHistory> GetBindContollerAndLogHistory(List<string> lines) { Contract.Requires(lines != null); Contract.Requires(lines.Any()); var allBlocks = GetAllBlocks(lines); if (allBlocks.Count < 3) { throw new FileLoadException("Count of blocks is less then 3"); } var allBlocksForMultiTree = allBlocks.Take(allBlocks.Count - 2).ToList(); var linesForSingleTree = allBlocks[allBlocks.Count - 2]; var commandLines = allBlocks.Last(); var multiTreeAndLogHistory = GetMultiTree(allBlocksForMultiTree); var singleTree = _singleTreeParser.GetSingleTree(linesForSingleTree); var multiTree = multiTreeAndLogHistory.First; var logHistory = multiTreeAndLogHistory.Second; logHistory.Add(new SingleTreeResult(singleTree)); logHistory.Add(new CommandsResult(commandLines)); var bindController = new BindContoller<StringId>(multiTree, singleTree); AddConnections(bindController, commandLines); return new Cortege<BindContoller<StringId>, LogHistory>(bindController, logHistory); }
public void Start(BindContoller<StringId> bindContoller) { Contract.Requires(bindContoller != null); _bindController = bindContoller; while (true) { DisplayTree(); Console.WriteLine("Type 'a' to add, 'r' to remove, 'ra' to remove all connection, 'e' to exit"); var action = Console.ReadLine(); _commandMediator.ProcessCommand(action); if (action == CommandMediator.ExitLongName || action == CommandMediator.ExitShortName) break; } }
private void AddConnections(BindContoller<StringId> bindContoller, List<string> commands) { Contract.Requires(bindContoller != null); Contract.Requires(commands != null); foreach (var command in commands) { var partsOfCommand = command.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (partsOfCommand[0] == AddLongName) { bindContoller.Bind(new StringId(partsOfCommand[1]), new StringId(partsOfCommand[2])); } if (partsOfCommand[0] == RemoveAllLongName) { bindContoller.RemoveAllConnections(); } if (partsOfCommand[0] == RemoveLongName) { bindContoller.RemoveConnection(new StringId(partsOfCommand[1])); } } }
private void ProcessBuildingTreeFromConsole(BindContoller<StringId> bindController = null) { BindContoller<StringId> newBindController = bindController; do { if (newBindController == null) { ProcessBuildingMinorTree(); _consoleConnectionController.Start(new BindContoller<StringId>(_mainMultiTree, _minorSingleTree)); } else { _consoleConnectionController.Start(newBindController); } _mainMultiTree = _consoleConnectionController.GetConnectedMultiTree(); Console.Clear(); Console.WriteLine("Do you want to type another tree?"); Console.WriteLine("type 'yes' to add tree or something else to finish with building trees"); if (Console.ReadLine() != "yes") { break; } newBindController = null; } while (true); _treeLogger.AddMultiTreeInFile(_mainMultiTree); }
private Cortege<MultiTree<StringId>, LogHistory> GetMultiTree(List<List<string>> blocks) { Contract.Requires(blocks != null); Contract.Requires(blocks.Any()); Contract.Requires(blocks.Count % 2 == 1); var logHistory = new LogHistory(); var singleTree = _singleTreeParser.GetSingleTree(blocks[0]); logHistory.Add(new SingleTreeResult(singleTree)); var mainTree = new MultiTree<StringId>(singleTree); for (int i = 1; i < blocks.Count; i += 2) { var minorTree = _singleTreeParser.GetSingleTree(blocks[i]); var connectionBlock = blocks[i + 1]; logHistory.Add(new SingleTreeResult(minorTree)); logHistory.Add(new CommandsResult(connectionBlock)); var bindController = new BindContoller<StringId>(mainTree, minorTree); AddConnections(bindController, connectionBlock); var idGenerator = new IdGenerator(mainTree.ToList()); var multiNode = _treeConstructor.GetFilledTree(bindController, idGenerator).ToMultiNode(); mainTree = new MultiTree<StringId>(multiNode); } return new Cortege<MultiTree<StringId>, LogHistory>(mainTree, logHistory); }