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(); }
private void btnConfirm_Click(object sender, RoutedEventArgs e) { if (cbxInstanceType.SelectedIndex < 0) { MessageBox.Show("请选择一个矿机类型.", "提示"); return; } // Validate the config if (properties.InstanceType == MinerClient.InstanceTypes.XDagger) { if (!ValidateXDaggerConfig()) { return; } } else if (properties.InstanceType == MinerClient.InstanceTypes.Ethereum) { if (!ValidateEthConfig()) { return; } } MessageBoxResult mresult = MessageBox.Show($"确认要修改选定的{ minerClients.Count }个矿机的配置吗?", "确认", MessageBoxButton.YesNo); if (mresult == MessageBoxResult.No) { return; } // Execute configure command string configParameters = string.Empty; if (properties.InstanceType == MinerClient.InstanceTypes.XDagger) { configParameters = ComposeXDaggerConfigParameters(); } else if (properties.InstanceType == MinerClient.InstanceTypes.Ethereum && properties.EthConfig.IsEmptyConfig()) { configParameters = ComposeEthConfigParameters(); } logger.Trace($"Composed configure command parameter: [{ configParameters }]"); ProgressWindow progress = new ProgressWindow("正在修改矿机配置...", this.minerClients, (obj) => { MinerClient client = (MinerClient)obj; if (properties.InstanceType == MinerClient.InstanceTypes.Ethereum && !properties.EthConfig.IsEmptyConfig()) { configParameters = ComposeEthConfigParameters(client); } logger.Trace($"Composed configure command parameter: [{ configParameters }] on machine [{ client.MachineFullName }]"); ConfigureOutput exeResult = client.ExecuteDaemon <ConfigureOutput>(configParameters); // If instance type changed, we need to decide the new instanceId if (client.InstanceTypeEnum != properties.InstanceType && exeResult.InstanceId != null) { int finalInstanceId = AssignInstanceId(client.MachineFullName, properties.InstanceType, exeResult.InstanceId.Value); if (finalInstanceId != exeResult.InstanceId) { client.ExecuteDaemon <ConfigureOutput>("-c \"{ 'InstanceId':'" + finalInstanceId.ToString() + "' }\""); } client.InstanceId = finalInstanceId; } //After the config command success, update the status of the client properties.UpdateClient(client); }, (result) => { this.HandleProgressResult(result.Result); } ); progress.ShowDialog(); }