示例#1
0
 private void StartServer_Click(object sender, EventArgs e)
 {
     if (_isStarted)
     {
         Server.Close();
         _isStarted       = false;
         EncType.Enabled  = true;
         StartServer.Text = "Запустить сервер";
     }
     else
     {
         _isStarted       = true;
         Server           = new ServerCore(Dispatcher.CurrentDispatcher, this, EncType.SelectedIndex == 0 ? EncriptionType.Rsa : EncriptionType.Xor);
         StartServer.Text = "Остановить сервер";
         EncType.Enabled  = false;
         Server.Start();
     }
 }
示例#2
0
 private void StartServerButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bStartServer.IsEnabled = false;
         if (ServerCore.IsStarted) //If started
         {
             ServerCore.Stop();
             StatusColor.Fill     = Brushes.WhiteSmoke;
             bStartServer.Content = "Start server";
         }
         else
         {
             var port = Convert.ToInt32(tb_port.Text);
             if (port < 0 || port > 65535)
             {
                 throw new FormatException("Port is " + (port < 0 ? "negative" : "greater than 65535"));
             }
             bStartServer.Content = "Server starting...";
             ServerCore.Start(port);
             StatusColor.Fill     = Brushes.LawnGreen;
             bStartServer.Content = "Pause server";
         }
         bStartServer.IsEnabled = true;
     }
     catch (FormatException ex)
     {
         MessageBox.Show("Port format error: " + ex.Message);
         Logger.LogError("User input error. Port format error: " + ex.Message);
     }
     catch (Exception ex)
     {
         StatusColor.Fill = Brushes.Red;
         Logger.LogError("Error: " + ex.Message);
     }
 }