public static void ParseTextForDeviceDetails(string text, List<PoolInformationResponse> poolInformation)
        {
            List<string> deviceBlob = text.Split('|').ToList();
            deviceBlob.RemoveAt(0);

            foreach (string deviceText in deviceBlob)
            {
                if (deviceText == "\0")
                    continue;

                //bfgminer may have multiple entries for the same key, e.g. Hardware Errors
                //seen with customer data/hardware
                //remove dupes using Distinct()
                var deviceAttributes = deviceText.Split(',').ToList().Distinct();

                Dictionary<string, string> keyValuePairs = deviceAttributes
                  .Where(value => value.Contains('='))
                  .Select(value => value.Split('='))
                  .ToDictionary(pair => pair[0], pair => pair[1]);

                //seen Count == 0 with user API logs
                if (keyValuePairs.Count > 0)
                {
                    PoolInformationResponse newPool = new PoolInformationResponse();

                    newPool.Index = int.Parse(keyValuePairs["POOL"]);

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("URL"))
                        newPool.Url = keyValuePairs["URL"];

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("Status"))
                        newPool.Status = keyValuePairs["Status"];

                    newPool.Priority = TryToParseInt(keyValuePairs, "Priority", 0);
                    newPool.Quota = TryToParseInt(keyValuePairs, "Quota", 0);

                    if (keyValuePairs.ContainsKey("Long Pool"))
                        newPool.LongPoll = !keyValuePairs["Long Pool"].Equals("n", StringComparison.OrdinalIgnoreCase);

                    newPool.GetWorks = TryToParseInt(keyValuePairs, "Getworks", 0);
                    newPool.Accepted = TryToParseInt(keyValuePairs, "Accepted", 0);
                    newPool.Rejected = TryToParseInt(keyValuePairs, "Rejected", 0);
                    newPool.Works = TryToParseInt(keyValuePairs, "Works", 0);
                    newPool.Discarded = TryToParseInt(keyValuePairs, "Discarded", 0);
                    newPool.Stale = TryToParseInt(keyValuePairs, "Stale", 0);
                    newPool.GetFailures = TryToParseInt(keyValuePairs, "Get Failures", 0);
                    newPool.RemoteFailures = TryToParseInt(keyValuePairs, "Remote Failures", 0);

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("User"))
                        newPool.User = keyValuePairs["User"];

                    newPool.LastShareTime = TryToParseInt(keyValuePairs, "Last Share Time", 0).UnixTimeToDateTime();
                    newPool.Diff1Shares = TryToParseInt(keyValuePairs, "Diff1 Shares", 0);

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("Proxy"))
                        newPool.Proxy = keyValuePairs["Proxy"];

                    newPool.DifficultyAccepted = TryToParseDouble(keyValuePairs, "Difficulty Accepted", 0.0);
                    newPool.DifficultyRejected = TryToParseDouble(keyValuePairs, "Difficulty Rejected", 0.0);
                    newPool.DifficultyStale = TryToParseDouble(keyValuePairs, "Difficulty Stale", 0.0);
                    newPool.LastShareDifficulty = TryToParseDouble(keyValuePairs, "Last Share Difficulty", 0.0);

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("Has Stratum"))
                        newPool.HasStratum = keyValuePairs["Has Stratum"].Equals("true", StringComparison.OrdinalIgnoreCase);

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("Stratum Active"))
                        newPool.StratumActive = keyValuePairs["Stratum Active"].Equals("true", StringComparison.OrdinalIgnoreCase);

                    //user bug reports indicate this key may not exist
                    if (keyValuePairs.ContainsKey("Stratum URL"))
                        newPool.StratumUrl = keyValuePairs["Stratum URL"];

                    newPool.BestShare = TryToParseInt(keyValuePairs, "Best Share", 0);
                    newPool.PoolRejectedPercent = TryToParseDouble(keyValuePairs, "Pool Rejected%", 0.0);
                    newPool.PoolStalePercent = TryToParseDouble(keyValuePairs, "Pool Stale%", 0.0);

                    poolInformation.Add(newPool);
                }
            }
        }
示例#2
0
        public void InspectDetails(Device device, CoinConfiguration coinConfiguration, CoinInformation coinInformation,
            List<DeviceInformationResponse> deviceInformation, PoolInformationResponse poolInformation,
            List<DeviceDetailsResponse> deviceDetails, bool showWorkUtility)
        {
            this.deviceDetails = deviceDetails;
            this.deviceInformation = deviceInformation;

            noDetailsPanel.Visible = false;
            double hashrate = deviceInformation.Sum(di => di.AverageHashrate);
            double currentRate = deviceInformation.Sum(di => di.CurrentHashrate);

            hashrateLabel.Text = hashrate.ToHashrateString();
            currentRateLabel.Text = currentRate.ToHashrateString();

            workersGridView.Visible = (device.Kind == DeviceKind.PXY) &&
                (deviceInformation.Count > 0);
            workersTitleLabel.Visible = workersGridView.Visible;

            //Internet or Coin API could be down
            if (coinInformation != null)
            {
            }

            //device may not be configured
            if (coinConfiguration != null)
                cryptoCoinBindingSource.DataSource = coinConfiguration.Coin;
            else
                cryptoCoinBindingSource.DataSource = new CryptoCoin();

            deviceInformationResponseBindingSource.DataSource = deviceInformation;

            //may not be hashing yet
            if (deviceDetails != null)
                deviceDetailsResponseBindingSource.DataSource = deviceDetails;
            else
                deviceDetailsResponseBindingSource.DataSource = new DeviceDetailsResponse();

            deviceBindingSource.DataSource = device;

            switch (device.Kind)
            {
                case DeviceKind.CPU:
                    pictureBox1.Image = imageList1.Images[3];
                    break;
                case DeviceKind.GPU:
                    pictureBox1.Image = imageList1.Images[0];
                    break;
                case DeviceKind.USB:
                    pictureBox1.Image = imageList1.Images[1];
                    break;
                case DeviceKind.PXY:
                    pictureBox1.Image = imageList1.Images[2];
                    break;
            }

            nameLabel.Width = this.Width - nameLabel.Left - closeDetailsButton.Width;

            acceptedLabel.Text = deviceInformation.Sum(d => d.AcceptedShares).ToString();
            rejectedLabel.Text = deviceInformation.Sum(d => d.RejectedShares).ToString();
            errorsLabel.Text = deviceInformation.Sum(d => d.HardwareErrors).ToString();

            if (showWorkUtility)
            {
                utilityLabel.Text = deviceInformation.Sum(d => d.WorkUtility).ToString();
                utilityDataGridViewTextBoxColumn.DataPropertyName = "WorkUtility";
            }
            else
            {
                utilityLabel.Text = deviceInformation.Sum(d => d.Utility).ToString();
                utilityDataGridViewTextBoxColumn.DataPropertyName = "Utility";
            }
            utilityPrefixLabel.Text = showWorkUtility ? "Work utility:" : "Utility:";

            DeviceInformationResponse deviceInfo = (DeviceInformationResponse)deviceInformationResponseBindingSource.Current;
            if (deviceInfo != null)
            {
                if (deviceInfo.Temperature > 0)
                    tempLabel.Text = deviceInfo.Temperature + "°";
                else
                    tempLabel.Text = String.Empty;

                if (deviceInfo.FanPercent > 0)
                    fanLabel.Text = deviceInfo.FanPercent + "%";
                else
                    fanLabel.Text = String.Empty;
            }
            else
            {
                tempLabel.Text = String.Empty;
                fanLabel.Text = String.Empty;
            }

            UpdateColumnVisibility();

            //may not be hashing yet
            if (poolInformation != null)
                poolInformationResponseBindingSource.DataSource = poolInformation;
            else
                poolInformationResponseBindingSource.DataSource = new PoolInformationResponse();
        }