Example #1
0
        void StopHandling(Socket socket)
        {
            if (socket == outcomingConnection)
            {
                Disconnect();
                return;
            }

            if (incomingConnections.Remove(socket))
            {
                ConnectionsCountChanged?.Invoke(this, new ConnectionsCountChangedEventArgs(ConnectionsCount));
                return;
            }

            // throw new InvalidOperationException("StopHandling() was given a socket that doesn't belong to client");
            // MessageBox.Show("StopHandling() was given a socket that doesn't belong to client", "Warning");
        }
Example #2
0
        public override void TerminateIncomingConnections()
        {
            // do I really need to lock?
            // Probably not, but I'm afraid to modify this old code
            lock (incomingConnections)
            {
                foreach (var socket in incomingConnections)
                {
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }

                incomingConnections.Clear();
            }

            ConnectionsCountChanged?.Invoke(this, new ConnectionsCountChangedEventArgs(ConnectionsCount));
        }
Example #3
0
        public MainWindowModel(string login)
        {
            Login  = login;
            Client = new Client();
            Window = new MainWindow {
                Title = Login
            };

            Window.Closing            += OnWindowClosing;
            Window.SendRequested      += OnSendRequested;
            Window.MessageTextChanged += (sender, args) =>
                                         Window.IsSendButtonEnabled = Client.HasConnections && !string.IsNullOrEmpty(args.NewText);
            Window.SettingsWindowRequested += OnSettingsWindowRequested;

            Client.MessageReceived         += (sender, args) => Window.AddMessage(args.Message);
            Client.ConnectionsCountChanged += (sender, args) => ConnectionsCountChanged?.Invoke(sender, args);

            ConnectionsCountChanged += (sender, args) => Window.SetConnectionsCount(args.Count);
        }