Ejemplo n.º 1
0
        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();
        }