Ejemplo n.º 1
0
        private static void UpdateAsync()
        {
            Task.Factory.StartNew(() => {
                try {
                    Task <byte[]> htmlDataTask = GetHtmlAsync("https://www.f2pool.com/");
                    byte[] htmlData            = null;
                    try {
                        Task.WaitAll(new Task[] { htmlDataTask }, 60 * 1000);
                        htmlData = htmlDataTask.Result;
                    }
                    catch {
                    }
                    if (htmlData != null && htmlData.Length != 0)
                    {
                        NTMinerConsole.UserOk($"{DateTime.Now.ToString()} - 鱼池首页html获取成功");
                        string html   = Encoding.UTF8.GetString(htmlData);
                        double usdCny = PickUsdCny(html);
                        NTMinerConsole.UserInfo($"usdCny={usdCny.ToString()}");
                        List <IncomeItem> incomeItems = PickIncomeItems(html);
                        NTMinerConsole.UserInfo($"鱼池首页有{incomeItems.Count.ToString()}个币种");
                        FillCny(incomeItems, usdCny);
                        NeatenSpeedUnit(incomeItems);
                        if (incomeItems != null && incomeItems.Count != 0)
                        {
                            RpcRoot.Login(new RpcUser(Config.RpcLoginName, HashUtil.Sha1(Config.RpcPassword)));
                            RpcRoot.SetIsOuterNet(false);
                            RpcRoot.OfficialServer.CalcConfigBinaryService.GetCalcConfigsAsync(data => {
                                NTMinerConsole.UserInfo($"NTMiner有{data.Count.ToString()}个币种");
                                HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                                foreach (CalcConfigData calcConfigData in data)
                                {
                                    IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase));
                                    if (incomeItem != null)
                                    {
                                        coinCodes.Add(calcConfigData.CoinCode);
                                        calcConfigData.Speed           = incomeItem.Speed;
                                        calcConfigData.SpeedUnit       = incomeItem.SpeedUnit;
                                        calcConfigData.NetSpeed        = incomeItem.NetSpeed;
                                        calcConfigData.NetSpeedUnit    = incomeItem.NetSpeedUnit;
                                        calcConfigData.IncomePerDay    = incomeItem.IncomeCoin;
                                        calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd;
                                        calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny;
                                        calcConfigData.ModifiedOn      = DateTime.Now;
                                        if (calcConfigData.ModifiedOn.AddMinutes(15) > calcConfigData.ModifiedOn.Date.AddDays(1))
                                        {
                                            calcConfigData.BaseNetSpeed     = calcConfigData.NetSpeed;
                                            calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit;
                                        }
                                        else if (calcConfigData.BaseNetSpeed != 0)
                                        {
                                            if (calcConfigData.NetSpeedUnit == calcConfigData.BaseNetSpeedUnit)
                                            {
                                                calcConfigData.DayWave = (calcConfigData.NetSpeed - calcConfigData.BaseNetSpeed) / calcConfigData.BaseNetSpeed;
                                            }
                                            else
                                            {
                                                if (string.IsNullOrEmpty(calcConfigData.BaseNetSpeedUnit))
                                                {
                                                    calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit;
                                                }
                                                var netSpeed           = calcConfigData.NetSpeed.FromUnitSpeed(calcConfigData.NetSpeedUnit);
                                                var baseNetSpeed       = calcConfigData.BaseNetSpeed.FromUnitSpeed(calcConfigData.BaseNetSpeedUnit);
                                                calcConfigData.DayWave = (netSpeed - baseNetSpeed) / baseNetSpeed;
                                            }
                                        }
                                    }
                                }
                                RpcRoot.OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => {
                                    if (!res.IsSuccess())
                                    {
                                        VirtualRoot.Out.ShowError(res.ReadMessage(e), autoHideSeconds: 4);
                                    }
                                });
                                foreach (IncomeItem incomeItem in incomeItems)
                                {
                                    if (coinCodes.Contains(incomeItem.CoinCode))
                                    {
                                        continue;
                                    }
                                    NTMinerConsole.UserInfo(incomeItem.ToString());
                                }

                                foreach (var incomeItem in incomeItems)
                                {
                                    if (!coinCodes.Contains(incomeItem.CoinCode))
                                    {
                                        continue;
                                    }
                                    NTMinerConsole.UserOk(incomeItem.ToString());
                                }

                                NTMinerConsole.UserOk($"更新了{coinCodes.Count.ToString()}个币种:{string.Join(",", coinCodes)}");
                                int unUpdatedCount = data.Count - coinCodes.Count;
                                NTMinerConsole.UserWarn($"{unUpdatedCount.ToString()}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}");
                            });
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
            });
        }
Ejemplo n.º 2
0
        private static void UpdateAsync()
        {
            Task.Factory.StartNew(() => {
                try {
                    var vdsUUDataTask = GetHtmlAsync("https://uupool.cn/api/getAllInfo.php");
                    var vdsZtDataTask = GetHtmlAsync("https://www.zt.com/api/v1/symbol");
                    var htmlDataTask  = GetHtmlAsync("https://www.f2pool.com/");
                    byte[] htmlData   = null;
                    byte[] vdsUUData  = null;
                    byte[] vdsZtData  = null;
                    try {
                        Task.WaitAll(new Task[] { vdsUUDataTask, vdsZtDataTask, htmlDataTask }, 30 * 1000);
                        htmlData  = htmlDataTask.Result;
                        vdsUUData = vdsUUDataTask.Result;
                        vdsZtData = vdsZtDataTask.Result;
                    }
                    catch {
                    }
                    if (htmlData != null && htmlData.Length != 0)
                    {
                        Write.UserOk($"{DateTime.Now} - 鱼池首页html获取成功");
                        string html      = Encoding.UTF8.GetString(htmlData);
                        string vdsUUHtml = string.Empty;
                        string vdsZtHtml = string.Empty;
                        if (vdsUUData != null && vdsUUData.Length != 0)
                        {
                            vdsUUHtml = Encoding.UTF8.GetString(vdsUUData);
                        }
                        if (vdsZtData != null && vdsZtData.Length != 0)
                        {
                            vdsZtHtml = Encoding.UTF8.GetString(vdsZtData);
                        }
                        double usdCny = PickUsdCny(html);
                        Write.UserInfo($"usdCny={usdCny}");
                        List <IncomeItem> incomeItems = PickIncomeItems(html);
                        IncomeItem vdsIncomeItem      = PickVDSIncomeItem(vdsUUHtml, vdsZtHtml, usdCny);
                        if (vdsIncomeItem != null && incomeItems.All(a => a.CoinCode != "VDS"))
                        {
                            incomeItems.Add(vdsIncomeItem);
                        }
                        Write.UserInfo($"鱼池首页有{incomeItems.Count}个币种");
                        FillCny(incomeItems, usdCny);
                        NeatenSpeedUnit(incomeItems);
                        if (incomeItems != null && incomeItems.Count != 0)
                        {
                            Login();
                            OfficialServer.CalcConfigService.GetCalcConfigsAsync(data => {
                                Write.UserInfo($"NTMiner有{data.Count}个币种");
                                HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                                foreach (CalcConfigData calcConfigData in data)
                                {
                                    IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase));
                                    if (incomeItem != null)
                                    {
                                        coinCodes.Add(calcConfigData.CoinCode);
                                        calcConfigData.Speed           = incomeItem.Speed;
                                        calcConfigData.SpeedUnit       = incomeItem.SpeedUnit;
                                        calcConfigData.IncomePerDay    = incomeItem.IncomeCoin;
                                        calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd;
                                        calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny;
                                        calcConfigData.ModifiedOn      = DateTime.Now;
                                    }
                                }
                                OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => {
                                    if (!res.IsSuccess())
                                    {
                                        Write.UserFail(res.ReadMessage(e));
                                    }
                                });
                                foreach (IncomeItem incomeItem in incomeItems)
                                {
                                    if (coinCodes.Contains(incomeItem.CoinCode))
                                    {
                                        continue;
                                    }
                                    Write.UserInfo(incomeItem.ToString());
                                }

                                foreach (var incomeItem in incomeItems)
                                {
                                    if (!coinCodes.Contains(incomeItem.CoinCode))
                                    {
                                        continue;
                                    }
                                    Write.UserOk(incomeItem.ToString());
                                }

                                Write.UserOk($"更新了{coinCodes.Count}个币种:{string.Join(",", coinCodes)}");
                                int unUpdatedCount = data.Count - coinCodes.Count;
                                Write.UserWarn($"{unUpdatedCount}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}");
                            });
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
            });
        }
Ejemplo n.º 3
0
        private static void UpdateAsync()
        {
            Task.Factory.StartNew(() => {
                try {
                    byte[] htmlData = GetHtmlAsync("https://www.f2pool.com/").Result;
                    if (htmlData != null && htmlData.Length != 0)
                    {
                        Console.WriteLine($"{DateTime.Now} - 鱼池首页html获取成功");
                        string html   = Encoding.UTF8.GetString(htmlData);
                        double usdCny = PickUsdCny(html);
                        Console.WriteLine($"usdCny={usdCny}");
                        List <IncomeItem> incomeItems = PickIncomeItems(html);
                        Console.WriteLine($"鱼池首页有{incomeItems.Count}个币种");
                        FillCny(incomeItems, usdCny);
                        NeatenSpeedUnit(incomeItems);
                        if (incomeItems != null && incomeItems.Count != 0)
                        {
                            Login();
                            DataResponse <List <CalcConfigData> > response = OfficialServer.GetCalcConfigs();
                            Console.WriteLine($"NTMiner有{response.Data.Count}个币种");
                            HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                            foreach (CalcConfigData calcConfigData in response.Data)
                            {
                                IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase));
                                if (incomeItem != null)
                                {
                                    coinCodes.Add(calcConfigData.CoinCode);
                                    calcConfigData.Speed           = incomeItem.Speed;
                                    calcConfigData.SpeedUnit       = incomeItem.SpeedUnit;
                                    calcConfigData.IncomePerDay    = incomeItem.IncomeCoin;
                                    calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd;
                                    calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny;
                                    calcConfigData.ModifiedOn      = DateTime.Now;
                                }
                            }
                            OfficialServer.SaveCalcConfigsAsync(response.Data, null);
                            foreach (IncomeItem incomeItem in incomeItems)
                            {
                                if (coinCodes.Contains(incomeItem.CoinCode))
                                {
                                    continue;
                                }
                                Console.WriteLine(incomeItem.ToString());
                            }

                            Console.ForegroundColor = ConsoleColor.Green;
                            foreach (var incomeItem in incomeItems)
                            {
                                if (!coinCodes.Contains(incomeItem.CoinCode))
                                {
                                    continue;
                                }
                                Console.WriteLine(incomeItem.ToString());
                            }
                            Console.ResetColor();

                            Console.WriteLine($"更新了{coinCodes.Count}个币种:{string.Join(",", coinCodes)}");
                            int unUpdatedCount = response.Data.Count - coinCodes.Count;
                            Console.WriteLine($"{unUpdatedCount}个币种未更新{(unUpdatedCount == 0 ? string.Empty: ":" + string.Join(",", response.Data.Select(a => a.CoinCode).Except(coinCodes)))}");
                        }
                    }
                }
                catch (Exception e) {
                    PrintError(e);
                }
            });
        }