/// <summary> /// 服务器管理 /// </summary> private void Manage_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; switch (btn.Name) { #region 启动登录服务器 case "loginStart": try { if (ProcessInstance.IsRuning("G-Box.LoginServer")) { MessageBox.Show("登录服务器已经启动!"); } else { Process.Start(@"G-Box.LoginServer.exe"); } } catch (Exception ex) { MessageBox.Show("启动登录服务器出错!"); ilogger.Logger(string.Format("启动登录服务器异常:{0}", ex.Message)); } break; #endregion #region 启动大厅服务器 case "hallStart": hallServer = new HallServer(configModel, ilogger, connViewModel); downServer = new DownServer(configModel, ilogger); if (hallServer.StartServer() && downServer.StartServer()) { hallStart.IsEnabled = false; hallClose.IsEnabled = true; hallStatus.Text = "已启动."; downStatus.Text = "已启动."; } else { MessageBox.Show("启动失败,请重试!"); } break; #endregion #region 关闭大厅服务器 case "hallClose": if (hallServer.StopServer() && downServer.StopServer()) { hallStart.IsEnabled = true; hallClose.IsEnabled = false; hallStatus.Text = "未启动."; downStatus.Text = "未启动."; } else { MessageBox.Show("停止失败,请重试!"); } break; #endregion #region 启动更新服务器 case "updateStart": try { if (ProcessInstance.IsRuning("G-Box.UpdateServer")) { MessageBox.Show("更新服务器已经启动!"); } else { Process.Start(@"G-Box.UpdateServer.exe"); } } catch (Exception ex) { MessageBox.Show("启动更新服务器出错!"); ilogger.Logger(string.Format("启动更新服务器异常:{0}", ex.Message)); } break; #endregion #region 浏览更新文件夹 case "updateScan": try { SWF.FolderBrowserDialog fbd = new SWF.FolderBrowserDialog(); fbd.ShowDialog(); updatePath.Text = fbd.SelectedPath; //文件夹路径 } catch (Exception ex) { ilogger.Logger(string.Format("浏览文件夹异常:{0}", ex.Message)); } break; #endregion #region 压缩更新文件 case "updateZip": if (File.Exists(currentPath + "UpdatePath\\updatefiles")) { MessageBox.Show("更新文件已经存在!"); return; } try { updateZip.IsEnabled = false; updateZip.Content = "Wait."; string path = updatePath.Text.Trim(); Task t = new Task(() => { if (path != null && path != "") { //指定文件夹下的压缩 GZip.Compress(@path + "\\", currentPath + "UpdatePath\\", "updatefiles"); } else { //默认文件夹 GZip.Compress(currentPath + "UpdatePath\\Backup\\", currentPath + "UpdatePath\\", "updatefiles"); } }); t.Start(); t.ContinueWith((task) => { if (!task.IsFaulted && task.IsCompleted) { Dispatcher.Invoke(new Action(() => { updateZip.IsEnabled = true; updateZip.Content = "压缩"; updatePath.Text = ""; MessageBox.Show("压缩执行完毕!"); }), System.Windows.Threading.DispatcherPriority.Normal); } }); } catch (Exception ex) { ilogger.Logger(string.Format("压缩文件异常:{0}", ex.Message)); } break; #endregion } }