Exemple #1
0
        /// <summary>
        /// 加载钱包
        /// </summary>
        /// <param name="walletRepository"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private Domain.Wallet LoadWallet(IWalletRepository walletRepository, Guid id)
        {
            var wallet = walletRepository.Get(id);

            if (wallet == null)
            {
                wallet = Domain.Wallet.Create(id);
                walletRepository.Add(wallet);
                try
                {
                    Factory.GetUnitOfWork().Commit();
                }
                catch (ClassicDomain.UniqueException)
                {
                    wallet = walletRepository.Get(id);
                }
            }
            else if (wallet.IsTrading())
            {
                var billingRepository = Factory.CreateBillingRepository();
                var billing           = GetLastValidBilling(billingRepository, id);
                if (billing == null)
                {
                    wallet.Init();
                }
                else
                {
                    wallet.FinishTrade(billing);
                }
                walletRepository.Replace(wallet);
                Factory.GetUnitOfWork().Commit();
            }
            return(wallet);
        }
Exemple #2
0
        public TradeService(IRepositoryFactory factory)
        {
            Factory = factory;

            if (Generator == null)
            {
                lock (GeneratorLocker)
                {
                    if (Generator == null)
                    {
                        var start = Factory.CreateBillingRepository().GetLashId() + 1;
                        Generator = new IdLongGenerator(1, start);
                    }
                }
            }
        }