示例#1
0
        private void RegisterBalanceChange(RegisterMyAccountBalanceChange cmd)
        {
            Monitor();

            _stopWatch = Stopwatch.StartNew();
            _stopWatch.Start();

            var account =
                _porfolioState.SupervizedAccounts.FirstOrDefault(x => x.Key == cmd.AccountNumber).Value ??
                new AccountUnderSupervision(cmd.AccountNumber, cmd.AccountBalanceAfterTransaction);

            _log.Debug(
                $"[RegisterBalanceChange]: account.BalanceAfterLastTransaction={account.BalanceAfterLastTransaction}\t" +
                $"cmd.AccountBalanceAfterTransaction={cmd.AccountBalanceAfterTransaction}\n" +
                $"account.LastBilledAmount={account.LastBilledAmount}\tcmd.AmountTransacted={cmd.AmountTransacted}");

            account.LastBilledAmount            = cmd.AmountTransacted;
            account.BalanceAfterLastTransaction = cmd.AccountBalanceAfterTransaction;

            _porfolioState.SupervizedAccounts.AddOrSet(cmd.AccountNumber, account);
            var before = _stopWatch.ElapsedMilliseconds;

            _porfolioState.UpdateBalance();
            var after = _stopWatch.ElapsedMilliseconds;



            var @event =
                new AccountUnderSupervisionBalanceChanged(
                    account.AccountNumber
                    , account.BalanceAfterLastTransaction
                    );

            _stopWatch.Stop();
            if (after - before >= 2)
            {
                ReportStopwatchInfo($"RegisterBalanceChange()/UpdateBalance() timediff {after-before}ms", _stopWatch.ElapsedMilliseconds);
            }
            else
            {
                ReportStopwatchInfo($"RegisterBalanceChange()", _stopWatch.ElapsedMilliseconds);
            }

            Persist(@event, s => ApplySnapShotStrategy());


            //Self.Tell(new PublishPortfolioStateToKafka());
        }
示例#2
0
        private void UpdateAccountUnderSupervisionBalance(AccountUnderSupervisionBalanceChanged cmd)
        {
            Monitor();

            _stopWatch = Stopwatch.StartNew();
            _stopWatch.Start();

            var account =
                _porfolioState.SupervizedAccounts.FirstOrDefault(x => x.Key == cmd.AccountNumber).Value ??
                new AccountUnderSupervision(cmd.AccountNumber, cmd.NewAccountBalance);

            account.BalanceAfterLastTransaction = cmd.NewAccountBalance;
            _porfolioState.SupervizedAccounts.AddOrSet(cmd.AccountNumber, account);
            _porfolioState.UpdateBalance();

            _stopWatch.Stop();
            ReportStopwatchInfo("UpdateAccountUnderSupervisionBalance", _stopWatch.ElapsedMilliseconds);
        }