public async Task <PoolStat> GetPoolStat() { PoolStat poolStat = null; var path = string.Format("miner/{0}/currentStats", miner); try { using (HttpResponseMessage response = await client.GetAsync(path)) { if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); poolStat = JsonConvert.DeserializeObject <PoolStat>(json); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(poolStat); }
public MinerStatus GetMinerStatus(PoolStat poolStat) { if (poolStat.Status != "OK") { return(MinerStatus.InternalServerError); } else { if (poolStat.Data.ReportedHashrate < poolStat.Data.AverageHashrate) { return(MinerStatus.PowerDecreasing); } if (poolStat.Data.CurrentHashrate == 0 || poolStat.Data.ActiveWorkers == 0) { return(MinerStatus.Idling); } if (!poolStat.Data.CurrentHashrate.HasValue || !poolStat.Data.ActiveWorkers.HasValue) { return(MinerStatus.Idling); } return(MinerStatus.Working); } }
public void NotifyMinerObserver(Message message, MinerStatus status = MinerStatus.Working, PoolStat poolStat = null) { switch (status) { case MinerStatus.Idling: { var text = string.Format("No worker detected! Please check your environment...\n-current hashrate: {0:0.00}\n-active workers: {1}", poolStat.Data.CurrentHashrate, poolStat.Data.ActiveWorkers); telegramBotClient.SendTextMessageAsync(message.Chat.Id, text); break; } case MinerStatus.PowerDecreasing: { var text = string.Format("Power decreasing, please check your environment...\n-current hashrate: {0:0.00}\n-active workers: {1}", poolStat.Data.CurrentHashrate, poolStat.Data.ActiveWorkers); telegramBotClient.SendTextMessageAsync(message.Chat.Id, text); break; } case MinerStatus.InternalServerError: { telegramBotClient.SendTextMessageAsync(message.Chat.Id, "No reply from flypool! Please check your environment and pool..."); break; } case MinerStatus.WrongToken: { telegramBotClient.SendTextMessageAsync(message.Chat.Id, "Please, provide valid token..."); break; } default: { break; } } }