Пример #1
0
        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"
                            );
                    }
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
    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();
    }
Пример #4
0
 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;
 }
Пример #5
0
        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;
        }
Пример #6
0
 public MicrolexDisplayer(List<ICommand> _program, ICommandContext env)
     : this()
 {
     program = _program;
     this.env = env;
     selector = new CommandSelector();
     //env.InstructionPointerChanged += new EventHandler(env_InstructionPointerChanged);
     Initialize();
 }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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());
        }
Пример #9
0
 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());
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
    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());
        }
Пример #16
0
    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());
        }
Пример #18
0
        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());
        }
Пример #20
0
    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);
    }
Пример #21
0
 public void CannotMatchAmbiguousCommand()
 {
     Assert.Throws <AmbiguousCommandException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("ambiguous")));
     Assert.Throws <AmbiguousCommandException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("command")));
 }
Пример #22
0
 public void MatchesOnlyCommands()
 {
     Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs(nameof(CommandSelectorTests).ToLowerInvariant())));
 }
Пример #23
0
 public void MatchesOnlyConcreteTypes()
 {
     Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("abstract")));
 }
Пример #24
0
 public void NullCheck()
 {
     Assert.Throws <ArgumentNullException>("assembly", () => CommandSelector.SelectCommand(null, CreateArgs("")));
     Assert.Throws <ArgumentNullException>("args", () => CommandSelector.SelectCommand(GetType().Assembly, null));
 }
Пример #25
0
 public void AssemblyWithoutAnyCommand()
 {
     Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetCallingAssembly(), CreateArgs("null")));
 }
Пример #26
0
 public void MatchesOnlyPublicTypes()
 {
     Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("internal")));
 }
Пример #27
0
 public void RequiresCommandToBeProvided()
 {
     Assert.Throws <CommandNotProvidedException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("")));
 }
Пример #28
0
 public void InitializeTargetSelectionAll(List <FightingEntity> possibleTargets)
 {
     this.CommonInitialization(possibleTargets);
     this._commandSelector = null;
     this.UpdateTargetSelectionUI();
 }
Пример #29
0
 public void MatchesOnlyLowercase()
 {
     Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("Null")));
     Assert.Throws <CommandNotFoundException>(() => CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("delegatE")));
 }
Пример #30
0
        public void MatcherRemovesConventionalSuffix()
        {
            Type command = CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("delegate"));

            Assert.Equal(typeof(DelegateCommand), command);
        }
Пример #31
0
        public void AssemblyWithCommands()
        {
            Type command = CommandSelector.SelectCommand(Assembly.GetExecutingAssembly(), CreateArgs("null"));

            Assert.Equal(typeof(NullCommand), command);
        }