private string ComposeEthConfigParameters(MinerClient client = null) { StringBuilder builder = new StringBuilder(); builder.Append(" -c \"{ "); bool isFirstParameter = true; if (!string.IsNullOrWhiteSpace(properties.DeviceName)) { builder.AppendFormat(" 'DeviceName':'{0}' ", properties.DeviceName); isFirstParameter = false; } if (client != null && properties.EthConfig != null) { EthConfig mergedConfig = client.EthConfig.CloneWithUpdate(properties.EthConfig); if (!isFirstParameter) { builder.Append(", "); } string poolFullAddress = mergedConfig.PoolFullAddress; poolFullAddress = client.FillStringTags(poolFullAddress); builder.AppendFormat(" 'EthPoolAddress':'{0}' ", poolFullAddress); } builder.Append(" }\""); return(builder.ToString()); }
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); } }
private bool ValidateEthConfig() { string ethWalletAddress = txtEthWallet.Text.Trim(); if (!string.IsNullOrWhiteSpace(ethWalletAddress) && !ethWalletAddress.StartsWith("0x")) { MessageBox.Show("钱包必须是以0x开头的32位字符串"); return(false); } bool ethPoolTotallyBlank = (cbxTargetEthPool.SelectedIndex < 0) && (cbxTargetEthPoolHost.SelectedIndex < 0) && (string.IsNullOrEmpty(txtEmailAddress.Text)); if (missingEthWalletAddress && string.IsNullOrEmpty(ethWalletAddress)) { MessageBox.Show("由于有些矿机没有设置钱包地址,必须填写钱包地址"); return(false); } if (cbxTargetEthPool.SelectedIndex >= 0 && cbxTargetEthPoolHost.SelectedIndex < 0) { MessageBox.Show("请选择矿池的地址"); return(false); } if (missingEthPoolAddress) { if (cbxTargetEthPool.SelectedIndex < 0) { MessageBox.Show("由于有些矿机没有设置矿池,请选择矿池类型"); return(false); } } EthConfig updatedConfig = new EthConfig(); updatedConfig.PoolIndex = (cbxTargetEthPool.SelectedIndex >= 0) ? (EthConfig.PoolIndexes)cbxTargetEthPool.SelectedIndex : (EthConfig.PoolIndexes?)null; updatedConfig.PoolHostIndex = cbxTargetEthPoolHost.SelectedIndex; updatedConfig.EmailAddress = txtEmailAddress.Text.Trim(); updatedConfig.WalletAddress = ethWalletAddress; updatedConfig.WorkerName = @"{MACHINE_NAME}_{INSTANCE_ID}"; properties.EthConfig = updatedConfig; if (cbxEthDevice.SelectedIndex >= 0) { properties.DeviceName = cbxEthDevice.SelectedItem.ToString(); } return(true); }
/// <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(); }
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(); }