private async void OnMessage(object sender, MessageEventArgs arguments) { var message = arguments.Message; if (message.Text != null) { try { string command = ExtractCommand(message.Text); IBotCommand handler = CommandSelector.MapCommandToHandler(command); await handler.Handle(message, this._botClient, this._pokeApiClient); } catch (Exception exception) { // Workaround since C# does not support multi catch as in Java if (exception is UnknownCommandException || exception is NoCommandHandlerException) { await this._botClient.SendTextMessageAsync( chatId : message.Chat, text : "Unfortunately the bot does not support this command. Enter /help or /start for more options." ); } else { Console.WriteLine(exception.Message); Console.WriteLine(exception.StackTrace); await this._botClient.SendTextMessageAsync( chatId : message.Chat, text : "500 - Internal Server Error" ); } } } }
public async Task RunAsync(string[] args) { Logger.LogInformation("ABP CLI (https://abp.io)"); await CheckCliVersionAsync(); var commandLineArgs = CommandLineArgumentParser.Parse(args); var commandType = CommandSelector.Select(commandLineArgs); using (var scope = ServiceScopeFactory.CreateScope()) { var command = (IConsoleCommand)scope.ServiceProvider.GetRequiredService(commandType); try { await command.ExecuteAsync(commandLineArgs); } catch (CliUsageException usageException) { Logger.LogWarning(usageException.Message); } catch (Exception ex) { Logger.LogException(ex); } } }
public void InitializeTargetSelectionSingle(List <FightingEntity> possibleTargets, int initialChoice, CommandSelector selector) { this.CommonInitialization(possibleTargets); this._commandSelector = selector; this._commandSelector.Initialize(0, possibleTargets.Count - 1, this.UpdateTargetSelectionUI, true); this.UpdateTargetSelectionUI(); }
public MoveSelectionPhase(BattleUI ui, BattleField field, CommandSelector selector, string callback) : base(TurnPhase.MOVE_SELECTION, callback) { this._ui = ui; this._field = field; this._playerActionCounter = 0; this._heroMenuActions = new Stack <HeroMenuAction>(); this._commandSelector = selector; }
public AdministrationConnection(ushort id, ServerConnection connection, IClientInfo clientInfo) { _commandSelector = new CommandSelector(); _connectionInfo = new ConnectionInfo(connection, id, clientInfo, (IConnectionInitializer)_commandSelector.CommandDictionary[32]); _connectionInfo.Failed += ConnectionInfoOnFailed; Id = id; }
public MicrolexDisplayer(List<ICommand> _program, ICommandContext env) : this() { program = _program; this.env = env; selector = new CommandSelector(); //env.InstructionPointerChanged += new EventHandler(env_InstructionPointerChanged); Initialize(); }
private async Task RunInternalAsync(CommandLineArgs commandLineArgs) { var commandType = CommandSelector.Select(commandLineArgs); using (var scope = ServiceScopeFactory.CreateScope()) { var command = (IConsoleCommand)scope.ServiceProvider.GetRequiredService(commandType); await command.ExecuteAsync(commandLineArgs); } }
public OptionObject2015 RunScript(OptionObject2015 optionObject2015, string parameter) { IRunScriptCommand command = CommandSelector.GetCommand(optionObject2015, parameter); if (command == null) { logger.Error("A valid RunScript command was not retrieved."); return(optionObject2015); } return(command.Execute()); }
private ImageCommand GetImageCommand( ) { Console.WriteLine("Enter Save Location, Enter nothing to use dafult location:"); foreach (var command in CommandTable.Keys) { if (command.Length > 0) { Console.WriteLine(command); } } return(CommandSelector.SelectCommand(Console.ReadLine(), CommandTable)); }
private static async Task <CommandResult> RunCommandPipelineAsync(ReadOnlyCollection <string> commandLineArguments, Assembly commandAssembly, IServiceProvider provider, CancellationToken stoppingToken) { CommandLineArguments args = CommandLineArgumentsParser.Parse(commandLineArguments); Type type = CommandSelector.SelectCommand(commandAssembly, args); using CommandBase instance = CommandActivator.ConstructCommand(provider, type); CommandArgumentsBinder.BindArguments(instance, args); CommandOptionsBinder.BindOptions(instance, args); CommandResult result = await CommandExecutor.InvokeAsync(instance, stoppingToken); return(result); }
public void GetCommand_SetFieldValue_ReturnsSetFieldValueCommand() { // Arrange OptionObject2015 optionObject2015 = new OptionObject2015(); IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject2015); IParameter parameter = new Parameter("SetFieldValue"); SetFieldValueCommand expected = new SetFieldValueCommand(optionObjectDecorator, parameter); // Act IRunScriptCommand actual = CommandSelector.GetCommand(optionObject2015, parameter); // Assert Assert.AreEqual(expected.GetType(), actual.GetType()); }
public async Task RunAsync(string[] args) { Logger.LogInformation("ABP CLI (abp.io)"); Logger.LogInformation("Version: " + Version); var commandLineArgs = CommandLineArgumentParser.Parse(args); var commandType = CommandSelector.Select(commandLineArgs); using (var scope = ServiceScopeFactory.CreateScope()) { var command = (IConsoleCommand)scope.ServiceProvider.GetRequiredService(commandType); await command.ExecuteAsync(commandLineArgs); } }
public void ClearSelection() { if (potentialTargets != null) { for (int i = 0; i < potentialTargets.Count; i++) { this.SetMaterialOutline(i, false); } potentialTargets.Clear(); } _commandSelector = null; }
public void GetCommand_EmptyParameter_ReturnsDefaultCommand() { // Arrange OptionObject2015 optionObject2015 = new OptionObject2015(); IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject2015); IParameter parameter = new Parameter(""); DefaultCommand expected = new DefaultCommand(optionObjectDecorator, parameter); // Act IRunScriptCommand actual = CommandSelector.GetCommand(optionObject2015, parameter); // Assert Assert.AreEqual(expected.GetType(), actual.GetType()); }
public void GetCommand_HelloWorld_ReturnsHelloWorldCommand() { // Arrange OptionObject2015 optionObject2015 = new OptionObject2015(); IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject2015); IParameter parameter = new Parameter("HelloWorld"); HelloWorldCommand expected = new HelloWorldCommand(optionObjectDecorator); // Act IRunScriptCommand actual = CommandSelector.GetCommand(optionObject2015, parameter); // Assert Assert.AreEqual(expected.GetType(), actual.GetType()); }
public void Initialize(BattleField field, BattleUI ui, CommandSelector commandSelector, StageController stageController) { // Initialize Stages phases = new List <Phase>(); _curPhase = 0; // Add the Phases in Order phases.Add(new TurnStartPhase(field, ui, callback)); phases.Add(new PartySetupPhase(ui, field, callback)); phases.Add(new MoveSelectionPhase(ui, field, commandSelector, callback)); phases.Add(new BattlePhase(ui, field, callback)); phases.Add(new TurnEndPhase(field, callback)); GameManager.Instance.time.GetController().StartCoroutine(phases[_curPhase].RunPhase()); }
public void GetCommand_SendEmail_ReturnsSendEmailCommand() { // Arrange OptionObject2015 optionObject2015 = new OptionObject2015(); IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject2015); IParameter parameter = new Parameter("SendEmail"); var smtpService = new SmtpService(); SendEmailCommand expected = new SendEmailCommand(optionObjectDecorator, smtpService); // Act IRunScriptCommand actual = CommandSelector.GetCommand(optionObject2015, parameter); // Assert Assert.AreEqual(expected.GetType(), actual.GetType()); }
public void UniqueCommandIdsTest() { using (var commandSelector = new CommandSelector()) { var commandTokens = new List <uint>(); foreach (var command in commandSelector.CommandCollection) { if (commandTokens.Any(x => x == command.Identifier)) { Assert.Fail($"Command tokens are doubled. Command: {command}"); } commandTokens.Add(command.Identifier); } } }
public void GetCommand_GetOdbcData_ReturnsGetOdbcDataCommand() { // Arrange OptionObject2015 optionObject2015 = new OptionObject2015(); IOptionObjectDecorator optionObjectDecorator = new OptionObjectDecorator(optionObject2015); IParameter parameter = new Parameter("GetOdbcData"); ConnectionStringCollection connectionStringCollection = new ConnectionStringCollection("", "", ""); var repository = new GetOdbcDataRepository(connectionStringCollection); GetOdbcDataCommand expected = new GetOdbcDataCommand(optionObjectDecorator, repository); // Act IRunScriptCommand actual = CommandSelector.GetCommand(optionObject2015, parameter); // Assert Assert.AreEqual(expected.GetType(), actual.GetType()); }
public void InitializeCommandSelection(List <string> options, int startChoice, CommandSelector selector) { this.options = options; this.clearExistingCommands(); foreach (var option in options) { CommandOptionText commandText = Instantiate(_commandTextPrefab) as CommandOptionText; commandText.text.text = option; commandText.transform.SetParent(_actionMenuTextParent.transform); _battleOptionsUI.Add(commandText); } _commandSelector = selector; _commandSelector.Initialize(0, options.Count - 1, this.SetSelectionFromCommandSelector, true); this.curIndex = startChoice; this.SetSelection(startChoice); this.SetCommandCardUI(CommandCardUIMode.SELECT_COMMAND); }
public void CannotMatchAmbiguousCommand() { Assert.Throws <AmbiguousCommandException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("ambiguous"))); Assert.Throws <AmbiguousCommandException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("command"))); }
public void MatchesOnlyCommands() { Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs(nameof(CommandSelectorTests).ToLowerInvariant()))); }
public void MatchesOnlyConcreteTypes() { Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("abstract"))); }
public void NullCheck() { Assert.Throws <ArgumentNullException>("assembly", () => CommandSelector.SelectCommand(null, CreateArgs(""))); Assert.Throws <ArgumentNullException>("args", () => CommandSelector.SelectCommand(GetType().Assembly, null)); }
public void AssemblyWithoutAnyCommand() { Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetCallingAssembly(), CreateArgs("null"))); }
public void MatchesOnlyPublicTypes() { Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("internal"))); }
public void RequiresCommandToBeProvided() { Assert.Throws <CommandNotProvidedException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs(""))); }
public void InitializeTargetSelectionAll(List <FightingEntity> possibleTargets) { this.CommonInitialization(possibleTargets); this._commandSelector = null; this.UpdateTargetSelectionUI(); }
public void MatchesOnlyLowercase() { Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("Null"))); Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("delegatE"))); }
public void MatcherRemovesConventionalSuffix() { Type command = CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("delegate")); Assert.Equal(typeof(DelegateCommand), command); }
public void AssemblyWithCommands() { Type command = CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("null")); Assert.Equal(typeof(NullCommand), command); }