예제 #1
0
        private void AddServer(object sender, RoutedEventArgs e)
        {
            try
            {
                var name = nameBox.Text;
                var port = int.Parse(portBox.Text);

                foreach (ServerControl sc in Servers)
                {
                    if (port.Equals(sc.Server.Port))
                    {
                        throw new PortAlreadyInUseException(port);
                    }
                }

                var newS = new ServerControl(new Server(name, port), this, Console);
                Servers.Add(newS);
                ServersView.Children.Add(newS);

                Back(BackB, new RoutedEventArgs());
                Console.WriteLine($"Server \'{nameBox.Text}\' successfully created on port {portBox.Text}.");
            }
            catch (FormatException fe)
            {
                //napis ze null
                Console.WriteLine(fe.Message);
            } catch (PortAlreadyInUseException pe)
            {
                Console.WriteLine(pe.Message);
            }
        }
예제 #2
0
 public void RemoveServer(ServerControl control)
 {
     ServersView.Children.Remove(control);
     Servers.Remove(control);
 }