예제 #1
0
 public StateEvent(string name, string status, string notes, IStateCommand expectedCommand = null)
 {
     ExpectedCommand = expectedCommand;
     Status          = status;
     Name            = name;
     Notes           = notes;
 }
예제 #2
0
        public override void ExecuteResult(ControllerContext context)
        {
            IStateCommand[] commands        = _facilitator.GetValidStateCommands(_expenseReport, _session.GetCurrentUser());
            IStateCommand   matchingCommand =
                Array.Find(commands, delegate(IStateCommand obj) { return(obj.Matches(_command)); });

            matchingCommand.Execute(_visitor);

            context.Controller.TempData["Flash"] = _session.PopUserMessage();
        }
예제 #3
0
 //execute command in response of the input state
 private void ExecuteTask
 (
     States _state,
     IStateCommand _command,
     WordCommandFactory _factory,
     Invoker _invoker
 )
 {
     if (_state != States.Exit)
     {
         _command = _factory.GetCommand(_state);
         _invoker.SetCommand(_command);
         _invoker.ExecuteCommand();
     }
 }
        public void ShouldFilterFullListToReturnValidCommands()
        {
            var mocks = new MockRepository();
            var facilitator = mocks.PartialMock<WorkflowFacilitator>(new StubbedCalendar(new DateTime(2000, 1, 1)));
            var commandsToReturn = new IStateCommand[]
                                       {
                                           new StubbedStateCommand(true), new StubbedStateCommand(true),
                                           new StubbedStateCommand(false)
                                       };

            Expect.Call(facilitator.GetAllStateCommands(null, null)).IgnoreArguments().Return(commandsToReturn);
            mocks.ReplayAll();

            IStateCommand[] commands = facilitator.GetValidStateCommands(null, null);

            mocks.VerifyAll();
            Assert.That(commands.Length, Is.EqualTo(2));
        }
예제 #5
0
        public void ShouldFilterFullListToReturnValidCommands()
        {
            var mocks            = new MockRepository();
            var facilitator      = mocks.PartialMock <WorkflowFacilitator>(new StubbedCalendar(new DateTime(2000, 1, 1)));
            var commandsToReturn = new IStateCommand[]
            {
                new StubbedStateCommand(true), new StubbedStateCommand(true),
                new StubbedStateCommand(false)
            };

            Expect.Call(facilitator.GetAllStateCommands(null, null)).IgnoreArguments().Return(commandsToReturn);
            mocks.ReplayAll();

            IStateCommand[] commands = facilitator.GetValidStateCommands(null, null);

            mocks.VerifyAll();
            Assert.That(commands.Length, Is.EqualTo(2));
        }
예제 #6
0
        public ExecuteTransitionResult Handle(ExecuteTransitionCommand command)
        {
            IStateCommand[] commands        = new WorkflowFacilitator().GetValidStateCommands(command);
            IStateCommand   matchingCommand =
                Array.Find(commands, delegate(IStateCommand obj) { return(obj.Matches(command.Command)); });

            matchingCommand.Execute(command);

            _bus.Send(new ExpenseReportSaveCommand {
                ExpenseReport = command.Report
            });
            _bus.Send(new AddExpenseReportFactCommand(new ExpenseReportFact(command.Report, command.CurrentDate)));

            return(new ExecuteTransitionResult
            {
                NewStatus = command.Report.Status.FriendlyName,
                NextStep = NextStep.Edit
            });
        }
 /// <summary>
 /// Initialize a new CommandDispatcher
 /// </summary>
 /// <param name="commandArguments">the command line options</param>
 /// <param name="parameterCommand">the parameter command</param>
 /// <param name="subscriptionCommand">the subscription command</param>
 /// <param name="optionCommand">the option command</param>
 /// <param name="scaleCommand">the scale command</param>
 /// <param name="stateCommand">the state command</param>
 /// <param name="domainCommand">the domain command</param>
 /// <param name="valueSetCommand">the value set command</param>
 /// <param name="reportGenerator">the reportgernerator command</param>
 public CommandDispatcher(
     ICommandArguments commandArguments,
     IParameterCommand parameterCommand,
     ISubscriptionCommand subscriptionCommand,
     IOptionCommand optionCommand,
     IScaleCommand scaleCommand,
     IStateCommand stateCommand,
     IDomainCommand domainCommand,
     IValueSetCommand valueSetCommand,
     IReportGenerator reportGenerator)
 {
     this.commandArguments    = commandArguments;
     this.parameterCommand    = parameterCommand;
     this.subscriptionCommand = subscriptionCommand;
     this.optionCommand       = optionCommand;
     this.scaleCommand        = scaleCommand;
     this.stateCommand        = stateCommand;
     this.domainCommand       = domainCommand;
     this.valueSetCommand     = valueSetCommand;
     this.reportGenerator     = reportGenerator;
 }
예제 #8
0
 public StateCommandInfo(int processId, IStateCommand state) : base(processId, state)
 {
     State = state;
 }
예제 #9
0
 public StateEventInfo(int processId, string name, string status, string notes, IStateCommand expectedCommand) : base(processId, new StateEvent(name, status, notes, expectedCommand))
 {
     State = new StateEvent(name, status, notes, expectedCommand);
 }
예제 #10
0
        //Manages the menu as a state maschine
        public void MenuLoop
        (
            States _state,
            DictionaryManager _dictionaryManager
        )
        {
            Invoker            invoker = new Invoker();
            WordCommandFactory factory = new WordCommandFactory(_dictionaryManager);
            IStateCommand      command = factory.GetCommand(_state);
            ConsoleKeyInfo     keyinfo = Console.ReadKey();

            while (_state != States.Exit)
            {
                this.DisplayMenu();
                _state  = States.idle;
                keyinfo = Console.ReadKey();
                if (keyinfo.KeyChar == '0')
                {
                    _state = States.import;
                }
                if (keyinfo.KeyChar == '1')
                {
                    _state = States.translatePol2ang;
                }
                if (keyinfo.KeyChar == '2')
                {
                    _state = States.translateAng2Pol;
                }
                if (keyinfo.KeyChar == '3')
                {
                    _state = States.addWord;
                }
                if (keyinfo.KeyChar == '4')
                {
                    _state = States.deleteWord;
                }
                if (keyinfo.KeyChar == '5')
                {
                    _state = States.DisplayAll;
                }
                if (keyinfo.KeyChar == '6')
                {
                    _state = States.Sort;
                }
                if (keyinfo.KeyChar == '7')
                {
                    _state = States.BST;
                }
                if (keyinfo.KeyChar == '8')
                {
                    _state = States.Exit;
                }
                Console.ReadKey();
                this.ExecuteTask
                (
                    _state,
                    command,
                    factory,
                    invoker
                );


                Console.Clear();
            }
        }
예제 #11
0
 public void SetCommand(IStateCommand command)
 {
     this._command = command;
 }