private void StepFour_StartMiner() { logger.Trace("Start StepFour_StartMiner."); BackgroundWork <int> .CreateWork( this, () => { ShowProgressIndicator("正在启动矿机服务", btnStepFourFinish, btnStepFourBack); }, () => { OKResult exeResult = createdClient.ExecuteDaemon <OKResult>("-s start"); return(0); }, (taskResult) => { HideProgressIndicator(); if (taskResult.HasError) { MessageBox.Show("启动矿机出现错误,请稍后手动启动:" + taskResult.Exception.Message); logger.Error("Got error while starting miner: " + taskResult.Exception.ToString()); createdClient.CurrentServiceStatus = MinerClient.ServiceStatus.Stopped; } else { createdClient.CurrentServiceStatus = MinerClient.ServiceStatus.Disconnected; } StepFour_Finish(); } ).Execute(); }
private void StepFive_StartService_Sync() { int startedWorkCount = 0; int finishedWorkCount = 0; foreach (MinerClient client in createdClients) { startedWorkCount++; BackgroundWork <int> .CreateWork(this, () => { }, () => { OKResult exeResult = client.ExecuteDaemon <OKResult>("-s start"); return(0); }, (taskResult) => { finishedWorkCount++; HideProgressIndicator(); if (taskResult.HasError) { logger.Error("Got error while starting miner: " + taskResult.Exception.ToString()); } } ).Execute(); } while (finishedWorkCount < startedWorkCount) { Thread.Sleep(30); } }
private void HandleProgressResult(int failureCount) { MessageBoxResult mresult = MessageBox.Show("修改配置完成,需要重启矿机服务后才能生效。需要现在重启所有修改过的矿机吗?", "确认", MessageBoxButton.YesNo); if (mresult == MessageBoxResult.No) { MinerManager.GetInstance().SaveCurrentInfo(); this.Close(); return; } // Restart the selected miners ProgressWindow progress = new ProgressWindow("正在重新启动矿机...", this.minerClients, (obj) => { MinerClient client = (MinerClient)obj; OKResult exeResult = client.ExecuteDaemon <OKResult>("-s stop"); exeResult = client.ExecuteDaemon <OKResult>("-s start"); }, (result) => { MinerManager.GetInstance().SaveCurrentInfo(); this.Close(); }, shouldPromptSummary: false ); progress.ShowDialog(); }
private void StepFour_ConfigureClients_Sync(string configureParameters) { int startedWorkCount = 0; int finishedWorkCount = 0; foreach (MinerClient client in createdClients) { if (client.CurrentDeploymentStatus == MinerClient.DeploymentStatus.Ready) { continue; } string clientConfigureParameters = client.FillStringTags(configureParameters); startedWorkCount++; BackgroundWork <int> .CreateWork(this, () => { }, () => { OKResult exeResult = client.ExecuteDaemon <OKResult>(clientConfigureParameters); exeResult = client.ExecuteDaemon <OKResult>("-s install"); return(0); }, (taskResult) => { finishedWorkCount++; if (taskResult.HasError) { logger.Error($"Got error while configuring client on machine [{ client.Machine.FullName }] : " + taskResult.Exception.ToString()); } else { client.CurrentDeploymentStatus = MinerClient.DeploymentStatus.Ready; dataGridMachineConfiguration.Refresh(); } } ).Execute(); } while (finishedWorkCount < startedWorkCount) { Thread.Sleep(30); } }
private void StopSelectedMiner() { logger.Trace("Start StopSelectedMiner."); List <MinerDataGridItem> minerDataGridItems = GetSelectedRowsInDataGrid(); if (minerDataGridItems.Count == 0) { return; } List <object> selectedClients = new List <object>(); foreach (MinerDataGridItem minerItem in minerDataGridItems) { selectedClients.Add(minerItem.Client); } ProgressWindow progress = new ProgressWindow("正在停止矿机...", selectedClients, (obj) => { MinerClient client = (MinerClient)obj; OKResult r = client.ExecuteDaemon <OKResult>("-s stop"); client.CurrentServiceStatus = MinerClient.ServiceStatus.Stopped; }, (result) => { if (result.HasError) { MessageBox.Show("错误:" + result.Exception.Message); logger.Error("Got Error while stoping miner: " + result.Exception.ToString()); } else { logger.Trace("Miner stopped."); } this.RefreshMinerListGrid(); } ); progress.ShowDialog(); }
private void StepFour_SetupMiner() { logger.Trace("Start StepFour_SetupMiner."); // Install the Service BackgroundWork <int> .CreateWork( this, () => { ShowProgressIndicator("正在安装矿机服务", btnStepFourFinish, btnStepFourBack); }, () => { OKResult exeResult = createdClient.ExecuteDaemon <OKResult>("-s install"); return(0); }, (taskResult) => { HideProgressIndicator(); if (taskResult.HasError) { MessageBox.Show("安装矿机出现错误:" + taskResult.Exception.Message); logger.Error("Error while installing miner: " + taskResult.Exception.ToString()); return; } createdClient.CurrentDeploymentStatus = MinerClient.DeploymentStatus.Ready; if (cKbSetStartTarget.IsChecked ?? false) { StepFour_StartMiner(); } else { StepFour_Finish(); } } ).Execute(); }
/// <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 UninstallSelectedMiner() { logger.Trace("Start UninstallSelectedMiner."); List <MinerDataGridItem> minerDataGridItems = GetSelectedRowsInDataGrid(); if (minerDataGridItems.Count == 0) { return; } List <object> selectedClients = new List <object>(); foreach (MinerDataGridItem minerItem in minerDataGridItems) { selectedClients.Add(minerItem.Client); } if (MessageBox.Show("确定要卸载选定的矿机吗?", "确认", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } ProgressWindow progress = new ProgressWindow("正在卸载矿机...", selectedClients, (obj) => { MinerClient client = (MinerClient)obj; try { OKResult r = client.ExecuteDaemon <OKResult>("-s uninstall"); client.CurrentDeploymentStatus = MinerClient.DeploymentStatus.Downloaded; client.CurrentServiceStatus = MinerClient.ServiceStatus.Stopped; } catch (Exception ex) { client.CurrentDeploymentStatus = MinerClient.DeploymentStatus.Unknown; client.CurrentServiceStatus = MinerClient.ServiceStatus.Unknown; logger.Error("Got Error while uninstalling miner service: " + ex.ToString()); throw; } finally { // Since sometimes the Windows Service will lock the config file for a while after uninstall, we will wait here System.Threading.Thread.Sleep(5000); client.DeleteBinaries(); } }, (result) => { if (result.HasError) { if (result.Exception is IOException) { /// MessageBox.Show("删除矿机目录错误,请到矿机目录下手动删除矿机文件。详细信息:" + result.Exception.Message); logger.Error("Got error while uninstalling miner with IOException: " + result.Exception.ToString()); } else { /// MessageBox.Show("错误:" + result.Exception.Message); logger.Error("Something wrong while uninstalling miner: " + result.Exception.ToString()); } } // Removing client from ObjectModel first, and then Delete binaries might throw IO exception which should be ignored foreach (MinerDataGridItem item in minerDataGridItems) { minerManager.RemoveClient(item.Client); minerListGridItems.Remove(item); } this.RefreshMinerListGrid(); }, false); progress.ShowDialog(); }