コード例 #1
0
ファイル: ClientTests.cs プロジェクト: strager/Ondit
        public void ConnectionStatusChangedEvent()
        {
            string input = "001 :Welcome\r\n";

            var writer = new IO.Helpers.DummyRawMessageWriter();

            using(var stringReader = new StringReader(input))
            using(var reader = new RawMessageTextReader(stringReader)) {
                using(var client = new Ondit.Client.Client(reader, writer)) {
                    ConnectionStatus? connectionStatusChanged = null;

                    client.ConnectionStatusChanged += (sender, e) => {
                        connectionStatusChanged = e.NewStatus;
                    };

                    Assert.AreEqual(ConnectionStatus.NotConnected, client.ConnectionStatus);

                    client.Connect();

                    Assert.AreEqual(ConnectionStatus.Connecting, connectionStatusChanged);
                    Assert.AreEqual(ConnectionStatus.Connecting, client.ConnectionStatus);

                    client.HandleMessage();

                    Assert.AreEqual(ConnectionStatus.Connected, connectionStatusChanged);
                    Assert.AreEqual(ConnectionStatus.Connected, client.ConnectionStatus);
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: strager/Ondit
        private void Connection(string host, int port)
        {
            client = new Client(host, port);

            client.SynchronizingObject = this;

            client.RawMessageSent += MessageSent;
            client.RawMessageReceived += MessageReceived;
            client.ConversationMessageReceived += ConversationMessageReceived;

            client.Connect();
            client.WaitForConnected();

            if(client.ConnectionStatus != ConnectionStatus.Connected) {
                conversation.Text += string.Format(@"Could not connect to {0} on port {1}." + Environment.NewLine, host, port);

                return;
            }

            clientThread = new Thread(() => {
                while(client != null) {
                    client.HandleMessageBlock();
                }
            });

            clientThread.Start();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: strager/Ondit
        void Run()
        {
            using(client = new Client("irc.slagg.org", 6667)) {
                Console.WriteLine("Connecting...");

                client.Connect();
                client.WaitForConnected();

                Console.WriteLine("Connected!");

                LoadPlugins();

                client.JoinChannel("#test");

                while(client.ConnectionStatus == ConnectionStatus.Connected) {
                    client.HandleMessageBlock();
                }
            }
        }