Ejemplo n.º 1
0
 public CommandRunner(ServiceManager svc, ExtensionClientManager extmgr)
 {
     _svc    = svc;
     _extmgr = extmgr;
     Add(ExecCommand.Get());
     Add(RestartCommand.Get());
 }
Ejemplo n.º 2
0
 private void RaiseCanExecuteChangedEvents()
 {
     PauseCommand.RaiseCanExecuteChanged();
     RestartCommand.RaiseCanExecuteChanged();
     AbortCommand.RaiseCanExecuteChanged();
     StopSaveCommand.RaiseCanExecuteChanged();
 }
Ejemplo n.º 3
0
        public async Task RestartContainer()
        {
            // Arrange
            const string ModuleName = "boo";
            var          module     = new Mock <IRuntimeModule>();

            module.SetupGet(m => m.Name).Returns(ModuleName);

            var containerOperations = new Mock <IContainerOperations>();

            containerOperations
            .Setup(co => co.RestartContainerAsync(ModuleName, It.IsAny <ContainerRestartParameters>(), CancellationToken.None))
            .Returns(Task.CompletedTask);

            var dockerClient = new Mock <IDockerClient>();

            dockerClient.SetupGet(c => c.Containers).Returns(containerOperations.Object);

            // Act
            var command = new RestartCommand(dockerClient.Object, module.Object);
            await command.ExecuteAsync(CancellationToken.None);

            // Assert
            containerOperations.VerifyAll();
            dockerClient.VerifyAll();
        }
        public IExecutable ManageCommand(string inputArgs)
        {
            IExecutable command = null;

            string commandType = inputArgs;

            switch (commandType)
            {
                case "top":
                    command = new StatusCommand(this.Engine);
                    break;
                case "restart":
                    command = new RestartCommand(this.Engine);
                    break;
                case "turn":
                    command = new TurnCommand(this.Engine);
                    break;
                case "exit":
                    command = new EndCommand(this.Engine);
                    break;
                default:
                    this.Engine.Writer.WriteLine("\nError! Invalid command\n");
                    break;
            }

            return command;
        }
Ejemplo n.º 5
0
        private static void OnFileChanged(Object source, FileSystemEventArgs e)
        {
            //采用临时禁用法解决触发两次事件的问题,只适合解决监控单个文件的处理
            if (source != null)
            {
                var watcher = source as FileSystemWatcher;
                watcher.EnableRaisingEvents = false;

                Thread th = new Thread(new ThreadStart(
                                           delegate()
                {
                    Thread.Sleep(1000);
                    watcher.EnableRaisingEvents = true;
                }
                                           ));
                th.Start();
                IsRestart = true;
            }
            LogerHelper.WriteOperateLog(string.Format("修改类型:{0},配置文件{0}被修改", e.ChangeType, e.FullPath));
            LogerHelper.WriteOperateLog("是否重启服务:" + IsRestart);
            if (IsRestart)
            {
                //重启服务
                ICommand command = new RestartCommand();
                command.DealCommand();
                IsRestart = false;
            }
        }
Ejemplo n.º 6
0
        public void WrongRunCommandTypesCases()
        {
            _mock.Answers.Add("OK");

            _mock.Answers.Add("AT+MODE?");
            _mock.Answers.Add("");
            _mock.Answers.Add("+MODE: \"GPRS\", \"AWAIT\"");
            _mock.Answers.Add("OK");

            _mock.Answers.Add("");
            _mock.Answers.Add("OK");

            List <BaseATCommand> zList       = new List <BaseATCommand>();
            AppModeCommand       zAppCommand = new AppModeCommand();

            zList.Add(zAppCommand);
            RestartCommand zRestartCommand = new RestartCommand();

            zList.Add(zRestartCommand);

            Dictionary <BaseATCommand, bool> zResult;
            string zErrorMessage = "";

            zResult = base.RunCommands(zList, CommandType.ctRead, out zErrorMessage);
            Assert.Equal(2, zResult.Count);
            Assert.Equal("", zErrorMessage);
            Assert.True(zResult[zAppCommand]);
            Assert.False(zResult[zRestartCommand]);
        }
        private void Restart()
        {
            var cmd = new RestartCommand();

            try
            {
                _logger.Log(cmd.Name);
                _logger.Log("Команда <" + cmd.Name + "> поставлена в очередь");
                _commandSenderHost.Sender.SendCommandAsync(
                    _targerAddressHost.TargetAddress
                    , cmd
                    , TimeSpan.FromSeconds(1), 1
                    , (exception, bytes) => _userInterfaceRoot.Notifier.Notify(() =>
                {
                    try
                    {
                        if (exception != null)
                        {
                            throw new Exception("Ошибка при передаче данных: " + exception.Message, exception);
                        }
                        _logger.Log("Команда <" + cmd.Name + "> была отправлена");
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(ex.Message);
                    }
                }));
            }
            catch (Exception ex)
            {
                _logger.Log("Не удалось поставить команду <" + cmd.Name + "> в очередь: " + ex.Message);
            }
        }
Ejemplo n.º 8
0
 private void UpdateCommands()
 {
     PlayCommand.OnCanExecuteChanged();
     PauseCommand.OnCanExecuteChanged();
     StopCommand.OnCanExecuteChanged();
     RestartCommand.OnCanExecuteChanged();
     CaptureImageCommand.OnCanExecuteChanged();
 }
Ejemplo n.º 9
0
 public MainViewModel()
 {
     //InstantiateConwayCells(137, 67);
     InstantiateConwayCells(30, 30);
     AddNeighboursOfConwayCellsAsync();
     PopulateCommand = new(DoPopulation);
     RestartCommand  = new(RestartGame);
 }
Ejemplo n.º 10
0
 private static void HandleRestart(RestartCommand concrete)
 {
     using (var process = Process.Start("shutdown", $"/r /t {concrete.Delay.Value?.TotalSeconds ?? 60}"))
     {
         process.StartInfo.CreateNoWindow  = true;
         process.StartInfo.UseShellExecute = true;
         process.StartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
     }
 }
Ejemplo n.º 11
0
 void AdjustCanExecutes()
 {
     RestartCommand.RaiseCanExecuteChanged();
     RunToBacktrackCommand.RaiseCanExecuteChanged();
     RunToSuccessCommand.RaiseCanExecuteChanged();
     StepIntoCommand.RaiseCanExecuteChanged();
     StepOverCommand.RaiseCanExecuteChanged();
     ReturnToCallerCommand.RaiseCanExecuteChanged();
 }
        public void CheckIfRestartCommandConstructorWorksProperly()
        {
            IMatrixField           field      = FieldFactory.Instance.GetField(5);
            IScoreboard            scoreboard = new ScoreboardProxy();
            IRandomNumberGenerator random     = new RandomNumberGenerator();
            IGameEngine            gameEngine = new GameFifteenEngine(field, scoreboard, random);

            RestartCommand restartCommand = new RestartCommand(gameEngine);

            Assert.IsInstanceOfType(restartCommand, typeof(Command));
        }
Ejemplo n.º 13
0
        public void RequiresServiceOption()
        {
            var command = new RestartCommand();

            var options = command.Options.OfType <ServiceOption>();

            var option = Assert.Single(options);

            Assert.NotNull(option);
            Assert.True(option !.IsRequired);
        }
Ejemplo n.º 14
0
        public void Execute(RestartCommand message)
        {
            _logger.Info("Restart requested.");

            _eventAggregator.PublishEvent(new ApplicationShutdownRequested(true));

            if (_runtimeInfo.IsWindowsService)
            {
                _serviceProvider.Restart(ServiceProvider.NZBDRONE_SERVICE_NAME);
            }
        }
Ejemplo n.º 15
0
        public void QueueRestart_Execute_ReturnsNotFoundMessage()
        {
            var command = new RestartCommand(_console, LoggerMock.GetLogger <RestartCommand>().Object, _projectService.Object, _jobDefinitionService.Object, _jobQueueService.Object)
            {
                Project = "Project 1",
                Number  = "2"
            };

            var resultMessage = command.Execute();

            Assert.Equal("Failed to restart queue 2. Make sure the project name and queue number are correct.", resultMessage);
        }
Ejemplo n.º 16
0
        public void QueueRestart_Execute_ReturnsSuccessMessage()
        {
            var command = new RestartCommand(_console, LoggerMock.GetLogger <RestartCommand>().Object, _projectService.Object, _jobDefinitionService.Object, _jobQueueService.Object)
            {
                Project = "Project 1",
                Number  = "1"
            };

            var resultMessage = command.Execute();

            Assert.StartsWith("Queue 1 has been restarted successfully", resultMessage);
        }
Ejemplo n.º 17
0
        public ExceptionViewModel(Exception exception, IApplicationService applicationService)
        {
            _exception          = exception;
            _applicationService = applicationService;

            OpenLogFolderCommand = ReactiveCommand.Create(Observable.Return(_applicationService.LogFolder != null))
                                   .DisposeWith(this);

            CopyCommand = ReactiveCommand.Create(Observable.Return(exception != null))
                          .DisposeWith(this);

            ContinueCommand = ReactiveCommand.Create()
                              .DisposeWith(this);

            ExitCommand = ReactiveCommand.Create()
                          .DisposeWith(this);

            RestartCommand = ReactiveCommand.Create()
                             .DisposeWith(this);

            OpenLogFolderCommand.ActivateGestures()
            .Subscribe(x => OpenLogFolder())
            .DisposeWith(this);

            CopyCommand.ActivateGestures()
            .Subscribe(x => Copy())
            .DisposeWith(this);

            ContinueCommand.ActivateGestures()
            .Subscribe(x => Continue())
            .DisposeWith(this);

            ExitCommand
            .ActivateGestures()
            .Subscribe(x => Exit())
            .DisposeWith(this);

            RestartCommand
            .ActivateGestures()
            .Subscribe(x => Restart())
            .DisposeWith(this);

            Closed.Take(1)
            .Subscribe(x =>
            {
                // Force all other potential exceptions to be realized
                // from the Finalizer thread to surface to the UI
                GC.Collect(2, GCCollectionMode.Forced);
                GC.WaitForPendingFinalizers();
            })
            .DisposeWith(this);
        }
        public void CheckIfMethodRestartExecuteReturnsProperString()
        {
            IMatrixField           field      = FieldFactory.Instance.GetField(5);
            IScoreboard            scoreboard = new ScoreboardProxy();
            IRandomNumberGenerator random     = new RandomNumberGenerator();
            IGameEngine            gameEngine = new GameFifteenEngine(field, scoreboard, random);

            RestartCommand restartCommand = new RestartCommand(gameEngine);

            string result = restartCommand.Execute();

            Assert.IsInstanceOfType(result, typeof(String));
        }
        public async void ReadCommandSettings(MqttPublisher publisher)
        {
            while (this.CommandSettingsFileLocked)
            {
                await Task.Delay(500);
            }
            this.CommandSettingsFileLocked = true;
            List <ConfiguredCommand> commands = new List <ConfiguredCommand>();

            using (var stream = new FileStream(Path.Combine(path, "configured-commands.json"), FileMode.Open))
            {
                Log.Logger.Information($"reading configured commands from: {stream.Name}");
                if (stream.Length > 0)
                {
                    commands = await JsonSerializer.DeserializeAsync <List <ConfiguredCommand> >(stream);
                }
                stream.Close();
                this.CommandSettingsFileLocked = false;
            }

            foreach (ConfiguredCommand configuredCommand in commands)
            {
                AbstractCommand command = null;
                switch (configuredCommand.Type)
                {
                case "ShutdownCommand":
                    command = new ShutdownCommand(publisher, configuredCommand.Name, configuredCommand.Id);
                    break;

                case "RestartCommand":
                    command = new RestartCommand(publisher, configuredCommand.Name, configuredCommand.Id);
                    break;

                case "LogOffCommand":
                    command = new LogOffCommand(publisher, configuredCommand.Name, configuredCommand.Id);
                    break;

                case "CustomCommand":
                    command = new CustomCommand(publisher, configuredCommand.Command, configuredCommand.Name, configuredCommand.Id);
                    break;

                default:
                    Log.Logger.Error("unsupported command type in config");
                    break;
                }
                if (command != null)
                {
                    this.ConfiguredCommands.Add(command);
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Function for creating commands
        /// </summary>
        /// <param name="command">Command name</param>
        /// <returns>New command object</returns>
        public ICommand CreateCommand(string command)
        {
            ICommand resultCommand;

            if (this.commandDictionary.ContainsKey(command))
            {
                return(this.commandDictionary[command]);
            }

            switch (command)
            {
            case "u":
                resultCommand = new MoveUp();
                break;

            case "d":
                resultCommand = new MoveDown();
                break;

            case "l":
                resultCommand = new MoveLeft();
                break;

            case "r":
                resultCommand = new MoveRight();
                break;

            case "restart":
                resultCommand = new RestartCommand();
                break;

            case "top":
                resultCommand = new ScoreCommand();
                break;

            case "exit":
                resultCommand = new ExitCommand();
                break;

            case "undo":
                resultCommand = new UndoCommand();
                break;

            default:
                throw new InvalidCommandException(GlobalErrorMessages.InvalidCommandMessage);
            }

            this.commandDictionary.Add(command, resultCommand);
            return(resultCommand);
        }
        public IVirtualMachineCommand GetCommand(VirtualMachineCommand command)
        {
            if (RestartCommand.CanExecute(command.Action))
            {
                return(new RestartCommand(VirtualMachineService, command));
            }
            else if (StartCommand.CanExecute(command.Action))
            {
                return(new StartCommand(VirtualMachineService, command));
            }
            else if (StopCommand.CanExecute(command.Action))
            {
                return(new StopCommand(VirtualMachineService, command));
            }

            return(null);
        }
Ejemplo n.º 22
0
        public static void GameEndControllers(Game1 game, KeyboardController keyboard, GamepadController gamepad)
        {
            keyboard.ClearDictionary();
            gamepad.ClearDictionary();



            ICommand resetcommand = new RestartCommand();

            keyboard.Add((int)Keys.R, resetcommand);
            gamepad.Add((int)Buttons.Back, resetcommand);
            //Add the Exit Command to the controllers
            ICommand exitcommand = new ExitCommand(game);

            keyboard.Add((int)Keys.Q, exitcommand);
            gamepad.Add((int)Buttons.Start, exitcommand);
        }
Ejemplo n.º 23
0
        public virtual ICommand CreateCommand(IGameEngine gameEngine, string commandArgs)
        {
            int    row;
            int    col;
            string commandName = commandArgs;

            if (commandArgs.Length >= 3)
            {
                bool isRowSet     = int.TryParse(commandArgs[0].ToString(), out row);
                bool isColSet     = int.TryParse(commandArgs[2].ToString(), out col);
                bool isRowInRange = row <= gameEngine.GameField.GetLength(0);
                bool isColInRange = col <= gameEngine.GameField.GetLength(1);
                if ((isRowSet && isColSet) && isRowInRange && isColInRange)
                {
                    commandName = "turn";
                }
            }

            ICommand command = null;

            string[] inputArgs = commandArgs.Split(' ');
            switch (commandName.ToLower())
            {
            case "top":
                command = new TopCommand(gameEngine);
                break;

            case "restart":
                command = new RestartCommand(gameEngine);
                break;

            case "turn":
                command = new TurnCommand(gameEngine, inputArgs);
                break;

            case "exit":
                command = new ExitCommand(gameEngine);
                break;

            default:
                break;
            }

            return(command);
        }
Ejemplo n.º 24
0
        public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnderNetCoreAndSettingsPickedFromEnvironment()
        {
            IApplicationClient applicationClient = Substitute.For <IApplicationClient>();
            var environmentSettings = new EnvironmentSettings {
                Login      = "******",
                Password   = "******",
                IsNetCore  = true,
                Maintainer = "Test",
                Uri        = "http://test.domain.com"
            };
            RestartCommand restartCommand = new RestartCommand(applicationClient, environmentSettings);
            var            options        = Substitute.For <RestartOptions>();

            restartCommand.Execute(options);
            applicationClient.Received(1).ExecutePostRequest(
                environmentSettings.Uri + "/ServiceModel/AppInstallerService.svc/RestartApp",
                "{}", Timeout.Infinite);
        }
        public ExceptionViewModel(Exception exception, IApplicationService applicationService)
        {
            _exception          = exception;
            _applicationService = applicationService;

            OpenLogFolderCommand = ReactiveCommand.Create(Observable.Return(_applicationService.LogFolder != null))
                                   .DisposeWith(this);

            CopyCommand = ReactiveCommand.Create(Observable.Return(exception != null))
                          .DisposeWith(this);

            ContinueCommand = ReactiveCommand.Create()
                              .DisposeWith(this);

            ExitCommand = ReactiveCommand.Create()
                          .DisposeWith(this);

            RestartCommand = ReactiveCommand.Create()
                             .DisposeWith(this);

            OpenLogFolderCommand.ActivateGestures()
            .Subscribe(x => OpenLogFolder())
            .DisposeWith(this);

            CopyCommand.ActivateGestures()
            .Subscribe(x => Copy())
            .DisposeWith(this);

            ContinueCommand.ActivateGestures()
            .Subscribe(x => Continue())
            .DisposeWith(this);

            ExitCommand
            .ActivateGestures()
            .Subscribe(x => Exit())
            .DisposeWith(this);

            RestartCommand
            .ActivateGestures()
            .Subscribe(x => Restart())
            .DisposeWith(this);
        }
        /// <summary>
        /// Process the game.
        /// </summary>
        /// <param name="playBoard">Current play board value.</param>
        /// <param name="playerMoves">Current player moves.</param>
        public void ProcessGame(ref char[,] playBoard, ref int playerMoves)
        {
            byte rowLenght = (byte)playBoard.GetLength(0);
            byte columnLenght = (byte)playBoard.GetLength(1);
            Board boardGenerator = new Board(rowLenght, columnLenght);

            ScoreBoardFormatter formatter = new ScoreBoardFormatter();

            // ILogger fileLogger = new FileLogger("scorebord.txt", formatter);
            ILogger consoleLogger = new ConsoleLogger(formatter);
            ScoreBoard scoreBoard = new ScoreBoard(consoleLogger);

            var printer = PrintingManager.Instance;

            switch (this.currentCommand)
            {
                case "RESTART":
                    IInputCommand restart = new RestartCommand(boardGenerator, printer);
                    restart.Execute(ref playBoard, ref playerMoves);
                    break;

                case "TOP":
                    IInputCommand topscoreBoard = new TopCommand(scoreBoard, this.topPlayers);
                    topscoreBoard.Execute(ref playBoard, ref playerMoves);
                    break;

                case "EXIT":
                    break;

                default:
                    InputCommandValidator validator = new InputCommandValidator();
                    if (validator.IsValidInputCommand(this.currentCommand))
                    {
                        IInputCommand play = new PlayCommand(this.currentCommand, this.topPlayers, scoreBoard, boardGenerator, printer);
                        play.Execute(ref playBoard, ref playerMoves);
                        break;
                    }

                    Console.WriteLine("Wrong input ! Try Again ! ");
                    break;
            }
        }
Ejemplo n.º 27
0
        public static void PauseControllers(Game1 game, KeyboardController keyboard, GamepadController gamepad, IGameState state)
        {
            keyboard.ClearDictionary();
            gamepad.ClearDictionary();


            ICommand unpause = new UnpauseCommand();

            keyboard.Add((int)Keys.P, unpause);
            gamepad.Add((int)Buttons.X, unpause);
            //Add the Exit Command to the controllers
            ICommand exitcommand = new ExitCommand(game);

            keyboard.Add((int)Keys.Q, exitcommand);
            gamepad.Add((int)Buttons.Start, exitcommand);
            ICommand resetcommand = new RestartCommand();

            keyboard.Add((int)Keys.R, resetcommand);
            gamepad.Add((int)Buttons.Back, resetcommand);
            AddSelection(game, keyboard, gamepad, state);
        }
        /// <summary>
        /// Adds a command to the configured commands. This properly initializes the class, subscribes to the command topic and writes it to the config file.
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="json"></param>
        public void AddCommand(AvailableCommands commandType, string json)
        {
            var serializerOptions = new JsonSerializerOptions
            {
                Converters = { new DynamicJsonConverter() }
            };
            dynamic model = JsonSerializer.Deserialize <dynamic>(json, serializerOptions);

            AbstractCommand commandToCreate = null;

            switch (commandType)
            {
            case AvailableCommands.ShutdownCommand:
                commandToCreate = new ShutdownCommand(this._publisher, model.Name);
                break;

            case AvailableCommands.RestartCommand:
                commandToCreate = new RestartCommand(this._publisher, model.Name);
                break;

            case AvailableCommands.LogOffCommand:
                commandToCreate = new LogOffCommand(this._publisher, model.Name);
                break;

            case AvailableCommands.CustomCommand:
                commandToCreate = new CustomCommand(this._publisher, model.Command, model.Name);
                break;

            default:
                Log.Logger.Error("Unknown sensortype");
                break;
            }
            if (commandToCreate != null)
            {
                this._configurationService.AddConfiguredCommand(commandToCreate);
            }
        }
Ejemplo n.º 29
0
 public void Execute(RestartCommand message)
 {
     Restart();
 }
Ejemplo n.º 30
0
        public ICommand BuildCommand(string command, IUser author, IMessageChannel channel, IGuild guild, params string[] parameters)
        {
            ICommand _command = null;

            switch (command)
            {
            case CommandNames.exit:
                _command = new ExitCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.update:
                _command = new UpdateCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.restart:
                _command = new RestartCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.help:
                _command = new HelpCommand(author, _config, channel, _messageWriter, _commandsInfo, _validationHandler, parameters);
                break;

            case CommandNames.version:
                _command = new VersionCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.random:
                _command = new RandomCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.github:
                _command = new GithubCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.uptime:
                _command = new UptimeCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.color:
                _command = new ColorCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.flipcoin:
                _command = new FlipcoinCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.roll:
                _command = new RollCommand(author, _config, channel, _messageWriter, _validationHandler, parameters);
                break;

            case CommandNames.purge:
                _command = new PurgeCommand(author, _config, channel, _messageWriter, _connectionHandler, _validationHandler, parameters);
                break;

            case CommandNames.summon:
                _command = new SummonCommand(author, _config, channel, _messageWriter, _audioService, guild, _validationHandler, parameters);
                break;

            case CommandNames.dismiss:
                _command = new DismissCommand(author, _config, channel, _messageWriter, _audioService, guild, _validationHandler, parameters);
                break;

            case CommandNames.play:
                _command = new PlayCommand(author, _config, channel, _messageWriter, _audioService, guild, _validationHandler, parameters);
                break;

            default:
                break;
            }
            return(_command);
        }
Ejemplo n.º 31
0
        public void CheckRunCommand()
        {
            RestartCommand zCommand = new RestartCommand();

            Assert.Equal("AT+TRSPSTART", zCommand.RunCommand());
        }
Ejemplo n.º 32
0
        public static void ReStartService()
        {
            ICommand command = new RestartCommand();

            command.DealCommand();//发送重启服务指令
        }