예제 #1
0
        private void SendData()
        {
            try
            {
                // Cấu hình GridView
                var dt = new DataTable();
                dt.Columns.Add("WorkerName");
                dt.Columns.Add("Ip");
                dt.Columns.Add("RunningTime");
                dt.Columns.Add("EthereumStats");
                dt.Columns.Add("DcrInfo");
                dt.Columns.Add("GpuTemperature");
                dt.Columns.Add("Pool");
                dt.Columns.Add("Version");
                dt.Columns.Add("Comments");

                // New MinerInfo
                var miner = new MinerInfo
                {
                    Wallet         = txtWallet.Text.ToLower().Trim(),
                    EmailId        = txtEmail.Text.ToLower().Trim(),
                    Name           = StringHelper.RemoveSign4VietnameseString(txtName.Text.Trim()),
                    CreatedDate    = DateTime.Now,
                    StatisticsDate = DateTime.Now
                };

                // Stats from ethermine.org
                var obj = JsonConvert.DeserializeObject <MonitorObject>(ConvertHelper.ToString(File.ReadAllText(DataFilePath)));
                if (obj != null)
                {
                    // Ghi nhớ thời gian Stats
                    //                    obj.StatsDate = DateTime.Now;
                    //                    File.Delete(DataFilePath);
                    //                    File.Create(DataFilePath).Close();
                    //                    File.WriteAllText(DataFilePath, JsonConvert.SerializeObject(obj));

                    // Monitor Workers
                    var i = 1;
                    while (true)
                    {
                        // Lấy thông tin Stats từ Ethermine
                        var host = txtHost.Text.Replace("http://", string.Empty);
                        var port = txtPort.Text;
                        miner = StatsHelper.GetStatsFromEthermine(miner);
                        var content = client.DownloadString("http://" + host + ":" + port);
                        //var content = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt");
                        var html = new HtmlAgilityPack.HtmlDocument();

                        html.LoadHtml(content);
                        var doc = html.DocumentNode;
                        // Lấy dữ liệu MinerInfo
                        // Lấy danh sách dòng
                        if (doc?.QuerySelectorAll("tr") != null)
                        {
                            var arrTrs = doc.QuerySelectorAll("tr").ToList();

                            // Xóa cột th
                            arrTrs.RemoveAt(0);

                            var arrWorkers =
                                arrTrs.Select(node => node.QuerySelectorAll("td").ToList()).Select(arrCols => new Worker
                            {
                                Name           = ConvertHelper.ToString(arrCols[0].InnerText),
                                Ip             = ConvertHelper.ToString(arrCols[1].InnerText),
                                RunningTime    = ConvertHelper.ToString(arrCols[2].InnerText),
                                EthereumStats  = ConvertHelper.ToString(arrCols[3].InnerText),
                                DcrInfo        = ConvertHelper.ToString(arrCols[4].InnerText),
                                GpuTemperature = ConvertHelper.ToString(arrCols[5].InnerText),
                                Pool           = ConvertHelper.ToString(arrCols[6].InnerText),
                                Version        = ConvertHelper.ToString(arrCols[7].InnerText),
                                Comments       = ConvertHelper.ToString(arrCols[8].InnerText),
                                CreatedDate    = DateTime.Now
                            }).ToList();


                            // Bind dữ liệu vào Grid
                            if (gvData_ETH.Rows.Count == 0)
                            {
                                foreach (var worker in arrWorkers)
                                {
                                    var row = dt.NewRow();

                                    row["WorkerName"]     = worker.Name;
                                    row["Ip"]             = worker.Ip;
                                    row["RunningTime"]    = worker.RunningTime;
                                    row["EthereumStats"]  = worker.EthereumStats;
                                    row["DcrInfo"]        = worker.DcrInfo;
                                    row["GpuTemperature"] = worker.GpuTemperature;
                                    row["Pool"]           = worker.Pool;
                                    row["Version"]        = worker.Version;
                                    row["Comments"]       = worker.Comments;
                                    dt.Rows.Add(row);
                                }
                                gvData_ETH.DataSource = dt;
                            }
                            else
                            {
                                for (var j = 0; j < gvData_ETH.Rows.Count; j++)
                                {
                                    gvData_ETH.Rows[j].Cells["WorkerName"].Value     = arrWorkers[j].Name;
                                    gvData_ETH.Rows[j].Cells["Ip"].Value             = arrWorkers[j].Ip;
                                    gvData_ETH.Rows[j].Cells["RunningTime"].Value    = arrWorkers[j].RunningTime;
                                    gvData_ETH.Rows[j].Cells["EthereumStats"].Value  = arrWorkers[j].EthereumStats;
                                    gvData_ETH.Rows[j].Cells["DcrInfo"].Value        = arrWorkers[j].DcrInfo;
                                    gvData_ETH.Rows[j].Cells["GpuTemperature"].Value = arrWorkers[j].GpuTemperature;
                                    gvData_ETH.Rows[j].Cells["Pool"].Value           = arrWorkers[j].Pool;
                                    gvData_ETH.Rows[j].Cells["Version"].Value        = arrWorkers[j].Version;
                                    gvData_ETH.Rows[j].Cells["Comments"].Value       = arrWorkers[j].Comments;
                                }
                            }


                            // Gửi dữ liệu lên website
                            miner.Workers = arrWorkers.ToArray();
                            var minerUniqueName = monitorService.SendtMiner(miner);
                            linkLabel1.Text = @"http://ethmonitor.net/miners/" + minerUniqueName.ToLower();

                            SetTextBoxData($"{i}. Sent infomation miner '{miner.Name}' and {arrWorkers.Count} workers to EthMonitor.NET successful at {DateTime.Now}");
                            i++;

                            // Sleep tiến trình
                            Thread.Sleep(SLEEP_TIME_MONITOR);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                thMonitor?.Abort();
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void btnMonitor_Click(object sender, EventArgs e)
        {
            try
            {
                string currentVersion;
                if (IsCurrentVersion(out currentVersion))
                {
                    var obj = new MonitorObject
                    {
                        Wallet      = StringHelper.RemoveSign4VietnameseString(txtWallet.Text.ToLower().Trim()),
                        Email       = txtEmail.Text.ToLower().Trim(),
                        Name        = txtName.Text.Trim(),
                        CreatedDate = DateTime.Now,
                        StatsDate   = DateTime.Now
                    };

                    if (!string.IsNullOrEmpty(obj.Email) && !string.IsNullOrEmpty(obj.Wallet) && !string.IsNullOrEmpty(obj.Name))
                    {
                        if (StatsHelper.CheckEthWallet(obj.Wallet))
                        {
                            // Ghi nhớ Email
                            if (!File.Exists(DataFilePath))
                            {
                                File.Create(DataFilePath).Close();
                            }
                            File.WriteAllText(DataFilePath, JsonConvert.SerializeObject(obj));

                            // Monitoring
                            thMonitor = new Thread(SendData)
                            {
                                IsBackground = true
                            };
                            thMonitor.Start();
                            if (!thCommand.IsAlive)
                            {
                                thCommand = new Thread(GetCommands)
                                {
                                    IsBackground = true
                                };
                                thCommand.Start();
                            }
                            RunningApp(true);
                        }
                        else
                        {
                            txtWallet.Select();
                            MessageBox.Show(this, @"Your ETH Wallet not found on Ethermine.org !!!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        RunningApp(false);
                        txtName.Select();
                        MessageBox.Show(this, @"You need to enter your Name, Email and ETH Wallet !!!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    AlertVersion(currentVersion);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void SendData()
        {
            try
            {
                // New MinerInfo
                var miner = new MinerInfo
                {
                    Wallet         = txtWallet.Text.ToLower().Trim(),
                    EmailId        = txtEmail.Text.ToLower().Trim(),
                    Name           = StringHelper.RemoveSign4VietnameseString(txtName.Text.Trim()),
                    CreatedDate    = DateTime.Now,
                    StatisticsDate = DateTime.Now
                };

                // Stats from ethermine.org
                try
                {
                    var obj = JsonConvert.DeserializeObject <MonitorObject>(ConvertHelper.ToString(File.ReadAllText(DataFilePath)));
                    if (obj != null)
                    {
                        // Ghi nhớ thời gian Stats
                        obj.StatsDate = DateTime.Now;
                        File.Delete(DataFilePath);
                        File.Create(DataFilePath).Close();
                        File.WriteAllText(DataFilePath, JsonConvert.SerializeObject(obj));

                        miner = StatsHelper.GetStatsFromEthermine(miner);
                    }
                }
                catch (Exception ex)
                {
                    SetTextBoxData($"Error \"{ex.Message}\" when get data from Ethermine.org with wallet: {miner.Wallet}");
                }

                // Monitor Workers
                var i = 1;
                while (true)
                {
                    var host    = txtHost.Text.Replace("http://", string.Empty);
                    var port    = txtPort.Text;
                    var content = client.DownloadString("http://" + host + ":" + port);
                    //var content = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt");
                    var html = new HtmlAgilityPack.HtmlDocument();
                    html.LoadHtml(content);
                    var doc = html.DocumentNode;

                    // Lấy dữ liệu MinerInfo
                    // Lấy danh sách dòng
                    var arrTrs = doc.QuerySelectorAll("tr").ToList();

                    // Xóa cột th
                    arrTrs.RemoveAt(0);

                    var arrWorkers =
                        arrTrs.Select(node => node.QuerySelectorAll("td").ToList()).Select(arrCols => new Worker
                    {
                        Name           = arrCols[0].InnerText,
                        Ip             = arrCols[1].InnerText,
                        RunningTime    = arrCols[2].InnerText,
                        EthereumStats  = arrCols[3].InnerText,
                        DcrInfo        = arrCols[4].InnerText,
                        GpuTemperature = arrCols[5].InnerText,
                        Pool           = arrCols[6].InnerText,
                        Version        = arrCols[7].InnerText,
                        Comments       = arrCols[8].InnerText,
                        CreatedDate    = DateTime.Now
                    }).ToList();

                    miner.Workers = arrWorkers.ToArray();
                    var minerUniqueName = monitorService.SendtMiner(miner);
                    linkLabel1.Text = @"http://ethmonitor.net/miners/" + minerUniqueName.ToLower();
                    SetTextBoxData($"{i}. Sent infomation miner '{miner.Name}' and {arrWorkers.Count} workers to EthMonitor.NET successful at {DateTime.Now}");
                    Thread.Sleep(SLEEP_TIME_MONITOR);
                    i++;
                }
            }
            catch (Exception ex)
            {
                thMonitor?.Abort();
                MessageBox.Show(ex.Message);
            }
        }