예제 #1
0
        private EthConfig ValidateEthConfig()
        {
            if (cbxTargetDeviceEth.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个硬件设备");
                return(null);
            }

            string ethWalletAddress = txtWalletAddressEth.Text;

            ethWalletAddress = ethWalletAddress.Trim();

            if (string.IsNullOrWhiteSpace(ethWalletAddress))
            {
                MessageBox.Show("请输入钱包地址");
                return(null);
            }

            if (!ethWalletAddress.StartsWith("0x"))
            {
                MessageBox.Show("钱包必须是以0x开头的32位字符串");
                return(null);
            }

            if (cbxTargetEthPool.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个ETH矿池");
                return(null);
            }

            if (cbxTargetEthPoolHost.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个ETH矿池地址");
                return(null);
            }

            EthConfig ethConfig = new EthConfig();

            ethConfig.PoolIndex     = (EthConfig.PoolIndexes)cbxTargetEthPool.SelectedIndex;
            ethConfig.PoolHostIndex = cbxTargetEthPoolHost.SelectedIndex;
            ethConfig.WalletAddress = txtWalletAddressEth.Text.Trim();
            ethConfig.EmailAddress  = txtEmailAddressEth.Text;
            ethConfig.WorkerName    = txtEthWorkerName.Text;

            try
            {
                ethConfig.ValidateProperties();
                return(ethConfig);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Eth配置数据有误:" + ex.Message);
                logger.Error("ValidateProperties failed: " + ex.ToString());
                return(null);
            }
        }
        /// <summary>
        ///
        /// </summary>
        private void StepThree_ConfigEthMiner()
        {
            logger.Trace("Start StepThree_ConfigEthMiner.");

            MinerDevice selectedDevice = (cBxTargetDeviceEth.SelectedIndex >= 0) ? displayedDeviceList.ElementAt(cBxTargetDeviceEth.SelectedIndex) : null;

            if (selectedDevice == null)
            {
                MessageBox.Show("请选择一个硬件设备");
                return;
            }

            string ethWalletAddress = txtWalletAddressEth.Text;

            ethWalletAddress = ethWalletAddress.Trim();

            if (string.IsNullOrWhiteSpace(ethWalletAddress))
            {
                MessageBox.Show("请输入钱包地址");
                return;
            }

            if (!ethWalletAddress.StartsWith("0x"))
            {
                MessageBox.Show("钱包必须是以0x开头的32位字符串");
                return;
            }

            if (cBxTargetEthPool.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个ETH矿池");
                return;
            }

            if (cBxTargetEthPoolHost.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个ETH矿池地址");
                return;
            }

            EthConfig ethConfig = new EthConfig();

            ethConfig.PoolIndex     = (EthConfig.PoolIndexes)cBxTargetEthPool.SelectedIndex;
            ethConfig.PoolHostIndex = cBxTargetEthPoolHost.SelectedIndex;
            ethConfig.WalletAddress = txtWalletAddressEth.Text.Trim();
            ethConfig.EmailAddress  = txtEmailAddressEth.Text;
            ethConfig.WorkerName    = txtEthWorkerName.Text;

            try
            {
                ethConfig.ValidateProperties();
            }
            catch (Exception ex)
            {
                MessageBox.Show("配置数据有误:" + ex.Message);
                logger.Error("ValidateProperties failed: " + ex.ToString());
                return;
            }

            BackgroundWork <int> .CreateWork(
                this,
                () => {
                ShowProgressIndicator("正在配置矿机", btnStepThreeNext, btnStepThreeBack);
            },
                () => {
                string commandParameters = string.Format(" -c \"{{ 'DeviceId':'{0}', 'EthPoolAddress':'{1}', 'AutoDecideInstanceId':true }}\"",
                                                         selectedDevice.DeviceId,
                                                         ethConfig.PoolFullAddress);
                OKResult exeResult = createdClient.ExecuteDaemon <OKResult>(commandParameters);
                return(0);
            },
                (taskResult) => {
                HideProgressIndicator();

                if (taskResult.HasError)
                {
                    MessageBox.Show("配置矿机出现错误:" + taskResult.Exception.Message);
                    logger.Error("ConfigureCommand failed: " + taskResult.Exception.ToString());
                    return;
                }

                // Save the currnet config into cache.
                createdClient.Device    = selectedDevice;
                createdClient.EthConfig = ethConfig;

                if (cKbWalletSaveToDefault.IsChecked ?? false)
                {
                    ManagerConfig.Current.DefaultEth = ethConfig;
                    ManagerConfig.Current.SaveToFile();
                }

                SwitchUIToStep(4);
            }
                ).Execute();
        }