예제 #1
0
 public void SaveCalcConfigs(List <CalcConfigData> data)
 {
     InitOnece();
     if (data == null || data.Count == 0)
     {
         return;
     }
     lock (_locker) {
         var dic = new Dictionary <string, CalcConfigData>(StringComparer.OrdinalIgnoreCase);
         foreach (var item in data)
         {
             if (dic.ContainsKey(item.CoinCode))
             {
                 dic[item.CoinCode].Update(item);
             }
             else
             {
                 dic.Add(item.CoinCode, item);
             }
         }
         using (LiteDatabase db = HostRoot.CreateLocalDb()) {
             var col = db.GetCollection <CalcConfigData>();
             col.Delete(Query.All());
             col.Insert(dic.Values);
         }
         _dicByCode = dic;
     }
 }
예제 #2
0
 public void SaveCalcConfigs(List <CalcConfigData> data)
 {
     InitOnece();
     if (data == null || data.Count == 0)
     {
         return;
     }
     lock (_locker) {
         string[] toRemoves = _dicByCode.Where(a => data.All(b => string.Equals(a.Key, b.CoinCode, StringComparison.OrdinalIgnoreCase))).Select(a => a.Key).ToArray();
         foreach (var key in toRemoves)
         {
             _dicByCode.Remove(key);
         }
         foreach (var item in data)
         {
             if (_dicByCode.ContainsKey(item.CoinCode))
             {
                 _dicByCode[item.CoinCode].Update(item);
             }
             else
             {
                 item.CreatedOn = DateTime.Now;
                 _dicByCode.Add(item.CoinCode, item);
             }
         }
         using (LiteDatabase db = HostRoot.CreateLocalDb()) {
             var col = db.GetCollection <CalcConfigData>();
             col.Delete(Query.In(nameof(CalcConfigData.CoinCode), toRemoves.Select(a => new BsonValue(a)).ToArray()));
             col.Upsert(_dicByCode.Values);
         }
     }
 }
예제 #3
0
 internal ClientSet(IHostRoot root)
 {
     _root = root;
     GetSpeed();
     VirtualRoot.On <Per20SecondEvent>("周期性将内存中的ClientData列表刷入磁盘", LogEnum.DevConsole,
                                       action: message => {
         InitOnece();
         lock (_locker) {
             DateTime time = message.Timestamp.AddMinutes(-5);
             using (LiteDatabase db = HostRoot.CreateLocalDb()) {
                 var col = db.GetCollection <MinerData>();
                 col.Upsert(_dicByObjectId.Values.Where(a => a.ModifiedOn > time).Select(a => new MinerData {
                     CreatedOn        = a.CreatedOn,
                     GroupId          = a.GroupId,
                     Id               = a.Id,
                     ClientId         = a.ClientId,
                     MinerIp          = a.MinerIp,
                     MinerName        = a.MinerName,
                     WindowsLoginName = a.WindowsLoginName,
                     WindowsPassword  = a.WindowsPassword,
                     WorkId           = a.WorkId
                 }));
             }
         }
     });
 }
예제 #4
0
 public void Remove(string objectId)
 {
     if (_dicByObjectId.TryGetValue(objectId, out ClientData clientData))
     {
         _dicByObjectId.Remove(objectId);
         _dicByClientId.Remove(clientData.ClientId);
         using (LiteDatabase db = HostRoot.CreateLocalDb()) {
             var col = db.GetCollection <MinerData>();
             col.Delete(clientData.Id);
         }
     }
 }
예제 #5
0
 public void Remove(Guid id)
 {
     InitOnece();
     lock (_locker) {
         if (_dicById.ContainsKey(id))
         {
             _dicById.Remove(id);
             using (LiteDatabase db = HostRoot.CreateLocalDb()) {
                 var col = db.GetCollection <PoolData>();
                 col.Delete(id);
             }
         }
     }
 }
예제 #6
0
 private void Init()
 {
     lock (_locker) {
         if (!_isInited)
         {
             using (LiteDatabase db = HostRoot.CreateLocalDb()) {
                 var col = db.GetCollection <PoolData>();
                 foreach (var item in col.FindAll())
                 {
                     _dicById.Add(item.Id, item);
                 }
             }
             _isInited = true;
         }
     }
 }
예제 #7
0
 internal ClientSet(IHostRoot root)
 {
     _root = root;
     GetSpeed();
     VirtualRoot.On <Per20SecondEvent>("周期性将内存中3分钟内活跃的ClientData列表刷入磁盘", LogEnum.DevConsole,
                                       action: message => {
         InitOnece();
         List <MinerData> minerDatas = new List <MinerData>();
         lock (_locker) {
             DateTime time = message.Timestamp.AddMinutes(-3);
             foreach (var clientData in _dicByObjectId.Values)
             {
                 if (clientData.ModifiedOn > time)
                 {
                     minerDatas.Add(new MinerData {
                         CreatedOn        = clientData.CreatedOn,
                         GroupId          = clientData.GroupId,
                         Id               = clientData.Id,
                         ClientId         = clientData.ClientId,
                         ClientName       = clientData.ClientName,
                         MinerIp          = clientData.MinerIp,
                         MinerName        = clientData.MinerName,
                         WindowsLoginName = clientData.WindowsLoginName,
                         WindowsPassword  = clientData.WindowsPassword,
                         WorkId           = clientData.WorkId
                     });
                 }
                 else
                 {
                     clientData.IsMining      = false;
                     clientData.MainCoinSpeed = 0;
                     clientData.DualCoinSpeed = 0;
                     foreach (var item in clientData.GpuTable)
                     {
                         item.MainCoinSpeed = 0;
                         item.DualCoinSpeed = 0;
                     }
                 }
             }
         }
         using (LiteDatabase db = HostRoot.CreateLocalDb()) {
             var col = db.GetCollection <MinerData>();
             col.Upsert(minerDatas);
         }
     });
 }
예제 #8
0
 public void AddOrUpdate(PoolData data)
 {
     InitOnece();
     lock (_locker) {
         using (LiteDatabase db = HostRoot.CreateLocalDb()) {
             var col = db.GetCollection <PoolData>();
             if (_dicById.ContainsKey(data.Id))
             {
                 _dicById[data.Id].Update(data);
                 col.Update(_dicById[data.Id]);
             }
             else
             {
                 _dicById.Add(data.Id, data);
                 col.Insert(data);
             }
         }
     }
 }
예제 #9
0
        public void AddMiner(string minerIp)
        {
            MinerData minerData = new MinerData {
                Id               = ObjectId.NewObjectId().ToString(),
                ClientId         = Guid.NewGuid(),
                CreatedOn        = DateTime.Now,
                GroupId          = Guid.Empty,
                MinerIp          = minerIp,
                WindowsLoginName = string.Empty,
                WindowsPassword  = String.Empty,
                WorkId           = Guid.Empty
            };
            var clientData = MinerData.CreateClientData(minerData);

            Add(clientData);
            using (LiteDatabase db = HostRoot.CreateLocalDb()) {
                var col = db.GetCollection <MinerData>();
                col.Insert(minerData);
            }
        }
예제 #10
0
 public void AddOrUpdate(MineWorkData data)
 {
     InitOnece();
     lock (_locker) {
         using (LiteDatabase db = HostRoot.CreateLocalDb()) {
             var col = db.GetCollection <MineWorkData>();
             if (_dicById.ContainsKey(data.Id))
             {
                 data.ModifiedOn = DateTime.Now;
                 _dicById[data.Id].Update(data);
                 col.Update(_dicById[data.Id]);
             }
             else
             {
                 data.CreatedOn = DateTime.Now;
                 _dicById.Add(data.Id, data);
                 col.Insert(data);
             }
         }
     }
 }
예제 #11
0
 private void Init()
 {
     lock (_locker) {
         if (!_isInited)
         {
             using (LiteDatabase db = HostRoot.CreateLocalDb()) {
                 var col = db.GetCollection <MinerData>();
                 foreach (var item in col.FindAll())
                 {
                     var data = MinerData.CreateClientData(item);
                     _dicByObjectId.Add(item.Id, data);
                     if (!_dicByClientId.ContainsKey(item.ClientId))
                     {
                         _dicByClientId.Add(item.ClientId, data);
                     }
                 }
             }
             _isInited = true;
         }
     }
 }
예제 #12
0
        private void InitOnece()
        {
            DateTime now = DateTime.Now;

            if (_lastInitOn.AddMinutes(10) < now)
            {
                lock (_locker) {
                    if (_lastInitOn.AddMinutes(10) < now)
                    {
                        _pubKeys.Clear();
                        using (LiteDatabase db = HostRoot.CreateLocalDb()) {
                            var col = db.GetCollection <UserData>();
                            foreach (var item in col.FindAll())
                            {
                                _pubKeys.Add(item.LoginName, item);
                            }
                        }
                        _lastInitOn = DateTime.Now;
                    }
                }
            }
        }