示例#1
0
        public override APIData GetSummary()
        {
            _currentMinerReadStatus = MinerAPIReadStatus.NONE;
            APIData ad = new APIData(MiningSetup.CurrentAlgorithmType);

            TcpClient       client = null;
            JsonApiResponse resp   = null;

            try {
                byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes("status\n");
                client = new TcpClient("127.0.0.1", APIPort);
                NetworkStream nwStream = client.GetStream();
                nwStream.Write(bytesToSend, 0, bytesToSend.Length);
                byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                int    bytesRead   = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
                string respStr     = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                client.Close();
            } catch (Exception ex) {
                Helpers.ConsolePrint("ERROR", ex.Message);
            }

            if (resp != null && resp.error == null)
            {
                ad.Speed = resp.result.speed_sps;
                _currentMinerReadStatus = MinerAPIReadStatus.GOT_READ;
                if (ad.Speed == 0)
                {
                    _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
                }
            }

            return(ad);
        }
        public override async Task<ApiData> GetSummaryAsync()
        {
            CurrentMinerReadStatus = MinerApiReadStatus.NONE;
            var ad = new ApiData(MiningSetup.CurrentAlgorithmType);

            JsonApiResponse resp = null;
            try
            {
                var bytesToSend = Encoding.ASCII.GetBytes("status\n");
                var client = new TcpClient("127.0.0.1", ApiPort);
                var nwStream = client.GetStream();
                await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);
                var bytesToRead = new byte[client.ReceiveBufferSize];
                var bytesRead = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);
                var respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                resp = JsonConvert.DeserializeObject<JsonApiResponse>(respStr, Globals.JsonSettings);
                client.Close();
            }
            catch (Exception ex)
            {
                Helpers.ConsolePrint("ERROR", ex.Message);
            }

            if (resp != null && resp.error == null)
            {
                ad.Speed = resp.result.speed_sps;
                CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                if (ad.Speed == 0)
                {
                    CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                }
            }

            return ad;
        }
示例#3
0
        public override async Task <APIData> GetSummaryAsync()
        {
            _currentMinerReadStatus = MinerAPIReadStatus.NONE;
            APIData         ad     = new APIData(MiningSetup.CurrentAlgorithmType);
            TcpClient       client = null;
            JsonApiResponse resp   = null;

            try {
                byte[] bytesToSend = Encoding.ASCII.GetBytes("{\"method\":\"getstat\"}\n");
                client = new TcpClient("127.0.0.1", APIPort);
                NetworkStream nwStream = client.GetStream();
                await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);

                byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                int    bytesRead   = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);

                string respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                client.Close();
            } catch (Exception ex) {
                Helpers.ConsolePrint(MinerTAG(), ex.Message);
            }

            if (resp != null && resp.error == null)
            {
                ad.Speed = resp.result.Aggregate <Result, uint>(0, (current, t1) => current + t1.speed_sps);
                _currentMinerReadStatus = MinerAPIReadStatus.GOT_READ;
                if (ad.Speed == 0)
                {
                    _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
                }
            }

            return(ad);
        }
示例#4
0
        public override async Task <ApiData> GetSummaryAsync()
        {
            CurrentMinerReadStatus = MinerApiReadStatus.NONE;
            var ad             = new ApiData(MiningSetup.CurrentAlgorithmType);
            var elapsedSeconds = DateTime.Now.Subtract(_started).Seconds;

            // if (elapsedSeconds < 15 && firstStart)
            if (firstStart)
            //          if (ad.Speed <= 0.0001)
            {
                Thread.Sleep(3000);
                ad.Speed   = 1;
                firstStart = false;
                return(ad);
            }

            JsonApiResponse resp = null;

            try
            {
                var bytesToSend = Encoding.ASCII.GetBytes(variables.miniZ_toSend);
                var client      = new TcpClient("127.0.0.1", ApiPort);
                var nwStream    = client.GetStream();
                await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);

                var bytesToRead = new byte[client.ReceiveBufferSize];
                var bytesRead   = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);

                var respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
//                Helpers.ConsolePrint("miniZ API:", respStr);
                if (!respStr.Contains("speed_sps") && prevSpeed != 0)
                {
                    client.Close();
                    CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                    ad.Speed = prevSpeed;
                    return(ad);
                }
                resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                client.Close();
            }
            catch (Exception ex)
            {
                Helpers.ConsolePrint(MinerTag(), ex.Message);
                CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                ad.Speed = prevSpeed;
            }

            if (resp != null && resp.error == null)
            {
                ad.Speed  = resp.result.Aggregate <Result, double>(0, (current, t1) => current + t1.speed_sps);
                prevSpeed = ad.Speed;
                CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                if (ad.Speed == 0)
                {
                    CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                }
            }

            return(ad);
        }
示例#5
0
        public override APIData GetSummary()
        {
            _currentMinerReadStatus = MinerAPIReadStatus.NONE;
            APIData ad = new APIData(MiningSetup.CurrentAlgorithmType);

            TcpClient       client = null;
            JsonApiResponse resp   = null;

            try {
                byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes("{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"miner_getstat1\"}n");
                client = new TcpClient("127.0.0.1", APIPort);
                NetworkStream nwStream = client.GetStream();
                nwStream.Write(bytesToSend, 0, bytesToSend.Length);
                byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                int    bytesRead   = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
                string respStr     = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                client.Close();
                //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", respStr);
            } catch (Exception ex) {
                Helpers.ConsolePrint(this.MinerTAG(), "GetSummary exception: " + ex.Message);
            }

            if (resp != null && resp.error == null)
            {
                //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "resp != null && resp.error == null");
                if (resp.result != null && resp.result.Count > 4)
                {
                    //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "resp.result != null && resp.result.Count > 4");
                    var speeds = resp.result[3].Split(';');
                    ad.Speed = 0;
                    foreach (var speed in speeds)
                    {
                        //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "foreach (var speed in speeds) {");
                        double tmpSpeed = 0;
                        try {
                            tmpSpeed = Double.Parse(speed, CultureInfo.InvariantCulture);
                        } catch {
                            tmpSpeed = 0;
                        }
                        ad.Speed += tmpSpeed;
                    }
                    ad.Speed *= api_read_mult;
                    _currentMinerReadStatus = MinerAPIReadStatus.GOT_READ;
                }
                if (ad.Speed == 0)
                {
                    _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
                }
                // some clayomre miners have this issue reporting negative speeds in that case restart miner
                if (ad.Speed < 0)
                {
                    Helpers.ConsolePrint(this.MinerTAG(), "Reporting negative speeds will restart...");
                    this.Restart();
                }
            }

            return(ad);
        }
示例#6
0
        public override async Task <ApiData> GetSummaryAsync()
        {
            CurrentMinerReadStatus = MinerApiReadStatus.NONE;
            var ad = new ApiData(MiningSetup.CurrentAlgorithmType);

            if (_skipApiCheck == false)
            {
                JsonApiResponse resp = null;
                try
                {
                    var dataToSend = GetHttpRequestNhmAgentStrin("");
                    var respStr    = await GetApiDataAsync(ApiPort, dataToSend, true);

                    if (respStr != null && respStr.Contains("{"))
                    {
                        var start = respStr.IndexOf("{");
                        if (start > -1)
                        {
                            var respStrJson = respStr.Substring(start);
                            resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStrJson.Trim(),
                                                                                   Globals.JsonSettings);
                        }
                    }
                    //Helpers.ConsolePrint("OptiminerZcashMiner API back:", respStr);
                }
                catch (Exception ex)
                {
                    Helpers.ConsolePrint("OptiminerZcashMiner", "GetSummary exception: " + ex.Message);
                }

                if (resp?.solution_rate != null)
                {
                    //Helpers.ConsolePrint("OptiminerZcashMiner API back:", "resp != null && resp.error == null");
                    const string totalKey = "Total";
                    const string _5SKey   = "5s";
                    if (resp.solution_rate.ContainsKey(totalKey))
                    {
                        var totalSolutionRateDict = resp.solution_rate[totalKey];
                        if (totalSolutionRateDict != null && totalSolutionRateDict.ContainsKey(_5SKey))
                        {
                            ad.Speed = totalSolutionRateDict[_5SKey];
                            CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                        }
                    }
                    if (ad.Speed == 0)
                    {
                        CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                    }
                }
            }
            else if (_skipApiCheck && _startApi.Elapsed.TotalSeconds > _waitSeconds)
            {
                _startApi.Stop();
                _skipApiCheck = false;
            }

            return(ad);
        }
        public override APIData GetSummary()
        {
            _currentMinerReadStatus = MinerAPIReadStatus.NONE;
            APIData ad = new APIData(MiningSetup.CurrentAlgorithmType);

            if (_skipAPICheck == false)
            {
                JsonApiResponse resp = null;
                try {
                    string DataToSend = GetHttpRequestNHMAgentStrin("");
                    string respStr    = GetAPIData(APIPort, DataToSend, true);
                    if (respStr != null && respStr.Contains("{"))
                    {
                        int start = respStr.IndexOf("{");
                        if (start > -1)
                        {
                            string respStrJSON = respStr.Substring(start);
                            resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStrJSON.Trim(), Globals.JsonSettings);
                        }
                    }
                    //Helpers.ConsolePrint("OptiminerZcashMiner API back:", respStr);
                } catch (Exception ex) {
                    Helpers.ConsolePrint("OptiminerZcashMiner", "GetSummary exception: " + ex.Message);
                }

                if (resp != null && resp.solution_rate != null)
                {
                    //Helpers.ConsolePrint("OptiminerZcashMiner API back:", "resp != null && resp.error == null");
                    const string total_key = "Total";
                    const string _5s_key   = "5s";
                    if (resp.solution_rate.ContainsKey(total_key))
                    {
                        var total_solution_rate_dict = resp.solution_rate[total_key];
                        if (total_solution_rate_dict != null && total_solution_rate_dict.ContainsKey(_5s_key))
                        {
                            ad.Speed = total_solution_rate_dict[_5s_key];
                            _currentMinerReadStatus = MinerAPIReadStatus.GOT_READ;
                        }
                    }
                    if (ad.Speed == 0)
                    {
                        _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
                    }
                }
            }
            else if (_skipAPICheck && _startAPI.Elapsed.TotalSeconds > waitSeconds)
            {
                _startAPI.Stop();
                _skipAPICheck = false;
            }

            return(ad);
        }
        internal static List <Hub> HandleGetHubsResponse(IRestResponse response)
        {
            List <Hub> hubs = null;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                JsonApiResponse <List <Hub> > result = JsonConvert.DeserializeObject <JsonApiResponse <List <Hub> > >(response.Content, settings);
                hubs = result.data;
            }
            return(hubs);
        }
示例#9
0
        //[ProducesResponseType(typeof(JsonApiResponse<List<ViewMeeting>>), StatusCodes.Status200OK)]
        public async Task <IActionResult> Get([FromBody][AllowNull] JsonApiRequest <MeetingGetParams> request)
        {
            var result = await _manager.GetAsync(request.RequestParams);

            var model = new JsonApiResponse <List <ViewMeeting> >
            {
                Errors   = null,
                Response = result.Select(x => _mapper.Map <ViewMeeting>(x)).ToList()
            };
            await _context.Clients.All.SendAsync("GetResponse", model.Response);

            return(Ok(model));
        }
示例#10
0
        public async Task <IActionResult> Login([AllowNull][FromBody] ViewUser user)
        {
            var loginResult = await ValidateAndLogin(user);

            var model = new JsonApiResponse <bool>
            {
                Response = loginResult
            };

            if (loginResult)
            {
                return(Ok(model));
            }
            return(Unauthorized(model));
        }
示例#11
0
        public async Task <IActionResult> Register([AllowNull][FromBody] ViewUserRegister user)
        {
            var dbUser         = _mapper.Map <UserRegister>(user);
            var registerStatus = await _authorizer.Register(dbUser);

            var model = new JsonApiResponse <bool>
            {
                Response = registerStatus
            };

            if (registerStatus)
            {
                return(Ok(model));
            }
            return(BadRequest(model));
        }
示例#12
0
        //[ProducesResponseType(typeof(JsonApiResponse<bool>), StatusCodes.Status200OK)]
        //[ProducesResponseType(typeof(JsonApiResponse<bool>), StatusCodes.Status400BadRequest)]
        public async Task <IActionResult> Add([FromBody] JsonApiRequest <ViewMeeting> request)
        {
            var result = await _manager.AddAsync(_mapper.Map <Meeting>(request.RequestParams));

            var model = new JsonApiResponse <bool>
            {
                Errors   = null,
                Response = result
            };

            if (result)
            {
                await _context.Clients.All.SendAsync("AddResponse", true);

                return(Ok(model));
            }

            await _context.Clients.All.SendAsync("AddResponse", false);

            return(BadRequest(model));
        }
示例#13
0
        public override async Task <ApiData> GetMinerStatsDataAsync()
        {
            var api            = new ApiData();
            var elapsedSeconds = DateTime.Now.Subtract(_started).Seconds;

            if (elapsedSeconds < 15)
            {
                return(api);
            }
            JsonApiResponse resp = null;

            try
            {
                var bytesToSend = Encoding.ASCII.GetBytes("{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"miner_getstat1\"}\n");
                using (var client = new TcpClient("127.0.0.1", _apiPort))
                    using (var nwStream = client.GetStream())
                    {
                        await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);

                        var bytesToRead = new byte[client.ReceiveBufferSize];
                        var bytesRead   = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);

                        var respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                        //Helpers.ConsolePrint(MinerTag(), "respStr: " + respStr);
                        resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr);
                        // TODO
                        //api.AlgorithmSpeedsTotal = new[] { (_algorithmType, resp.TotalHashrate ?? 0) };
                        if (resp != null && resp.error == null)
                        {
                            //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "resp != null && resp.error == null");
                            if (resp.result != null && resp.result.Count > 4)
                            {
                                var speeds     = resp.result[3].Split(';');
                                var totalSpeed = 0d;
                                foreach (var speed in speeds)
                                {
                                    //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "foreach (var speed in speeds) {");
                                    double tmpSpeed;
                                    try
                                    {
                                        tmpSpeed = double.Parse(speed, CultureInfo.InvariantCulture);
                                    }
                                    catch
                                    {
                                        tmpSpeed = 0;
                                    }

                                    totalSpeed += tmpSpeed;
                                }
                                var total = new List <(AlgorithmType, double)>();
                                total.Add((_algorithmType, totalSpeed));
                                api.AlgorithmSpeedsTotal = total; //new List<(AlgorithmType, double)>((_algorithmType, totalSpeed));
                            }

                            //if (ad.Speed == 0)
                            //{
                            //    CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                            //}

                            ////// some clayomre miners have this issue reporting negative speeds in that case restart miner
                            ////if (ad.Speed < 0)
                            ////{
                            ////    Helpers.ConsolePrint(MinerTag(), "Reporting negative speeds will restart...");
                            ////    Restart();
                            ////}
                        }
                    }
            }
            catch (Exception ex)
            {
                //Helpers.ConsolePrint(MinerTag(), "GetSummary exception: " + ex.Message);
            }

            return(api);
        }
示例#14
0
        public override async Task <ApiData> GetSummaryAsync()
        {
            CurrentMinerReadStatus = MinerApiReadStatus.NONE;
            var ad = new ApiData(MiningSetup.CurrentAlgorithmType, MiningSetup.CurrentSecondaryAlgorithmType);

            JsonApiResponse resp = null;

            try
            {
                var bytesToSend = Encoding.ASCII.GetBytes("{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"miner_getstat1\"}\n");
                using (var client = new TcpClient("127.0.0.1", ApiPort))
                    using (var nwStream = client.GetStream())
                    {
                        await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);

                        var bytesToRead = new byte[client.ReceiveBufferSize];
                        var bytesRead   = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);

                        var respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                        resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                    }
                //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", respStr);
            }
            catch (Exception ex)
            {
                Helpers.ConsolePrint(MinerTag(), "GetSummary exception: " + ex.Message);
            }

            if (resp != null && resp.error == null)
            {
                //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "resp != null && resp.error == null");
                if (resp.result != null && resp.result.Count > 4)
                {
                    //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "resp.result != null && resp.result.Count > 4");
                    var speeds          = resp.result[3].Split(';');
                    var secondarySpeeds = (IsDual()) ? resp.result[5].Split(';') : new string[0];
                    ad.Speed          = 0;
                    ad.SecondarySpeed = 0;
                    foreach (var speed in speeds)
                    {
                        //Helpers.ConsolePrint("ClaymoreZcashMiner API back:", "foreach (var speed in speeds) {");
                        double tmpSpeed;
                        try
                        {
                            tmpSpeed = double.Parse(speed, CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                            tmpSpeed = 0;
                        }

                        ad.Speed += tmpSpeed;
                    }

                    foreach (var speed in secondarySpeeds)
                    {
                        double tmpSpeed;
                        try
                        {
                            tmpSpeed = double.Parse(speed, CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                            tmpSpeed = 0;
                        }

                        ad.SecondarySpeed += tmpSpeed;
                    }

                    ad.Speed              *= ApiReadMult;
                    ad.SecondarySpeed     *= ApiReadMult;
                    CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                }

                if (ad.Speed == 0)
                {
                    CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                }

                // some clayomre miners have this issue reporting negative speeds in that case restart miner
                if (ad.Speed < 0)
                {
                    Helpers.ConsolePrint(MinerTag(), "Reporting negative speeds will restart...");
                    Restart();
                }
            }

            return(ad);
        }
示例#15
0
        public override async Task <ApiData> GetSummaryAsync()
        {
            CurrentMinerReadStatus = MinerApiReadStatus.NONE;
            var ad             = new ApiData(MiningSetup.CurrentAlgorithmType, MiningSetup.CurrentSecondaryAlgorithmType);
            var elapsedSeconds = DateTime.Now.Subtract(_started).Seconds;

            if (elapsedSeconds < 15 && firstStart)
            {
                return(ad);
            }
            firstStart = false;

            JsonApiResponse resp = null;

            try
            {
                var bytesToSend = Encoding.ASCII.GetBytes("{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"miner_getstat1\"}\n");
                using (var client = new TcpClient("127.0.0.1", ApiPort))
                    using (var nwStream = client.GetStream())
                    {
                        await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);

                        var bytesToRead = new byte[client.ReceiveBufferSize];
                        var bytesRead   = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);

                        var respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                        //Helpers.ConsolePrint(MinerTag(), "respStr: " + respStr);
                        resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                    }
            }
            catch (Exception ex)
            {
                Helpers.ConsolePrint(MinerTag(), "GetSummary exception: " + ex.Message);
            }
            //{"id":0,"jsonrpc":"2.0","result":["TT-Miner/2.2.1","0","4235681;1;0","2077789;2157892","0;0;0","off;off","71;79;59;68","mtp.hk.nicehash.com:3374","0;0;0;0"]}

            if (resp != null && resp.error == null)
            {
                var    speed    = resp.result[2].ToString().Split(';')[0];
                double tmpSpeed = double.Parse(speed, CultureInfo.InvariantCulture);
                ad.Speed = tmpSpeed;

                /*
                 *  var speeds = resp.result[2].Split(';');
                 *  ad.Speed = 0;
                 *  ad.SecondarySpeed = 0;
                 *  foreach (var speed in speeds)
                 *  {
                 *      double tmpSpeed;
                 *      try
                 *      {
                 *          tmpSpeed = double.Parse(speed, CultureInfo.InvariantCulture);
                 *      }
                 *      catch
                 *      {
                 *          tmpSpeed = 0;
                 *      }
                 *      ad.Speed = tmpSpeed;
                 *  }
                 */
                CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;

                if (ad.Speed == 0)
                {
                    CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                }
            }
            //Thread.Sleep(200);
            return(ad);
        }
示例#16
0
        public override async Task <ApiData> GetSummaryAsync()
        {
            CurrentMinerReadStatus = MinerApiReadStatus.NONE;
            var ad             = new ApiData(MiningSetup.CurrentAlgorithmType, MiningSetup.CurrentSecondaryAlgorithmType);
            var elapsedSeconds = DateTime.Now.Subtract(_started).Seconds;

            if (elapsedSeconds < 15 && firstStart)
            {
                return(ad);
            }
            firstStart = false;

            JsonApiResponse resp = null;

            try
            {
                var bytesToSend = Encoding.ASCII.GetBytes("{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"miner_getstat1\"}\n");
                using (var client = new TcpClient("127.0.0.1", ApiPort))
                    using (var nwStream = client.GetStream())
                    {
                        await nwStream.WriteAsync(bytesToSend, 0, bytesToSend.Length);

                        var bytesToRead = new byte[client.ReceiveBufferSize];
                        var bytesRead   = await nwStream.ReadAsync(bytesToRead, 0, client.ReceiveBufferSize);

                        var respStr = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                        // Helpers.ConsolePrint(MinerTag(), "respStr: " + respStr);
                        resp = JsonConvert.DeserializeObject <JsonApiResponse>(respStr, Globals.JsonSettings);
                    }
            }
            catch (Exception ex)
            {
                Helpers.ConsolePrint(MinerTag(), "GetSummary exception: " + ex.Message);
            }

            if (resp != null && resp.error == null)
            {
                var speeds = resp.result[3].Split(';');
                ad.Speed          = 0;
                ad.SecondarySpeed = 0;
                foreach (var speed in speeds)
                {
                    double tmpSpeed;
                    try
                    {
                        tmpSpeed = double.Parse(speed, CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        tmpSpeed = 0;
                    }
                    ad.Speed += tmpSpeed;
                }
                CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;

                if (ad.Speed == 0)
                {
                    CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                }
            }
            //Thread.Sleep(200);
            return(ad);
        }