Exemple #1
0
        public void CommandTest()
        {
            StringBuilderLogger logger;

            Logger.LogProvider = logger = new StringBuilderLogger();

            using (var module = new CommandModule()) {
                var context = new TaskContext()
                {
                    EnvironmentVariables = new Dictionary <string, string>(),
                    SkippedSteps         = new HashSet <int>(),
                    WorkingDirectory     = "../../../"
                };

                var definition = new CommandModuleDefinition()
                {
                    FilePath  = "dotnet",
                    Arguments = "list reference"
                };

                module.Execute(context, definition);

                Assert.AreEqual("Executing dotnet list reference", logger.Out.ToString(0, 31));

                Logger.ResetProvider();
            }
        }
Exemple #2
0
        public void EmptyCommandDoesnotMoveRover()
        {
            var rover = new Rover();
            var world = new BoundedWorld(5, 5);

            var commandModule = new CommandModule(rover, world.IsWithinBoundary);

            commandModule.Execute("", IgnoreErrors);

            Assert.Equal(0, rover.Location.X);
            Assert.Equal(0, rover.Location.Y);
        }
Exemple #3
0
        public void RoverFollowsCompleteCommandsToExpectedCoordinate(string command, int expectedX, int expectedY, Direction expectedDirection)
        {
            var rover = new Rover();
            var world = new BoundedWorld(5, 5);

            var commandModule = new CommandModule(rover, world.IsWithinBoundary);

            commandModule.Execute(command, IgnoreErrors);

            Assert.Equal(expectedX, rover.Location.X);
            Assert.Equal(expectedY, rover.Location.Y);
            Assert.Equal(expectedDirection, rover.Direction);
        }
        public void Execute(LauncherCommandInfo CommandInfo)
        {
            string[] Commands     = ParseCommandList(CommandInfo);
            int      CommnadCount = Commands.Count();

            foreach (var Command in Commands.Select((command, index) => new { command, index }))
            {
                bool IsImmediately = Command.index != CommnadCount - 1 || (App.AppConfig.IsImmediately && CommandInfo.IsImmediately);
                try
                {
                    if (App.AppConfig.IsCopyToClipboard || !IsImmediately)
                    {
                        System.Windows.Forms.Clipboard.Clear();
                        System.Threading.Thread.Sleep(100);
                        System.Windows.Forms.Clipboard.SetText(Command.command);
                    }
                }
                catch (Exception ex)
                {
                    LogStatics.Debug(ex.ToString());
                }
                switch (CommandInfo.Type)
                {
                case CommandExecuteType.None:
                    break;

                case CommandExecuteType.Command:
                    foreach (var CommandModule in App.PluginManagerInstance.CommandExecuteModules)
                    {
                        if (CommandModule.CanExecute(Command.command, IsImmediately))
                        {
                            CommandModule.Execute(Command.command, IsImmediately);
                        }
                    }
                    break;

                case CommandExecuteType.FileOpen:
                    ExecuteFileOpen(Command.command);
                    break;
                }
            }
        }
Exemple #5
0
        public void RoverFollowsCompleteCommandsToExpectedCoordinateWithFailReportingPolicy(string command, int expectedX, int expectedY, Direction expectedDirection, bool errorsOccured)
        {
            var rover  = new Rover();
            var world  = new BoundedWorld(5, 5);
            var policy = new StopOnErrorPolicy();

            var commandModule = new CommandModule(rover, world.IsWithinBoundary);

            var errorHappened = false;

            commandModule.Execute(command, () => { errorHappened = true; return(false); });

            Assert.Equal(errorsOccured, errorHappened);
            Assert.Equal(expectedX, rover.Location.X);
            Assert.Equal(expectedY, rover.Location.Y);
            Assert.Equal(expectedDirection, rover.Direction);

            //commandModule.Execute(command, policy.StopOnError);
            //Assert.Equal(errorsOccured, policy.ErrorHappened);
        }
Exemple #6
0
        protected override async Task ExecuteAsync(CancellationToken workerStoppingToken)
        {
            using (cancellationToken = new CancellationTokenSource())
                using (var stoppingToken = CancellationTokenSource.CreateLinkedTokenSource(workerStoppingToken, cancellationToken.Token))
                    using (discord = new DiscordSocketClient(new DiscordSocketConfig
                    {
                        /**
                         * Increases memory usage, but needed for the !purgeall command,
                         * and to get embeds that are parsed asynchonously and sent via MESSAGE_UPDATE event
                         */
                        MessageCacheSize = 128,
                    }))
                    {
                        discord.Log   += Discord_Log;
                        discord.Ready += Discord_Ready;

                        command = new CommandService(new CommandServiceConfig()
                        {
                        });

                        using (services = ConfigureServices(discord, command))
                        {
                            var randomImage = services.GetService <RandomImageService>();
                            var randomize   = services.GetService <RandomizeState>();
                            var config      = services.GetService <ConfigService>();

                            await command.AddModulesAsync(Assembly.GetEntryAssembly(), services);

                            foreach (var cmd in config.Command)
                            {
                                await command.CreateModuleAsync(cmd, builder =>
                                {
                                    builder.AddCommand("", (context, param, service, command) =>
                                    {
                                        return(CommandModule.Execute(context, param, service, command));
                                    }, builder =>
                                    {
                                    });

                                    builder.AddCommand("", (context, param, service, command) =>
                                    {
                                        return(CommandModule.Execute(context, param, service, command));
                                    }, builder =>
                                    {
                                        builder.AddParameter <string>("message", param =>
                                        {
                                            param.IsRemainder = true;
                                        });
                                    });
                                });
                            }

                            discord.MessageReceived += Discord_MessageReceived;
                            discord.MessageUpdated  += Discord_MessageUpdated;
                            discord.Disconnected    += Discord_Disconnected;

                            await discord.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("Token"));

                            await discord.StartAsync();

                            while (!stoppingToken.Token.WaitHandle.WaitOne(5000))
                            {
                                foreach (var(channel, state) in randomize.Where(pair => pair.Value != RandomStatus.Off))
                                {
                                    await randomImage.RandomImage(channel, state);
                                }
                            }

                            discord.MessageReceived -= Discord_MessageReceived;
                            discord.MessageUpdated  -= Discord_MessageUpdated;
                            discord.Disconnected    -= Discord_Disconnected;
                        }

                        await discord.StopAsync();

                        await discord.LogoutAsync();
                    }

            cancellationToken = null;
            lifetime.StopApplication();
        }