Esempio n. 1
0
        private static void UpdateAsync()
        {
            Task.Factory.StartNew(() => {
                try {
                    byte[] htmlData = GetHtmlAsync("https://www.f2pool.com/").Result;
                    if (htmlData != null && htmlData.Length != 0)
                    {
                        Write.UserOk($"{DateTime.Now} - 鱼池首页html获取成功");
                        string html   = Encoding.UTF8.GetString(htmlData);
                        double usdCny = PickUsdCny(html);
                        Write.UserInfo($"usdCny={usdCny}");
                        List <IncomeItem> incomeItems = PickIncomeItems(html);
                        Write.UserInfo($"鱼池首页有{incomeItems.Count}个币种");
                        FillCny(incomeItems, usdCny);
                        NeatenSpeedUnit(incomeItems);
                        if (incomeItems != null && incomeItems.Count != 0)
                        {
                            Login();
                            OfficialServer.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.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);
                }
            });
        }
Esempio n. 2
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);
                }
            });
        }