예제 #1
0
        /// <summary>
        ///
        /// </summary>
        private void Snapshot(DateTime now)
        {
            InitOnece();
            try {
                var coinSnapshots = VirtualRoot.CreateCoinSnapshots(_isPull, now, _clientSet.AsEnumerable().ToArray(), out int onlineCount, out int miningCount);

                _clientSet.ClientCount.Update(onlineCount, miningCount);
                if (coinSnapshots.Count > 0)
                {
                    _dataList.AddRange(coinSnapshots);
                    using (LiteDatabase db = CreateReportDb()) {
                        var col = db.GetCollection <CoinSnapshotData>();
                        col.Insert(coinSnapshots);
                    }
                    NTMinerConsole.UserLine("拍摄快照" + coinSnapshots.Count + "张,快照时间戳:" + now.ToString("yyyy-MM-dd HH:mm:ss fff"), _isPull ? MessageType.Debug : MessageType.Info);
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
        }
예제 #2
0
        public List <ClientData> QueryClients(
            IUser user,
            QueryClientsRequest query,
            out int total,
            out List <CoinSnapshotData> coinSnapshots,
            out int onlineCount,
            out int miningCount)
        {
            coinSnapshots = new List <CoinSnapshotData>();
            onlineCount   = 0;
            miningCount   = 0;
            if (!IsReadied)
            {
                total = 0;
                return(new List <ClientData>());
            }
            List <ClientData> list = new List <ClientData>();
            var  data                = _dicByObjectId.Values.ToArray();
            bool isFilterByUser      = user != null && !string.IsNullOrEmpty(user.LoginName) && !user.IsAdmin();
            bool isFilterByGroup     = query.GroupId.HasValue && query.GroupId.Value != Guid.Empty;
            bool isFilterByMinerIp   = !string.IsNullOrEmpty(query.MinerIp);
            bool isFilterByMinerName = !string.IsNullOrEmpty(query.MinerName);
            bool isFilterByVersion   = !string.IsNullOrEmpty(query.Version);
            bool isFilterByWork      = query.WorkId.HasValue && query.WorkId.Value != Guid.Empty;
            bool isFilterByCoin      = !isFilterByWork && !string.IsNullOrEmpty(query.Coin);
            bool isFilterByPool      = !isFilterByWork && !string.IsNullOrEmpty(query.Pool);
            bool isFilterByWallet    = !isFilterByWork && !string.IsNullOrEmpty(query.Wallet);
            bool isFilterByKernel    = !isFilterByWork && !string.IsNullOrEmpty(query.Kernel);
            bool isFilterByGpuType   = query.GpuType != GpuType.Empty;
            bool isFilterByGpuName   = !string.IsNullOrEmpty(query.GpuName);
            bool isFilterByGpuDriver = !string.IsNullOrEmpty(query.GpuDriver);

            for (int i = 0; i < data.Length; i++)
            {
                var  item      = data[i];
                bool isInclude = true;
                if (isInclude && isFilterByUser)
                {
                    isInclude = user.LoginName.Equals(item.LoginName);
                }
                if (isInclude && isFilterByGroup)
                {
                    isInclude = item.GroupId == query.GroupId.Value;
                }
                if (isInclude)
                {
                    switch (query.MineState)
                    {
                    case MineStatus.All:
                        break;

                    case MineStatus.Mining:
                        isInclude = item.IsMining == true;
                        break;

                    case MineStatus.UnMining:
                        isInclude = item.IsMining == false;
                        break;

                    default:
                        break;
                    }
                }
                if (isInclude && isFilterByMinerIp)
                {
                    isInclude = query.MinerIp.Equals(item.MinerIp) || (!string.IsNullOrEmpty(item.LocalIp) && item.LocalIp.Contains(query.MinerIp));
                }
                if (isInclude && isFilterByMinerName)
                {
                    isInclude = (!string.IsNullOrEmpty(item.MinerName) && item.MinerName.IndexOf(query.MinerName, StringComparison.OrdinalIgnoreCase) != -1) ||
                                (!string.IsNullOrEmpty(item.WorkerName) && item.WorkerName.IndexOf(query.MinerName, StringComparison.OrdinalIgnoreCase) != -1);
                }
                if (isInclude && isFilterByVersion)
                {
                    isInclude = !string.IsNullOrEmpty(item.Version) && item.Version.Contains(query.Version);
                }
                if (isInclude)
                {
                    if (isFilterByWork)
                    {
                        isInclude = item.WorkId == query.WorkId.Value;
                    }
                    else
                    {
                        if (isInclude && isFilterByCoin)
                        {
                            isInclude = query.Coin.Equals(item.MainCoinCode) || query.Coin.Equals(item.DualCoinCode);
                        }
                        if (isInclude && isFilterByPool)
                        {
                            isInclude = query.Pool.Equals(item.MainCoinPool) || query.Pool.Equals(item.DualCoinPool);
                        }
                        if (isInclude && isFilterByWallet)
                        {
                            isInclude = query.Wallet.Equals(item.MainCoinWallet) || query.Wallet.Equals(item.DualCoinWallet);
                        }
                        if (isInclude && isFilterByKernel)
                        {
                            isInclude = !string.IsNullOrEmpty(item.Kernel) && item.Kernel.IgnoreCaseContains(query.Kernel);
                        }
                    }
                }
                if (isInclude && isFilterByGpuType)
                {
                    isInclude = item.GpuType == query.GpuType;
                }
                if (isInclude && isFilterByGpuName)
                {
                    isInclude = !string.IsNullOrEmpty(item.GpuInfo) && item.GpuInfo.IgnoreCaseContains(query.GpuName);
                }
                if (isInclude && isFilterByGpuDriver)
                {
                    isInclude = !string.IsNullOrEmpty(item.GpuDriver) && item.GpuDriver.IgnoreCaseContains(query.GpuDriver);
                }
                if (isInclude)
                {
                    list.Add(item);
                }
            }
            total = list.Count();
            switch (query.SortDirection)
            {
            case SortDirection.Ascending:
                list = list.OrderBy(a => a.MinerName).ToList();
                break;

            case SortDirection.Descending:
                list = list.OrderByDescending(a => a.MinerName).ToList();
                break;

            default:
                break;
            }
            coinSnapshots = VirtualRoot.CreateCoinSnapshots(_isPull, DateTime.Now, list, out onlineCount, out miningCount).ToList();
            var results = list.Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToList();

            DoCheckIsOnline(results);
            return(results);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user">传null表示是内网群控调用</param>
        /// <param name="query"></param>
        /// <param name="total"></param>
        /// <param name="coinSnapshots"></param>
        /// <param name="onlineCount"></param>
        /// <param name="miningCount"></param>
        /// <returns></returns>
        public List <ClientData> QueryClients(
            IUser user,
            QueryClientsRequest query,
            out int total,
            out CoinSnapshotData[] coinSnapshots,
            out int onlineCount,
            out int miningCount)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            coinSnapshots = new CoinSnapshotData[0];
            onlineCount   = 0;
            miningCount   = 0;
            if (!IsReadied || query == null)
            {
                total = 0;
                return(new List <ClientData>());
            }
            List <ClientData> list = new List <ClientData>();

            ClientData[] data       = null;
            bool         isIntranet = user == null;

            if (isIntranet)
            {
                data = _dicByObjectId.Values.ToArray();
            }
            else if (user.IsAdmin())
            {
                data = _dicByObjectId.Values.ToArray();
            }
            else
            {
                string loginName = user.LoginName;
                if (string.IsNullOrEmpty(loginName))
                {
                    total = 0;
                    return(new List <ClientData>());
                }
                if (!_clientDatasByLoginName.TryGetValue(loginName, out ClientDatas clientDatas))
                {
                    clientDatas = new ClientDatas(loginName, _dicByObjectId.Values.Where(a => a.LoginName == loginName).ToList());
                    _clientDatasByLoginName[loginName] = clientDatas;
                }
                data = clientDatas.Datas;
            }
            bool isFilterByGroup     = query.GroupId.HasValue && query.GroupId.Value != Guid.Empty;
            bool isFilterByMinerIp   = !string.IsNullOrEmpty(query.MinerIp);
            bool isFilterByMinerName = !string.IsNullOrEmpty(query.MinerName);
            bool isFilterByVersion   = !string.IsNullOrEmpty(query.Version);
            bool isFilterByWork      = query.WorkId.HasValue && query.WorkId.Value != Guid.Empty;
            bool isFilterByCoin      = !isFilterByWork && !string.IsNullOrEmpty(query.Coin);
            bool isFilterByPool      = !isFilterByWork && !string.IsNullOrEmpty(query.Pool);
            bool isFilterByWallet    = !isFilterByWork && !string.IsNullOrEmpty(query.Wallet);
            bool isFilterByKernel    = !isFilterByWork && !string.IsNullOrEmpty(query.Kernel);
            bool isFilterByGpuType   = query.GpuType != GpuType.Empty;
            bool isFilterByGpuName   = !string.IsNullOrEmpty(query.GpuName);
            bool isFilterByGpuDriver = !string.IsNullOrEmpty(query.GpuDriver);

            for (int i = 0; i < data.Length; i++)
            {
                var  item      = data[i];
                bool isInclude = true;
                if (isInclude && isFilterByGroup)
                {
                    isInclude = item.GroupId == query.GroupId.Value;
                }
                if (isInclude)
                {
                    switch (query.MineState)
                    {
                    case MineStatus.All:
                        break;

                    case MineStatus.Mining:
                        isInclude = item.IsMining == true;
                        break;

                    case MineStatus.UnMining:
                        isInclude = item.IsMining == false;
                        break;

                    default:
                        break;
                    }
                }
                if (isInclude && isFilterByMinerIp)
                {
                    isInclude = !string.IsNullOrEmpty(item.LocalIp) && item.LocalIp.Contains(query.MinerIp);
                    if (!isInclude)
                    {
                        if (query.MinerIp.IndexOf(':') != -1)
                        {
                            isInclude = query.MinerIp.Equals(item.MinerIp);
                        }
                        else if (!string.IsNullOrEmpty(item.MinerIp))
                        {
                            // MinerIp可能带有端口号
                            int    index   = item.MinerIp.IndexOf(':');
                            string minerIp = item.MinerIp;
                            if (index != -1)
                            {
                                minerIp = minerIp.Substring(0, index);
                            }
                            isInclude = query.MinerIp.Equals(minerIp);
                        }
                    }
                }
                if (isInclude && isFilterByMinerName)
                {
                    isInclude = (!string.IsNullOrEmpty(item.MinerName) && item.MinerName.IndexOf(query.MinerName, StringComparison.OrdinalIgnoreCase) != -1) ||
                                (!string.IsNullOrEmpty(item.WorkerName) && item.WorkerName.IndexOf(query.MinerName, StringComparison.OrdinalIgnoreCase) != -1);
                }
                if (isInclude && isFilterByVersion)
                {
                    isInclude = !string.IsNullOrEmpty(item.Version) && item.Version.Contains(query.Version);
                }
                if (isInclude)
                {
                    if (isFilterByWork)
                    {
                        isInclude = item.WorkId == query.WorkId.Value;
                    }
                    else
                    {
                        if (isInclude && isFilterByCoin)
                        {
                            isInclude = query.Coin.Equals(item.MainCoinCode) || query.Coin.Equals(item.DualCoinCode);
                        }
                        if (isInclude && isFilterByPool)
                        {
                            isInclude = query.Pool.Equals(item.MainCoinPool) || query.Pool.Equals(item.DualCoinPool);
                        }
                        if (isInclude && isFilterByWallet)
                        {
                            isInclude = query.Wallet.Equals(item.MainCoinWallet) || query.Wallet.Equals(item.DualCoinWallet);
                        }
                        if (isInclude && isFilterByKernel)
                        {
                            isInclude = !string.IsNullOrEmpty(item.Kernel) && item.Kernel.IgnoreCaseContains(query.Kernel);
                        }
                    }
                }
                if (isInclude && isFilterByGpuType)
                {
                    isInclude = item.GpuType == query.GpuType;
                }
                if (isInclude && isFilterByGpuName)
                {
                    isInclude = !string.IsNullOrEmpty(item.GpuInfo) && item.GpuInfo.IgnoreCaseContains(query.GpuName);
                }
                if (isInclude && isFilterByGpuDriver)
                {
                    isInclude = !string.IsNullOrEmpty(item.GpuDriver) && item.GpuDriver.IgnoreCaseContains(query.GpuDriver);
                }
                if (isInclude)
                {
                    list.Add(item);
                }
            }
            total = list.Count();
            list.Sort(new ClientDataComparer(query.SortDirection, query.SortField));
            coinSnapshots = VirtualRoot.CreateCoinSnapshots(_isPull, DateTime.Now, data, out onlineCount, out miningCount).ToArray();
            var      results = list.Take(query).ToList();
            DateTime time    = DateTime.Now.AddSeconds(_isPull ? -20 : -180);

            // 一定时间未上报算力视为0算力
            foreach (var clientData in results)
            {
                if (clientData.MinerActiveOn < time)
                {
                    clientData.DualCoinSpeed = 0;
                    clientData.MainCoinSpeed = 0;
                }
            }
            stopwatch.Stop();
            _queryClientsMilliseconds.Enqueue(stopwatch.ElapsedMilliseconds);
            while (_queryClientsMilliseconds.Count > 100)
            {
                _queryClientsMilliseconds.Dequeue();
            }
            return(results);
        }
예제 #4
0
        public List <ClientData> QueryClients(
            IUser user,
            QueryClientsRequest query,
            out int total,
            out List <CoinSnapshotData> coinSnapshots,
            out int onlineCount,
            out int miningCount)
        {
            coinSnapshots = new List <CoinSnapshotData>();
            onlineCount   = 0;
            miningCount   = 0;
            if (!IsReadied)
            {
                total = 0;
                return(new List <ClientData>());
            }
            List <ClientData> list = new List <ClientData>();
            var  data                = _dicByObjectId.Values.ToArray();
            bool isFilterByUser      = user != null && !string.IsNullOrEmpty(user.LoginName) && !user.IsAdmin();
            bool isFilterByGroup     = query.GroupId.HasValue && query.GroupId.Value != Guid.Empty;
            bool isFilterByMinerIp   = !string.IsNullOrEmpty(query.MinerIp);
            bool isFilterByMinerName = !string.IsNullOrEmpty(query.MinerName);
            bool isFilterByVersion   = !string.IsNullOrEmpty(query.Version);
            bool isFilterByWork      = query.WorkId.HasValue && query.WorkId.Value != Guid.Empty;
            bool isFilterByCoin      = !isFilterByWork && !string.IsNullOrEmpty(query.Coin);
            bool isFilterByPool      = !isFilterByWork && !string.IsNullOrEmpty(query.Pool);
            bool isFilterByWallet    = !isFilterByWork && !string.IsNullOrEmpty(query.Wallet);
            bool isFilterByKernel    = !isFilterByWork && !string.IsNullOrEmpty(query.Kernel);
            bool isFilterByGpuType   = query.GpuType != GpuType.Empty;
            bool isFilterByGpuName   = !string.IsNullOrEmpty(query.GpuName);
            bool isFilterByGpuDriver = !string.IsNullOrEmpty(query.GpuDriver);

            for (int i = 0; i < data.Length; i++)
            {
                var  item      = data[i];
                bool isInclude = true;
                if (isInclude && isFilterByUser)
                {
                    isInclude = user.LoginName.Equals(item.LoginName);
                }
                if (isInclude && isFilterByGroup)
                {
                    isInclude = item.GroupId == query.GroupId.Value;
                }
                if (isInclude)
                {
                    switch (query.MineState)
                    {
                    case MineStatus.All:
                        break;

                    case MineStatus.Mining:
                        isInclude = item.IsMining == true;
                        break;

                    case MineStatus.UnMining:
                        isInclude = item.IsMining == false;
                        break;

                    default:
                        break;
                    }
                }
                if (isInclude && isFilterByMinerIp)
                {
                    isInclude = query.MinerIp.Equals(item.MinerIp) || (!string.IsNullOrEmpty(item.LocalIp) && item.LocalIp.Contains(query.MinerIp));
                }
                if (isInclude && isFilterByMinerName)
                {
                    isInclude = (!string.IsNullOrEmpty(item.MinerName) && item.MinerName.IndexOf(query.MinerName, StringComparison.OrdinalIgnoreCase) != -1) ||
                                (!string.IsNullOrEmpty(item.WorkerName) && item.WorkerName.IndexOf(query.MinerName, StringComparison.OrdinalIgnoreCase) != -1);
                }
                if (isInclude && isFilterByVersion)
                {
                    isInclude = !string.IsNullOrEmpty(item.Version) && item.Version.Contains(query.Version);
                }
                if (isInclude)
                {
                    if (isFilterByWork)
                    {
                        isInclude = item.WorkId == query.WorkId.Value;
                    }
                    else
                    {
                        if (isInclude && isFilterByCoin)
                        {
                            isInclude = query.Coin.Equals(item.MainCoinCode) || query.Coin.Equals(item.DualCoinCode);
                        }
                        if (isInclude && isFilterByPool)
                        {
                            isInclude = query.Pool.Equals(item.MainCoinPool) || query.Pool.Equals(item.DualCoinPool);
                        }
                        if (isInclude && isFilterByWallet)
                        {
                            isInclude = query.Wallet.Equals(item.MainCoinWallet) || query.Wallet.Equals(item.DualCoinWallet);
                        }
                        if (isInclude && isFilterByKernel)
                        {
                            isInclude = !string.IsNullOrEmpty(item.Kernel) && item.Kernel.IgnoreCaseContains(query.Kernel);
                        }
                    }
                }
                if (isInclude && isFilterByGpuType)
                {
                    isInclude = item.GpuType == query.GpuType;
                }
                if (isInclude && isFilterByGpuName)
                {
                    isInclude = !string.IsNullOrEmpty(item.GpuInfo) && item.GpuInfo.IgnoreCaseContains(query.GpuName);
                }
                if (isInclude && isFilterByGpuDriver)
                {
                    isInclude = !string.IsNullOrEmpty(item.GpuDriver) && item.GpuDriver.IgnoreCaseContains(query.GpuDriver);
                }
                if (isInclude)
                {
                    list.Add(item);
                }
            }
            total = list.Count();
            list.Sort(new ClientDataComparer(query.SortDirection, query.SortField));
            ClientData[] items = (user == null || user.IsAdmin()) ? data : data.Where(a => a.LoginName == user.LoginName).ToArray();
            coinSnapshots = VirtualRoot.CreateCoinSnapshots(_isPull, DateTime.Now, items, out onlineCount, out miningCount).ToList();
            var      results = list.Take(query).ToList();
            DateTime time    = DateTime.Now.AddSeconds(_isPull ? -20 : -180);

            // 一定时间未上报算力视为0算力
            foreach (var clientData in results)
            {
                if (clientData.MinerActiveOn < time)
                {
                    clientData.DualCoinSpeed = 0;
                    clientData.MainCoinSpeed = 0;
                }
            }
            return(results);
        }