public static void SendConsoleMessage(this MainWindow mainWindow)
 {
     if (mainWindow.autoCompleteBoxConsoleCommand.Text.Length > 0)
     {
         if (mainWindow.autoCompleteBoxConsoleCommandSuggestions.IndexOf(mainWindow.autoCompleteBoxConsoleCommand.Text) < 0)
         {
             mainWindow.autoCompleteBoxConsoleCommandSuggestions.Add(mainWindow.autoCompleteBoxConsoleCommand.Text);
             ApplyDataBinding(mainWindow);
         }
         if (mainWindow.tabControlServersLogs.SelectedIndex > 0)
         {
             IServer server = mainWindow._tabItems[(mainWindow.tabControlServersLogs.SelectedItem as TabItem)];
             if (server.ServerProcess != null)
             {
                 if (server.ServerProcess.StartInfo.FileName != "")
                 {
                     if (server.ServerProcess.Responding)
                     {
                         SendMessageUtil.SendTextMessage(mainWindow.autoCompleteBoxConsoleCommand.Text, server.ServerProcess);
                         Thread.Sleep(50);
                         ((mainWindow.tabControlServersLogs.SelectedItem as TabItem).Content as RichTextBox).ScrollToEnd();
                     }
                 }
             }
         }
         else
         {
             foreach (IServer server in mainWindow._serversControl.Servers)
             {
                 if (server.ServerProcess != null)
                 {
                     if (server.ServerProcess.StartInfo.FileName != "")
                     {
                         if (server.ServerProcess.Responding)
                         {
                             SendMessageUtil.SendTextMessage(mainWindow.autoCompleteBoxConsoleCommand.Text, server.ServerProcess);
                         }
                     }
                 }
             }
         }
         mainWindow.autoCompleteBoxConsoleCommand.Focus();
     }
 }
Beispiel #2
0
        public virtual void Stop()
        {
            if (_serverThread != null)
            {
                if (_serverThread.ThreadState == System.Threading.ThreadState.Running || _serverThread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
                {
                    _serverThread.Abort();

                    if (ServerProcess != null)
                    {
                        try
                        {
                            if (this is ValveHltvServer)
                            {
                                _logger.Info(string.Format(Properties.Resources.log_KillProcessShutdown, Options.HostName));
                                try
                                {
                                    ServerProcess.Kill();
                                }
                                catch (Exception e)
                                {
                                    _logger.DebugException(Properties.Resources.log_ProcessAlreadyKilled, e);
                                }
                            }
                            else
                            {
                                _logger.Info(string.Format(Properties.Resources.log_TryingNormalShutdown, Options.HostName));
                                if (SendMessageUtil.SendTextMessage("quit", ServerProcess))
                                {
                                    ServerProcess.WaitForExit(3000);
                                    if (!ServerProcess.HasExited)
                                    {
                                        _logger.Warn(string.Format(Properties.Resources.log_NormalShutdownFailed, Options.HostName));
                                        _logger.Info(string.Format(Properties.Resources.log_KillProcessShutdown, Options.HostName));
                                        try
                                        {
                                            ServerProcess.Kill();
                                        }
                                        catch (Exception e)
                                        {
                                            _logger.DebugException(Properties.Resources.log_ProcessAlreadyKilled, e);
                                        }
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        ServerProcess.Kill();
                                    }
                                    catch (Exception e)
                                    {
                                        _logger.DebugException(Properties.Resources.log_ProcessAlreadyKilled, e);
                                    }
                                }
                            }
                        }
                        catch
                        {
                            try
                            {
                                ServerProcess.Kill();
                            }
                            catch (Exception e)
                            {
                                _logger.DebugException(Properties.Resources.log_ProcessAlreadyKilled, e);
                            }
                        }
                    }
                    _logger.Info(string.Format(Properties.Resources.log_SuccessfulStopped, Options.HostName));
                    OnServerStoped(this, new EventArgs());
                }
                else
                {
                    _logger.Info(string.Format(Properties.Resources.log_ServerAlreadyStopped, Options.HostName));
                }
            }
            else
            {
                _logger.Info(string.Format(Properties.Resources.log_ServerAlreadyStopped, Options.HostName));
            }
        }