public CreatedStateLogging( ILog log, IAccountState decorated) { this.log = CtorGuard.NotNull(log, nameof(log)); this.decorated = CtorGuard.NotNull(decorated, nameof(decorated)); }
//取钱 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); } }
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); }
internal Account(IAccountState accountState, IAccountStateFactory stateFactory, Money initialMoney, string holder) { _state = accountState; _stateFactory = stateFactory; _money = initialMoney; _holder = holder; }
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); }
public void Withdraw(Money amount) { if (amount.Currency != Balance.Currency) { return; } else { this.State = this.State.Withdraw(() => { Balance.Value -= amount.Value; }); } }
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; }); }
public void Deposit(Money amount) { if (amount.Currency != Balance.Currency) { return; } else { this.State = this.State.Deposit(() => { Balance.Value += amount.Value; }); } }
public void Freeze() { if (this.IsClosed) { return; } if (!this.IsVerifeid) { return; } this.AccountState = this.AccountState.Freeze(); }
public void Withdraw(decimal amount) { if (!this.IsVerifeid) { return; } if (this.IsClosed) { return; } this.AccountState = this.AccountState.Withdraw(() => this.Balance -= amount); }
//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"); } }); }
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); }
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(); } }
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)); }
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); }
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; }
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; } }
public void Freeze() { this.State = this.State.Freeze(); }
public void Close() { this.State = this.State.Close(); }
public void HolderVerified() { this.State = this.State.HolderVerified(); }
// #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; }); }
public Account(Action onUnfreeze) { this.State = new NotVerified(onUnfreeze); }
/// <summary> /// Same tests as Deposit() /// </summary> /// <param name="amount"></param> public void Withdraw(decimal amount) { this.State = this.State.Withdraw(() => { this.Balance -= amount; }); }
public void HolderVerified() { this.State = this.State.HolderVerified(); }
/// <summary> /// Depositing or Withdrawing unfreezes account, /// needs callback function on unfreeze /// </summary> public void Freeze() { this.State = this.State.Freeze(); }
/// <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; }); }
public void Close() { this.State = this.State.Close(); }
public void Close() => this.State = this.State.Close(_amount);
public void Open() => this.State = this.State.Open();
public void HolderVirfied() => this.State = this.State.HolderVerified();