コード例 #1
0
ファイル: Customer.cs プロジェクト: AChehre/SimpleWorkflow
        private void ChangeState(CustomerState dest)
        {
            var command = GetCommand(CustomerTransition.Create(State, dest));

            if (command == null)
            {
                throw new Exception($"Command is null for {State} -> {dest}");
            }
            command.Execute();
        }
コード例 #2
0
        public CustomerService()
        {
            RegisterTransition(CustomerTransition.Create(CustomerState.Undefined, CustomerState.New),
                               new UndefinedToNewCommand());

            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Confirmed),
                               new NewToConfirmedCommand());


            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Unconfirmed),
                               new NewToUnconfirmedCommand());
        }
コード例 #3
0
        public void ChangeStateToUnconfirmed()
        {
            var transition = new CustomerTransition(State, CustomerState.Unconfirmed);

            if (!HasTransition(transition))
            {
                throw new InvalidOperationException(transition.ToString());
            }

            if (DocumentsSigned)
            {
                throw new Exception("Documents are signed!");
            }

            State = CustomerState.Unconfirmed;
        }
コード例 #4
0
ファイル: Customer.cs プロジェクト: AChehre/SimpleWorkflow
        public Customer(Guid customerId)
        {
            CustomerId = customerId;
            State      = CustomerState.Undefined;


            RegisterTransition(CustomerTransition.Create(CustomerState.Undefined, CustomerState.New),
                               new UndefinedToNewCommand(this));

            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Confirmed),
                               new NewToConfirmedCommand(this));


            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Unconfirmed),
                               new NewToUnconfirmedCommand(this));

            ChangeStateToNew();
        }
コード例 #5
0
        private void ChangeState(Customer customer, CustomerState dest)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }


            var command = GetCommand(CustomerTransition.Create(customer.State, dest));

            if (command == null)
            {
                throw new Exception($"Command is null for {customer.State} -> {dest}");
            }
            var baseCustomerCommand = (BaseCustomerCommand)command;

            baseCustomerCommand.SetCustomer(customer);
            command.Execute();
        }