예제 #1
0
파일: Program.cs 프로젝트: borkowij/DevTest
        private static SurfaceAreaCalculator BuildSurfaceAreaCalculator()
        {
            var logger         = new Logger();
            var figuresStorage = new FiguresStorage();

            var figureCreators = new List <IFigureCreator>
            {
                new SquareCreator(),
                new CircleCreator(),
                new TriangleCreator(),
                new RectangleCreator(),
                new TrapezoidCreator()
            };

            var figureCreationManager = new FigureCreationManager(figureCreators);
            var commandExecutors      = new List <ICommandExecutor>
            {
                new CreateCommandExecutor(figuresStorage, figureCreationManager, logger),
                new PrintCommandExecutor(figuresStorage, logger),
                new ResetCommandExecutor(figuresStorage, logger),
                new ExitCommandExecutor()
            };

            var commandExecutionManager = new CommandExecutionManager(commandExecutors, logger);

            return(new SurfaceAreaCalculator(commandExecutionManager, logger));
        }
예제 #2
0
        public void ExecuteCommand_NullCommand_ArgumentNullException()
        {
            var commandExecutionManager = new CommandExecutionManager();
            var ex = Assert.Throws <ArgumentNullException>(
                () => commandExecutionManager.ExecuteCommand(null));

            Assert.That(ex.ParamName, Is.EqualTo(ExecuteCommandParam));
        }
예제 #3
0
        public void ExecuteCommand_ExecutesCommand()
        {
            var commandExecutionManager = new CommandExecutionManager();
            var commandMock             = new Mock <ICommand>();

            commandExecutionManager.ExecuteCommand(commandMock.Object);

            commandMock.Verify(c => c.Execute(), Times.Once());
        }
예제 #4
0
 public ContextMenuInitalizer(ClientsContextMenu clientsContextMenu, IEnumerable <ICommandDescription> commandDescriptions,
                              VisualStudioIcons icons, IWindowService windowService, CommandExecutionManager commandExecutionManager)
 {
     _clientsContextMenu  = clientsContextMenu;
     _commandDescriptions = commandDescriptions;
     _icons                   = icons;
     _windowService           = windowService;
     _commandExecutionManager = commandExecutionManager;
 }
예제 #5
0
 public TasksViewModel(IWindowService windowService, IMazeRestClient restClient, IAppDispatcher dispatcher, IServiceProvider services,
                       CommandExecutionManager commandExecutionManager) : base(Tx.T("TasksInfrastructure:Tasks"), PackIconFontAwesomeKind.CalendarCheckRegular)
 {
     CommandExecutionManager = commandExecutionManager;
     _windowService          = windowService;
     _restClient             = restClient;
     _dispatcher             = dispatcher;
     _services = services;
 }
예제 #6
0
        public void Undo_PerformsUndo()
        {
            var commandExecutionManager = new CommandExecutionManager();
            var commandMock             = new Mock <ICommand>();

            commandExecutionManager.ExecuteCommand(commandMock.Object);

            commandExecutionManager.Undo();

            commandMock.Verify(c => c.Undo(), Times.Once());
        }
예제 #7
0
        public void Redo_PerformsRedo()
        {
            var commandExecutionManager = new CommandExecutionManager();
            var commandMock             = new Mock <ICommand>();

            commandExecutionManager.ExecuteCommand(commandMock.Object);
            commandExecutionManager.Undo();

            commandExecutionManager.Redo();

            commandMock.Verify(c => c.Execute(), Times.Exactly(2));
        }
예제 #8
0
        public void ExecuteCommand_ClearsUndoHistory()
        {
            var commandExecutionManager = new CommandExecutionManager();
            var commandMock             = new Mock <ICommand>();

            commandExecutionManager.ExecuteCommand(commandMock.Object);
            commandExecutionManager.Undo();

            commandExecutionManager.ExecuteCommand(commandMock.Object);

            Assert.Throws <InvalidOperationException>(() => commandExecutionManager.Redo());
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandExample"/> class.
        /// </summary>
        /// <param name="robot">The <see cref="IRobot"/> to use in this example.</param>
        /// <param name="commandFactory">The <see cref="CommandFactory"/> used to create instances
        /// of <see cref="ICommand"/>.</param>
        /// <param name="commandExecutionManager">The <see cref="CommandExecutionManager"/> used
        /// to manage execution of instances of <see cref="ICommand"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="robot"/>,
        /// <paramref name="commandFactory"/>, or <paramref name="commandExecutionManager"/> is
        /// <see langword="null"/>.</exception>
        public CommandExample(
            IRobot robot,
            CommandFactory commandFactory,
            CommandExecutionManager commandExecutionManager)
        {
            ParameterValidation.IsNotNull(robot, nameof(robot));
            ParameterValidation.IsNotNull(commandFactory, nameof(commandFactory));
            ParameterValidation.IsNotNull(commandExecutionManager, nameof(commandExecutionManager));

            this.robot                   = robot;
            this.commandFactory          = commandFactory;
            this.commandExecutionManager = commandExecutionManager;
        }
예제 #10
0
        public void Redo_NothingToRedo_InvalidOperationException()
        {
            var commandExecutionManager = new CommandExecutionManager();

            Assert.Throws <InvalidOperationException>(() => commandExecutionManager.Redo());
        }
예제 #11
0
        /// <summary>
        /// Listen and process messages
        /// </summary>
        private void ProcessOperation()
        {
            var lastCommandDate = DateTime.Now;
            var time            = 0;

            _SocketReader.Clear();
            _SocketReader.SleepTime = 5;
            _SocketReader.Socket    = _Socket;
            _SocketReader.Timeout   = CommandTimeout;

            NetResponse response = null;

            try
            {
                while (_ProcessFlag)
                {
                    response = null;

                    if (_Socket.Available > 0)
                    {
                        OnBeginReceiveData();
                        _SocketReader.Clear();
                        _SocketReader.Read();
                        OnEndReceiveData();

                        if (_SocketReader.LastStatus == SocketReader.ReadStatus.Success)
                        {
                            if (_SocketReader.Type == SocketReader.ReadType.Command)
                            {
                                NetCommand command = NetCommand.Parse(_SocketReader.Data);
                                command.Id = _SocketReader.CommandId;

                                ServerCommandsManager.PublishCommandExecute(command);
                                command.Status = CommandStatus.Executed;

                                if (command.Response == null)
                                {
                                    command.Response = new NetResponse(false, "Server command could not be executed");
                                }

                                Send(command.Response);
                            }
                            else
                            {
                                var command = _SendCommands[_SocketReader.CommandId] as NetCommand;
                                if (command == null)
                                {
                                    OnUnknownServerData();
                                }
                                else
                                {
                                    response         = NetResponse.Parse(_SocketReader.Data);
                                    command.Response = response;
                                    command.Status   = CommandStatus.Executed;
                                    CommandExecutionManager.PublishCommandExecute(command);
                                    _SendCommands.Remove(command.Id);
                                }
                            }
                        }
                        else
                        {
                            Disconnect();
                        }

                        lastCommandDate = DateTime.Now;
                    }
                    else
                    {
                        NetCommand active = null;

                        for (int k = 0; k < Commands.Count; k++)
                        {
                            NetCommand cd = Commands[k, true];
                            if (cd.Status == CommandStatus.Waiting)
                            {
                                active = cd;
                                break;
                            }
                        }

                        if (active != null)
                        {
                            Commands.Active = active;
                            OnBeginSendingData();
                            Send(active);
                            OnEndSendingData();
                            _SendCommands.Add(active.Id, active);
                        }
                        else
                        {
                            time = Convert.ToInt32(DateTime.Now.Subtract(lastCommandDate).TotalMilliseconds);
                            if (KeepConnection && time >= NoopPeriod)
                            {
                                Commands.Add(new NetCommand(CommandNames.NOOP));
                            }
                            else
                            {
                                if (time > ConnectionTimeout)
                                {
                                    break;
                                }
                            }

                            Thread.Sleep(10);
                        }
                    }
                }
            }
            catch (SocketException ex)
            {
                if (ex.NativeErrorCode != 0x2745 && ex.NativeErrorCode != 0x2714)
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                OnSystemError(ex);
            }
            finally
            {
                Disconnect();
            }
        }