static void CreateManager() { _firstCommand = new Command("hallo"); _firstOption = new Option {HaveParameters = false, Identifier = "f", Parameters = null}; _parameterOption = new Option {HaveParameters = true,Identifier = "p"}; _secondCommand = new Command("copy",new[]{_firstOption},false); _parameterCommand = new Command("pm",new []{_parameterOption},true); _consoleManager = _consoleBuilder.Build(new[] { _firstCommand,_secondCommand ,_parameterCommand}); }
public bool RegisterCommandEvent(Command command,EventHandler commandTask) { if (_eventList.ContainsKey(command)) { return false; } _eventList.Add(command,commandTask); return true; }
public Command CreateCleanCommandClone(Command command) { var clone = new Command(); clone = Mapper.Map(command, clone); return clone; }
public IList<Option> GetOptions(CommandName name, Command command) { if (!name.CleanInput.Contains('-')) { return null; } var rawOptions = name.CleanInput.Split('-'); if (!rawOptions.Any()) { return null; } var options = new List<Option>(); foreach (var rawOption in rawOptions) { if (string.IsNullOrWhiteSpace(rawOption)) { continue; } string optionName = String.Empty; try { int firstWhitespace = rawOption.IndexOf(' '); if (firstWhitespace == -1) { optionName = rawOption; } else { optionName = rawOption.Substring(0, firstWhitespace); } } catch { continue; } var cOption = command.Options.FirstOrDefault(c => c.Identifier.ToLower().Equals(optionName.ToLower())); if (cOption == null) { continue; } var clone = new Option(); clone = Mapper.Map(cOption, clone); if (!cOption.HaveParameters) { options.Add(clone); continue; } var parameters = GetParameters(rawOption.Replace(optionName + " ", "")); if (parameters == null) { options.Add(clone); continue; } clone.Parameters = parameters; options.Add(clone); } return options; }
public bool UnRegisterCommandEvent(Command command) { throw new NotImplementedException(); }
EventHandler getEventHandlerFromCommand(Command command) { var keys = _eventList.Keys; var key = keys.FirstOrDefault(d => d.Name.Equals(command.Name)); if (key == null || !_eventList.ContainsKey(key)) { return null; } return _eventList[key]; }