public CreatedStateLogging(
     ILog log,
     IAccountState decorated)
 {
     this.log       = CtorGuard.NotNull(log, nameof(log));
     this.decorated = CtorGuard.NotNull(decorated, nameof(decorated));
 }
Exemplo n.º 2
0
 //取钱
 public void Withdraw(decimal amount)
 {
     this.State = this.State.Withdraw(() =>
     {
         this.Balance -= amount;
     });
 }
 public CreatedStateLogging(
     ILogger logger,
     IAccountState decorated)
 {
     this.logger    = logger ?? throw new System.ArgumentNullException(nameof(logger));
     this.decorated = decorated ?? throw new System.ArgumentNullException(nameof(decorated));
 }
 private void SetState(IAccountState state)
 {
     lock (mutex)
     {
         this.state = state;
         this.state.StateTransition(this);
     }
 }
Exemplo n.º 5
0
        public void Deposit(decimal amount)
        {
            //if (this.IsClosed)
            //    return;
            //this.Freezable = this.Freezable.Deposit();

            this.State = this.State.Deposit(() => { this.Balance += amount; });
        }
 public void Deposit(decimal amount)
 {
     if (this.IsClosed)
     {
         return;
     }
     this.AccountState = this.AccountState.Deposit(() => this.Balance += amount);
 }
Exemplo n.º 7
0
 internal Account(IAccountState accountState,
                  IAccountStateFactory stateFactory,
                  Money initialMoney,
                  string holder)
 {
     _state        = accountState;
     _stateFactory = stateFactory;
     _money        = initialMoney;
     _holder       = holder;
 }
Exemplo n.º 8
0
        public void Freeze()
        {
            //if (this.IsClosed)
            //    return;
            //if (!this.IsVerified)
            //    return;

            //this.Freezable = this.Freezable.Freeze();
            this.State = this.State.Freeze();
        }
        public AccountStatusAwareOperations(
            IAccountState activeState,
            IAccountState inactiveState,
            IAccountState initialState)
        {
            this.activeState   = activeState ?? throw new System.ArgumentNullException(nameof(activeState));
            this.inactiveState = inactiveState ?? throw new System.ArgumentNullException(nameof(inactiveState));
            this.initialState  = initialState ?? throw new System.ArgumentNullException(nameof(initialState));

            SetState(initialState);
        }
Exemplo n.º 10
0
 public void Withdraw(Money amount)
 {
     if (amount.Currency != Balance.Currency)
     {
         return;
     }
     else
     {
         this.State = this.State.Withdraw(() => { Balance.Value -= amount.Value; });
     }
 }
Exemplo n.º 11
0
        public void Withdraw(decimal amount)
        {
            //if (!this.IsVerified)
            //    return;

            //if (this.IsClosed)
            //    return;

            //this.Freezable = this.Freezable.Withdraw();
            this.State = this.State.Withdraw(() => { this.Balance -= amount; });
        }
Exemplo n.º 12
0
 public void Deposit(Money amount)
 {
     if (amount.Currency != Balance.Currency)
     {
         return;
     }
     else
     {
         this.State = this.State.Deposit(() => { Balance.Value += amount.Value; });
     }
 }
Exemplo n.º 13
0
 public void Freeze()
 {
     if (this.IsClosed)
     {
         return;
     }
     if (!this.IsVerifeid)
     {
         return;
     }
     this.AccountState = this.AccountState.Freeze();
 }
Exemplo n.º 14
0
 public void Withdraw(decimal amount)
 {
     if (!this.IsVerifeid)
     {
         return;
     }
     if (this.IsClosed)
     {
         return;
     }
     this.AccountState = this.AccountState.Withdraw(() => this.Balance -= amount);
 }
Exemplo n.º 15
0
        //private read-only IBlocksProcessor _blocksProcessor

        public NodeMain(IServerCommunicationServicesRepository communicationServicesFactory, IServerCommunicationServicesRegistry communicationServicesRegistry, IConfigurationService configurationService, IModulesRepository modulesRepository, IPacketsHandler packetsHandler, IBlocksHandlersRegistry blocksProcessorFactory, ILoggerService loggerService, ICryptoService cryptoService, IStatesRepository statesRepository)
        {
            _log = loggerService.GetLogger(GetType().Name);
            _communicationServicesFactory  = communicationServicesFactory;
            _communicationServicesRegistry = communicationServicesRegistry;
            _configurationService          = configurationService;
            _modulesRepository             = modulesRepository;
            _packetsHandler          = packetsHandler;
            _cryptoService           = cryptoService;
            _nodeContext             = statesRepository.GetInstance <INodeContext>();
            _accountState            = statesRepository.GetInstance <IAccountState>();
            _cancellationTokenSource = new CancellationTokenSource();
        }
 // #3 (Interaction): Withdraw was invoked on the State
 // #4 (Behavior): Result of State.Withdraw is new State
 // #6 (Behavior): Deposit 1, Verify, Withdraw 1 - Balance == 9
 public void Withdraw(decimal amount)
 {
     State = State.Withdraw(() =>
     {
         if (amount <= Balance)
         {
             Balance -= amount;
             Console.WriteLine($"Successfully withdrawn {amount}");
         }
         else
         {
             Console.WriteLine("amount less than Balance - cannot withdraw");
         }
     });
 }
Exemplo n.º 17
0
        public LoyaltyPointAccount(
            IAccountState createdState,
            IAccountState activeState,
            IAccountState inactiveState,
            LoyaltyPointAccountIdentity identity,
            Currency primaryCurrency)
        {
            this.createdState  = CtorGuard.NotNull(createdState, nameof(createdState));
            this.activeState   = CtorGuard.NotNull(activeState, nameof(activeState));
            this.inactiveState = CtorGuard.NotNull(inactiveState, nameof(inactiveState));

            this.identity        = identity;
            this.primaryCurrency = primaryCurrency;

            SetState(createdState);
        }
Exemplo n.º 18
0
        public Account(string owner, string agency, double numberAccount)
        {
            Owner         = owner;
            Agency        = agency;
            NumberAccount = numberAccount;
            CreatedOn     = DateTime.Now;

            if (Balance >= 0)
            {
                AccountState = new PositiveBalance();
            }
            else
            {
                AccountState = new NegativeBalance();
            }
        }
Exemplo n.º 19
0
 public SynchronizationGroupParticipationService(ISynchronizationProducer synchronizationProducer, IStatesRepository statesRepository,
                                                 INodesRatingProviderFactory nodesRatingProvidersFactory, ILoggerService loggerService)
 {
     _synchronizationProducer   = synchronizationProducer;
     _nodesRatingProvider       = nodesRatingProvidersFactory.GetInstance(PacketType.Transactional);
     _synchronizationContext    = statesRepository.GetInstance <ISynchronizationContext>();
     _accountState              = statesRepository.GetInstance <IAccountState>();
     _synchronizationGroupState = statesRepository.GetInstance <ISynchronizationGroupState>();
     _synchronizationGroupParticipationCheckAction = new TransformBlock <string, string>((Func <string, string>)SynchronizationGroupParticipationCheckAction, new ExecutionDataflowBlockOptions {
         MaxDegreeOfParallelism = 1
     });
     _synchronizationGroupLeaderCheckAction = new ActionBlock <string>((Action <string>)SynchronizationGroupLeaderCheckAction, new ExecutionDataflowBlockOptions {
         MaxDegreeOfParallelism = 1
     });
     _logger = loggerService.GetLogger(nameof(SynchronizationGroupParticipationService));
 }
Exemplo n.º 20
0
 public SynchronizationBlocksHandler(IStatesRepository statesRepository, ISynchronizationProducer synchronizationProducer, ISerializersFactory signatureSupportSerializersFactory,
                                     ICryptoService cryptoService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, INodesRatingProviderFactory nodesRatingProvidersFactory, IServerCommunicationServicesRegistry communicationServicesRegistry)
 {
     _synchronizationContext             = statesRepository.GetInstance <ISynchronizationContext>();
     _synchronizationProducer            = synchronizationProducer;
     _nodeContext                        = statesRepository.GetInstance <INodeContext>();
     _accountState                       = statesRepository.GetInstance <IAccountState>();
     _neighborhoodState                  = statesRepository.GetInstance <INeighborhoodState>();
     _signatureSupportSerializersFactory = signatureSupportSerializersFactory;
     _cryptoService                      = cryptoService;
     _communicationServicesRegistry      = communicationServicesRegistry;
     _identityKeyProvider                = identityKeyProvidersRegistry.GetInstance();
     _synchronizationBlocks              = new BlockingCollection <SynchronizationBlockBase>();
     _retransmittedBlocks                = new BlockingCollection <SynchronizationBlockRetransmissionV1>();
     _synchronizationBlocksByHeight      = new Dictionary <ulong, Dictionary <IKey, List <SynchronizationBlockRetransmissionV1> > >();
     _nodesRatingProvider                = nodesRatingProvidersFactory.GetInstance(PacketType.Transactional);
 }
Exemplo n.º 21
0
        public Account(bool isVerified, bool isOpen, decimal initialAmount, string holder, Action onUnFreeze)
        {
            if (isVerified)
            {
                State = new Active(onUnFreeze);
            }
            if (isOpen)
            {
                State = new Active(onUnFreeze);
            }
            else
            {
                State = new Closed(onUnFreeze);
            }

            _amount         = initialAmount;
            _holder         = holder;
            this.onUnFreeze = onUnFreeze;
        }
Exemplo n.º 22
0
        public Account(double balance)
        {
            _nilAcountState     = new NilAccountState(this);
            _silverAccountState = new SilverAccountState(this);
            _goldAccountState   = new GoldAccountState(this);

            Balance = balance;

            if (Balance > 0 && Balance <= 1000)
            {
                _currentState = _silverAccountState;
            }
            else if (Balance > 1000)
            {
                _currentState = _goldAccountState;
            }
            else
            {
                _currentState = _nilAcountState;
            }
        }
Exemplo n.º 23
0
 public void Freeze()
 {
     this.State = this.State.Freeze();
 }
Exemplo n.º 24
0
 public void Close()
 {
     this.State = this.State.Close();
 }
Exemplo n.º 25
0
 public void HolderVerified()
 {
     this.State = this.State.HolderVerified();
 }
Exemplo n.º 26
0
 // #1 (Interaction): Deposit was invoked on the State
 // #2 (Behavior): Result of State.Deposit is new State
 // #5 (Behavior): Deposit 10, Deposit 1 - Balance == 11
 public void Deposit(decimal amount)
 {
     this.State = this.State.Deposit(() => { this.Balance += amount; });
 }
Exemplo n.º 27
0
 public Account(Action onUnfreeze)
 {
     this.State = new NotVerified(onUnfreeze);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Same tests as Deposit()
 /// </summary>
 /// <param name="amount"></param>
 public void Withdraw(decimal amount)
 {
     this.State = this.State.Withdraw(() => { this.Balance -= amount; });
 }
Exemplo n.º 29
0
 public void HolderVerified()
 {
     this.State = this.State.HolderVerified();
 }
Exemplo n.º 30
0
 /// <summary>
 /// Depositing or Withdrawing unfreezes account,
 /// needs callback function on unfreeze
 /// </summary>
 public void Freeze()
 {
     this.State = this.State.Freeze();
 }
Exemplo n.º 31
0
 /// <summary>
 /// #1: Interaction - Deposit was invoked on the State
 /// #2: Behavior - Result of State.Deposit is new State
 /// </summary>
 /// <param name="amount"></param>
 public void Deposit(decimal amount)
 {
     this.State = this.State.Deposit(() => { this.Balance += amount; });
 }
Exemplo n.º 32
0
 public void Close()
 {
     this.State = this.State.Close();
 }
Exemplo n.º 33
0
 public void Close() => this.State = this.State.Close(_amount);
Exemplo n.º 34
0
 public void Open() => this.State = this.State.Open();
Exemplo n.º 35
0
 public void HolderVirfied() => this.State = this.State.HolderVerified();