示例#1
0
        protected async Task <APIData> GetSummaryCPUAsync(string method = "", bool overrideLoop = false)
        {
            APIData ad = new APIData(MiningSetup.CurrentAlgorithmType);

            try {
                _currentMinerReadStatus = MinerAPIReadStatus.WAIT;
                string dataToSend = GetHttpRequestNHMAgentStrin(method);
                string respStr    = await GetAPIDataAsync(APIPort, dataToSend);

                if (String.IsNullOrEmpty(respStr))
                {
                    _currentMinerReadStatus = MinerAPIReadStatus.NETWORK_EXCEPTION;
                    throw new Exception("Response is empty!");
                }
                if (respStr.IndexOf("HTTP/1.1 200 OK") > -1)
                {
                    respStr = respStr.Substring(respStr.IndexOf(HTTPHeaderDelimiter) + HTTPHeaderDelimiter.Length);
                }
                else
                {
                    throw new Exception("Response not HTTP formed! " + respStr);
                }

                dynamic resp = JsonConvert.DeserializeObject(respStr);

                if (resp != null)
                {
                    JArray totals = resp.hashrate.total;
                    foreach (var total in totals)
                    {
                        if (total.Value <string>() == null)
                        {
                            continue;
                        }
                        ad.Speed = total.Value <double>();
                        break;
                    }
                    if (ad.Speed == 0)
                    {
                        _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
                    }
                    else
                    {
                        _currentMinerReadStatus = MinerAPIReadStatus.GOT_READ;
                    }
                }
                else
                {
                    throw new Exception($"Response does not contain speed data: {respStr.Trim()}");
                }
            } catch (Exception ex) {
                Helpers.ConsolePrint(MinerTAG(), ex.Message);
            }

            return(ad);
        }
示例#2
0
        protected async Task <APIData> GetSummaryCPU_CCMINERAsync()
        {
            string resp;
            // TODO aname
            string  aname = null;
            APIData ad    = new APIData(MiningSetup.CurrentAlgorithmType);

            string DataToSend = GetHttpRequestNHMAgentStrin("summary");

            resp = await GetAPIDataAsync(APIPort, DataToSend);

            if (resp == null)
            {
                Helpers.ConsolePrint(MinerTAG(), ProcessTag() + " summary is null");
                _currentMinerReadStatus = MinerAPIReadStatus.NONE;
                return(null);
            }

            try {
                string[] resps = resp.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < resps.Length; i++)
                {
                    string[] optval = resps[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (optval.Length != 2)
                    {
                        continue;
                    }
                    if (optval[0] == "ALGO")
                    {
                        aname = optval[1];
                    }
                    else if (optval[0] == "KHS")
                    {
                        ad.Speed = double.Parse(optval[1], CultureInfo.InvariantCulture) * 1000; // HPS
                    }
                }
            } catch {
                Helpers.ConsolePrint(MinerTAG(), ProcessTag() + " Could not read data from API bind port");
                _currentMinerReadStatus = MinerAPIReadStatus.NONE;
                return(null);
            }

            _currentMinerReadStatus = MinerAPIReadStatus.GOT_READ;
            // check if speed zero
            if (ad.Speed == 0)
            {
                _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
            }

            return(ad);
        }
示例#3
0
        public void AddRateInfo(string groupName, string deviceStringInfo, APIData iAPIData, double paying, bool isApiGetException)
        {
            string ApiGetExceptionString = isApiGetException ? "**" : "";

            string speedString        = Helpers.FormatDualSpeedOutput(iAPIData.AlgorithmID, iAPIData.Speed, iAPIData.SecondarySpeed) + iAPIData.AlgorithmName + ApiGetExceptionString;
            string rateBTCString      = FormatPayingOutput(paying);
            string rateCurrencyString = ExchangeRateAPI.ConvertToActiveCurrency(paying * Globals.BitcoinUSDRate * factorTimeUnit).ToString("F2", CultureInfo.InvariantCulture)
                                        + String.Format(" {0}/", ExchangeRateAPI.ActiveDisplayCurrency) + International.GetText(ConfigManager.GeneralConfig.TimeUnit.ToString());

            try {  // flowLayoutPanelRatesIndex may be OOB, so catch
                ((GroupProfitControl)flowLayoutPanelRates.Controls[flowLayoutPanelRatesIndex++])
                .UpdateProfitStats(groupName, deviceStringInfo, speedString, rateBTCString, rateCurrencyString);
            } catch { }

            UpdateGlobalRate();
        }