Exemplo n.º 1
0
        public AppContext()
        {
#if DEBUG
            var cmds = Utilities.GetConflictingCommands();
            if (cmds.Any())
            {
                Debugger.Break();
            }
#endif
            MainForm = form;
            server   = new MessengerServer(2059);
            server.Pusher.Bind <InstantMessageContent>(e => form.WriteLine(e.ToString()));
            server.Pusher.Bind <LoginContent>(e => form.WriteLine($@"{e.ClientName} has logged in."));
            server.Pusher.Bind <LogoutContent>(e => form.WriteLine($@"{e.ClientName} has logged out. Reason: {e.Reason}."));
            server.Pusher.Bind <ConnectionRefusedContent>(e =>
            {
                if (e.Reason == ConnectionRefusedReason.EmptyName)
                {
                    form.WriteLine("A client tried to login with an empty name.");
                }
                else
                {
                    form.WriteLine($@"{e.ClientName} has been refused, reasons: {e.Reason}.");
                }
            });

            form.CommandSubmitted += ConsoleCommandSubmitted;
            HelpCmd();
            StartCmd();
        }