示例#1
0
        public async Task <bool> DeleteNetworkAsync(NetworkViewModel networkViewModel)
        {
            try
            {
                if (networkViewModel.CurrentStatus != ServerStatus.STOPPED)
                {
                    StopNetwork(networkViewModel, false);
                    while (networkViewModel.CurrentStatus != ServerStatus.STOPPED)
                    {
                        Thread.Sleep(500);
                    }
                }

                if (!networkViewModel.DownloadCompleted)
                {
                    //Cancel download
                    await Downloader.CancelJarDownloadAsync(networkViewModel);
                }

                networkViewModel.DeleteEntity();
                DirectoryInfo serverDirectory =
                    new DirectoryInfo(Path.Combine(App.ServerPath, networkViewModel.Name));
                serverDirectory.Delete(true);
                Application.Current.Dispatcher?.Invoke(() => ServerManager.Instance.RemoveEntity(networkViewModel));
                EntitySerializer.Instance.StoreEntities();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                return(false);
            }
        }