예제 #1
0
        public void UpdateShare(Guid coinId, int?acceptShareCount, int?rejectShareCount, DateTime now)
        {
            CoinShare coinShare = (CoinShare)GetOrCreate(coinId);
            bool      isChanged = false;

            if (acceptShareCount.HasValue)
            {
                if (coinShare.AcceptShareCount != acceptShareCount.Value)
                {
                    coinShare.AcceptShareCount = acceptShareCount.Value;
                    isChanged = true;
                }
            }
            if (rejectShareCount.HasValue)
            {
                if (coinShare.RejectShareCount != rejectShareCount.Value)
                {
                    coinShare.RejectShareCount = rejectShareCount.Value;
                    isChanged = true;
                }
            }
            coinShare.ShareOn = now;
            if (isChanged)
            {
                VirtualRoot.RaiseEvent(new ShareChangedEvent(coinShare));
            }
        }
예제 #2
0
        public ICoinShare GetOrCreate(Guid coinId)
        {
            if (!_root.CoinSet.Contains(coinId))
            {
                return(new CoinShare()
                {
                    CoinId = coinId,
                    RejectShareCount = 0,
                    RejectPercent = 0,
                    ShareOn = DateTime.Now,
                    AcceptShareCount = 0
                });
            }
            CoinShare share;

            if (!_dicByCoinId.TryGetValue(coinId, out share))
            {
                lock (_locker) {
                    if (!_dicByCoinId.TryGetValue(coinId, out share))
                    {
                        share = new CoinShare {
                            CoinId           = coinId,
                            RejectShareCount = 0,
                            RejectPercent    = 0,
                            ShareOn          = DateTime.Now,
                            AcceptShareCount = 0
                        };
                        _dicByCoinId.Add(coinId, share);
                    }
                }
            }
            return(share);
        }