示例#1
0
        private XDaggerConfig ValidateXDaggerConfig()
        {
            if (cbxTargetDevice.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个硬件设备");
                return(null);
            }

            XDaggerConfig xDaggerConfig = new XDaggerConfig();

            xDaggerConfig.PoolAddress = txtXDaggerPoolAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(xDaggerConfig.PoolAddress))
            {
                MessageBox.Show("请输入矿池地址");
                return(null);
            }

            xDaggerConfig.WalletAddress = txtXDaggerWalletAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(xDaggerConfig.WalletAddress))
            {
                MessageBox.Show("请输入钱包地址");
                return(null);
            }

            if (xDaggerConfig.WalletAddress.Length != 32)
            {
                MessageBox.Show("钱包必须为长度32位的字母与数字组合");
                return(null);
            }

            return(xDaggerConfig);
        }
        /// <summary>
        ///
        /// </summary>
        private void StepThree_ConfigXDaggerMiner()
        {
            logger.Trace("Start StepThree_ConfigXDaggerMiner.");

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

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

            XDaggerConfig xDaggerConfig = new XDaggerConfig();

            xDaggerConfig.PoolAddress = txtXDaggerPoolAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(xDaggerConfig.PoolAddress))
            {
                MessageBox.Show("请输入矿池地址");
                return;
            }

            xDaggerConfig.WalletAddress = txtWalletAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(xDaggerConfig.WalletAddress))
            {
                MessageBox.Show("请输入钱包地址");
                return;
            }

            if (xDaggerConfig.WalletAddress.Length != 32)
            {
                MessageBox.Show("钱包必须为长度32位的字母与数字组合");
                return;
            }

            BackgroundWork <int?> .CreateWork(
                this,
                () => {
                ShowProgressIndicator("正在配置矿机", btnStepThreeNext, btnStepThreeBack);
            },
                () => {
                string commandParameters = string.Format(" -c \"{{ 'DeviceId':'{0}', 'XDaggerWallet':'{1}', 'XDaggerPoolAddress':'{2}', 'AutoDecideInstanceId':true }}\"",
                                                         selectedDevice.DeviceId,
                                                         xDaggerConfig.WalletAddress,
                                                         xDaggerConfig.PoolAddress);

                ConfigureOutput exeResult = createdClient.ExecuteDaemon <ConfigureOutput>(commandParameters);

                logger.Trace("ConfigureCommand finished with InstanceId: " + exeResult.InstanceId);
                return(exeResult.InstanceId);
            },
                (taskResult) => {
                HideProgressIndicator();

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

                int?instanceId = taskResult.Result;
                if (instanceId == null)
                {
                    MessageBox.Show("配置矿机出现错误,未返回InstanceId.");
                    logger.Error("配置矿机出现错误,未返回InstanceId.");
                    return;
                }

                createdClient.InstanceId = instanceId.Value;

                // Save the currnet config into cache.
                createdClient.Device        = selectedDevice;
                createdClient.XDaggerConfig = xDaggerConfig;

                if (cKbWalletSaveToDefault.IsChecked ?? false)
                {
                    ManagerConfig.Current.DefaultXDagger = xDaggerConfig;
                    ManagerConfig.Current.SaveToFile();
                }

                SwitchUIToStep(4);
            }
                ).Execute();
        }
示例#3
0
        private void StepFour_ConfigureClients()
        {
            logger.Trace("Start StepFour_ConfigureClients.");

            string configureParameters = string.Empty;
            string deviceName          = string.Empty;

            XDaggerConfig xDaggerConfig = null;
            EthConfig     ethConfig     = null;

            if (selectedMinerClientType == MinerClient.InstanceTypes.XDagger)
            {
                xDaggerConfig = ValidateXDaggerConfig();
                if (xDaggerConfig == null)
                {
                    return;
                }

                deviceName          = (string)cbxTargetDevice.SelectedValue;
                configureParameters = string.Format(" -c \"{{ 'DeviceName':'{0}', 'XDaggerWallet':'{1}', 'XDaggerPoolAddress':'{2}', 'AutoDecideInstanceId':true }}\"",
                                                    deviceName,
                                                    xDaggerConfig.WalletAddress,
                                                    xDaggerConfig.PoolAddress);
            }
            else if (selectedMinerClientType == MinerClient.InstanceTypes.Ethereum)
            {
                ethConfig = ValidateEthConfig();
                if (ethConfig == null)
                {
                    return;
                }

                deviceName          = (string)cbxTargetDeviceEth.SelectedValue;
                configureParameters = string.Format(" -c \"{{ 'DeviceName':'{0}', 'EthPoolAddress':'{1}', 'AutoDecideInstanceId':true }}\"",
                                                    deviceName,
                                                    ethConfig.PoolFullAddress);
            }

            grdStepFourXDagger.Visibility = Visibility.Hidden;
            grdStepFourEth.Visibility     = Visibility.Hidden;
            grdStepFourStatus.Visibility  = Visibility.Visible;

            dataGridMachineConfiguration.ClearItems();
            foreach (MinerClient client in createdClients)
            {
                client.Device = client.Machine.Devices.FirstOrDefault(d => d.DisplayName.Equals(deviceName));
                if (selectedMinerClientType == MinerClient.InstanceTypes.XDagger)
                {
                    client.XDaggerConfig = xDaggerConfig;
                }
                else if (selectedMinerClientType == MinerClient.InstanceTypes.Ethereum)
                {
                    client.EthConfig            = ethConfig;
                    client.EthConfig.WorkerName = client.FillStringTags(client.EthConfig.WorkerName);
                }

                dataGridMachineConfiguration.AddItem(client);
            }

            BackgroundWork <int> .CreateWork(
                this,
                () => {
                ShowProgressIndicator("正在配置目标机器......", btnStepFourStatusNext, btnStepFourStatusBack);
            },
                () => {
                StepFour_ConfigureClients_Sync(configureParameters);
                return(0);
            },
                (taskResult) => {
                HideProgressIndicator();
                if (taskResult.HasError)
                {
                    HideProgressIndicator();
                    MessageBox.Show("配置过程出现错误: " + taskResult.Exception.Message);
                    logger.Error("Got error while copying binary: " + taskResult.Exception.ToString());

                    btnStepFourStatusNext.IsEnabled = false;
                    return;
                }

                List <MinerClient> failedClients = new List <MinerClient>();
                foreach (MinerClient client in createdClients)
                {
                    if (client.CurrentDeploymentStatus != MinerClient.DeploymentStatus.Ready)
                    {
                        failedClients.Add(client);
                    }
                }

                if (failedClients.Count > 0)
                {
                    MessageBox.Show("有部分矿机配置失败,请退回上一步重试.", "提示");
                    btnStepFourStatusNext.IsEnabled = false;
                }
            }
                ).Execute();
        }