示例#1
0
        static void Main(string[] args)
        {
            string server   = "http://jabbr-staging.apphb.com/";
            string roomName = "test";
            string userName = "******";
            string password = "******";

            var client = new JabbRClient(server);

            // Subscribe to new messages
            client.MessageReceived += (message, room) =>
            {
                Console.WriteLine("[{0}] {1}: {2}", message.When, message.User.Name, message.Content);
            };

            client.UserJoined += (user, room) =>
            {
                Console.WriteLine("{0} joined {1}", user.Name, room);
            };

            client.UserLeft += (user, room) =>
            {
                Console.WriteLine("{0} left {1}", user.Name, room);
            };

            client.PrivateMessage += (from, to, message) =>
            {
                Console.WriteLine("*PRIVATE* {0} -> {1} ", from, message);
            };

            // Connect to chat
            client.Connect(userName, password).ContinueWith(task =>
            {
                LogOnInfo info = task.Result;


                Console.WriteLine("Logged on successfully. You are currently in the following rooms:");
                foreach (var room in info.Rooms)
                {
                    Console.WriteLine(room.Name);
                    Console.WriteLine(room.Private);
                }

                Console.WriteLine("User id is {0}. Don't share this!", info.UserId);

                Console.WriteLine();

                // Get my user info
                User myInfo = client.GetUserInfo().Result;

                Console.WriteLine(myInfo.Name);
                Console.WriteLine(myInfo.LastActivity);
                Console.WriteLine(myInfo.Status);
                Console.WriteLine(myInfo.Country);


                client.JoinRoom(roomName);

                Console.WriteLine();

                // Join a room called test
                client.JoinRoom(roomName).ContinueWith(_ =>
                {
                    // Get info about the test room
                    client.GetRoomInfo(roomName).ContinueWith(t =>
                    {
                        Room roomInfo = t.Result;

                        Console.WriteLine("Users");

                        foreach (var u in roomInfo.Users)
                        {
                            Console.WriteLine(u.Name);
                        }

                        Console.WriteLine();

                        foreach (var u in roomInfo.Users)
                        {
                            if (u.Name != userName)
                            {
                                client.SendPrivateMessage(u.Name, "hey there, this is private right?");
                            }
                        }
                    });
                });

                // Set the flag
                client.SetFlag("bb");

                // Set the user note
                client.SetNote("This is testing a note");

                // Mark the client as typing
                client.SetTyping(roomName);

                // Clear the note
                client.SetNote(null);

                // Say hello to the room
                client.Send("Hello world", roomName);

                Console.WriteLine("Press any key to leave the room and disconnect");
                Console.Read();
                client.LeaveRoom(roomName).ContinueWith(_ =>
                {
                    client.Disconnect();
                });
            });

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            string server = "https://jabbr-staging.apphb.com/";
            string roomName = "test";
            string userName = "******";
            string password = "******";

            // this might be needed in some cases
            ServicePointManager.DefaultConnectionLimit = 100;

            var client = new JabbRClient(server);

            // Subscribe to new messages
            client.MessageReceived += (message, room) =>
            {
                Console.WriteLine("[{0}] {1}: {2}", message.When, message.User.Name, message.Content);
            };

            client.UserJoined += (user, room, isOwner) =>
            {
                Console.WriteLine("{0} joined {1}", user.Name, room);
            };

            client.UserLeft += (user, room) =>
            {
                Console.WriteLine("{0} left {1}", user.Name, room);
            };

            client.PrivateMessage += (from, to, message) =>
            {
                Console.WriteLine("*PRIVATE* {0} -> {1} ", from, message);
            };

            var wh = new ManualResetEventSlim();

            // Connect to chat
            client.Connect(userName, password).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    wh.Set();
                }

                LogOnInfo info = task.Result;

                Console.WriteLine("Logged on successfully. You are currently in the following rooms:");
                foreach (var room in info.Rooms)
                {
                    Console.WriteLine(room.Name);
                    Console.WriteLine(room.Private);
                }

                Console.WriteLine("User id is {0}. Don't share this!", info.UserId);

                Console.WriteLine();

                // Get my user info
                User myInfo = client.GetUserInfo().Result;

                Console.WriteLine(myInfo.Name);
                Console.WriteLine(myInfo.LastActivity);
                Console.WriteLine(myInfo.Status);
                Console.WriteLine(myInfo.Country);

                // Join a room called test
                client.JoinRoom(roomName).ContinueWith(_ =>
                {
                    // Get info about the test room
                    client.GetRoomInfo(roomName).ContinueWith(t =>
                    {
                        Room roomInfo = t.Result;

                        Console.WriteLine("Users");

                        foreach (var u in roomInfo.Users)
                        {
                            Console.WriteLine(u.Name);
                        }

                        Console.WriteLine();

                        foreach (var u in roomInfo.Users)
                        {
                            if (u.Name != userName)
                            {
                                client.SendPrivateMessage(u.Name, "hey there, this is private right?");
                            }
                        }
                    });
                });

                // Set the flag
                client.SetFlag("bb");

                // Set the user note
                client.SetNote("This is testing a note");

                // Mark the client as typing
                client.SetTyping(roomName);

                // Clear the note
                client.SetNote(null);

                // Say hello to the room
                client.Send("Hello world", roomName);

                Console.WriteLine("Press any key to leave the room and disconnect");
                
                Console.Read();
  
                client.LeaveRoom(roomName).ContinueWith(_ =>
                {
                    client.Disconnect();

                    wh.Set();
                });
            });

            wh.Wait();
        }
示例#3
0
        static void Main(string[] args)
        {
            string server = "http://localhost:16207/";
            string roomName = "test";
            string userName = "******";
            string password = "******";

            // this might be needed in some cases
            ServicePointManager.DefaultConnectionLimit = 10;

            var client = new JabbRClient(server);

            // Subscribe to new messages
            client.MessageReceived += (message, room) =>
            {
                Console.WriteLine("[{0}] {1}: {2}", message.When, message.User.Name, message.Content);
            };

            client.UserJoined += (user, room, isOwner) =>
            {
                Console.WriteLine("{0} joined {1}", user.Name, room);
            };

            client.UserLeft += (user, room) =>
            {
                Console.WriteLine("{0} left {1}", user.Name, room);
            };

            client.PrivateMessage += (from, to, message) =>
            {
                Console.WriteLine("*PRIVATE* {0} -> {1} ", from, message);
            };

            var wh = new ManualResetEventSlim();

            // Connect to chat
            client.Connect(userName, password).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    wh.Set();
                }

                LogOnInfo info = task.Result;

                Console.WriteLine("Logged on successfully. You are currently in the following rooms:");
                foreach (var room in info.Rooms)
                {
                    Console.WriteLine(room.Name);
                    Console.WriteLine(room.Private);
                }

                Console.WriteLine("User id is {0}. Don't share this!", info.UserId);

                Console.WriteLine();

                // Get my user info
                User myInfo = client.GetUserInfo().Result;

                Console.WriteLine(myInfo.Name);
                Console.WriteLine(myInfo.LastActivity);
                Console.WriteLine(myInfo.Status);
                Console.WriteLine(myInfo.Country);

                // Join a room called test
                client.JoinRoom(roomName).ContinueWith(_ =>
                {
                    // Get info about the test room
                    client.GetRoomInfo(roomName).ContinueWith(t =>
                    {
                        Room roomInfo = t.Result;

                        Console.WriteLine("Users");

                        foreach (var u in roomInfo.Users)
                        {
                            Console.WriteLine(u.Name);
                        }

                        Console.WriteLine();

                        foreach (var u in roomInfo.Users)
                        {
                            if (u.Name != userName)
                            {
                                client.SendPrivateMessage(u.Name, "hey there, this is private right?");
                            }
                        }
                    });
                });

                // Set the flag
                client.SetFlag("bb");

                // Set the user note
                client.SetNote("This is testing a note");

                // Mark the client as typing
                client.SetTyping(roomName);

                // Clear the note
                client.SetNote(null);

                // Say hello to the room
                client.Send("Hello world", roomName);

                // Post a notification
                client.PostNotification(new ClientNotification
                {
                    Source = "Github",
                    Content = "This is a fake github notification from the client",
                    ImageUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHD0lEQVR4nH2Xy28cWRXGf/dRVV3dfnWcOGOPMwxxJgLNgJAijRhWLCKxyyJ/CFt2rJDYjNjyLyDNfzA7YANEbACNFBQNyGDHdpzY7W7X4z5Z1KOrY4uSjrpVbt/73e985zvnCgbP8+fPAZQQAiEESimklCvRPUIIYgQEECMxRkIIeB/w3uOcxTmHcw5rLcYYrG3exRj9ixcvmnUAnj17hrX2SYzxS6XUJ1JKIaVcAlAK2YISQnS7ghDt/h2AiPce77uNHc7ZFQBtnHnvf22t/UoDVFX1Q+CP29vb+Xg8RmuNUuoGA0sASxa6J8aI94EQ/MrJuzDGYKzF1DVFUeydnZ39znu/JQG897/a3NzM8zzvqexO1W0khOiB3AauiSWgho2Ac466NlRVRXF9zWKxwDnPdDoVxphf6vb3j0ejEd570jRFa43WCVovN7LWopQiTdP+5EMGmvx7AIwxSClIEk0IHqUd0kqEaDRUlgWj0Qil1L0OgJZKIWDlNN135xwvX75EKcXu7i53794lxoi1lhgjUkoSnTBfzDk6OuL8/Jz9/X02NjaaNXr9LPUSWwV3AJCtuN6nWWtNXdftqSSHh4ecn5/jnCOE0DOhpKKqK0xdE0KgLEum0+lKukAM0qkQsgUgBgoXA/V3AJIk6alXShFCQCuFSJKuHgghkCRJo6E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h0ufQShqIqS9KOHzE5O0esbGBuoDYS375C2JoZAVVf9PHEbAxJoqa+p67qhryybqJrPN+dvOZ1sYz/7MfX2HvM6kn38mKI2ZB8/ZlGW5Aff591lSbFxl/rTz7nYPWC2uG5Y6ACY1TSEEFAA0+n050LKO6rr7605dANqmWSIR58SgKhTxOYBtU9Ze/gD1CRD3f0elc0ZPXiEyCWVMRipcXWFe/emBzDUQ/vOawBjLFJKKq2XU3EIPVXSGMzxIfX2B0ilsFYQvKCcOwyeugAIKFdiiia/4uoCjv6Nqar3NncrDOgmBd0Um/Q+HQYAtNaob/6KHK8Rt+/jkzs4meN9QgwSVwUEDooSXb1Dnb/Gzi5uXEiMtf2Nyfuw9AHnHFKqgU+vbt5fVIxBzi4RUpAK0YzZApLY9BLvPVVb493F5LbPRoADBkIIwXuHsZbOGZtFPFq7G8PEcIhdNrMlax2AoeKbaK9t3uP9Si/gX977T6wxxBBw3qP+zw1ouHmXsjhgYQjktugYiDFeCoCdnZ0vYoy/l1ImsttwMBkJsZzhhJA0k9gSRNfbO68fev9KdH9rgEQhxC8EwN7eHs65pyGE38QYP+xOdlt0N+LuN8MU3BYhxKWxtUCBKyHEl8Bv/weLMsKv/a+a7AAAAABJRU5ErkJggg==",
                    Room = "test"
                });

                Console.WriteLine("Press any key to leave the room and disconnect");

                Console.Read();

                client.LeaveRoom(roomName).ContinueWith(_ =>
                {
                    client.Disconnect();

                    wh.Set();
                });
            });

            wh.Wait();
        }
示例#4
0
        static void Main(string[] args)
        {
            string server   = "http://localhost:16207/";
            string roomName = "test";
            string userName = "******";
            string password = "******";

            var client = new JabbRClient(server);

            // Uncomment to see tracing
            // client.TraceWriter = Console.Out;

            // Subscribe to new messages
            client.MessageReceived += (message, room) =>
            {
                Console.WriteLine("[{0}] {1}: {2}", message.When, message.User.Name, message.Content);
            };

            client.UserJoined += (user, room, isOwner) =>
            {
                Console.WriteLine("{0} joined {1}", user.Name, room);
            };

            client.UserLeft += (user, room) =>
            {
                Console.WriteLine("{0} left {1}", user.Name, room);
            };

            client.PrivateMessage += (from, to, message) =>
            {
                Console.WriteLine("*PRIVATE* {0} -> {1} ", from, message);
            };

            var wh = new ManualResetEventSlim();

            EnsureAccount(server, userName, password);

            // Connect to chat
            client.Connect(userName, password).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("Error: " + task.Exception.GetBaseException());
                    wh.Set();
                }

                LogOnInfo info = task.Result;

                Console.WriteLine("Logged on successfully. You are currently in the following rooms:");
                foreach (var room in info.Rooms)
                {
                    Console.WriteLine(room.Name);
                    Console.WriteLine(room.Private);
                }

                Console.WriteLine("User id is {0}. Don't share this!", info.UserId);

                Console.WriteLine();

                // Get my user info
                User myInfo = client.GetUserInfo().Result;

                Console.WriteLine(myInfo.Name);
                Console.WriteLine(myInfo.LastActivity);
                Console.WriteLine(myInfo.Status);
                Console.WriteLine(myInfo.Country);

                // Join a room called test
                client.JoinRoom(roomName).ContinueWith(_ =>
                {
                    // Get info about the test room
                    client.GetRoomInfo(roomName).ContinueWith(t =>
                    {
                        Room roomInfo = t.Result;

                        Console.WriteLine("Users");

                        foreach (var u in roomInfo.Users)
                        {
                            Console.WriteLine(u.Name);
                        }

                        Console.WriteLine();

                        foreach (var u in roomInfo.Users)
                        {
                            if (u.Name != userName)
                            {
                                client.SendPrivateMessage(u.Name, "hey there, this is private right?");
                            }
                        }
                    });
                });

                // Set the flag
                client.SetFlag("bb");

                // Set the user note
                client.SetNote("This is testing a note");

                // Mark the client as typing
                client.SetTyping(roomName);

                // Clear the note
                client.SetNote(null);

                // Say hello to the room
                client.Send("Hello world", roomName);

                // Post a notification
                client.PostNotification(new ClientNotification
                {
                    Source   = "Github",
                    Content  = "This is a fake github notification from the client",
                    ImageUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHD0lEQVR4nH2Xy28cWRXGf/dRVV3dfnWcOGOPMwxxJgLNgJAijRhWLCKxyyJ/CFt2rJDYjNjy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K9t3uP9Si/gX977T6wxxBBw3qP+zw1ouHmXsjhgYQjktugYiDFeCoCdnZ0vYoy/l1ImsttwMBkJsZzhhJA0k9gSRNfbO68fev9KdH9rgEQhxC8EwN7eHs65pyGE38QYP+xOdlt0N+LuN8MU3BYhxKWxtUCBKyHEl8Bv/weLMsKv/a+a7AAAAABJRU5ErkJggg==",
                    Room     = "test"
                });

                Console.WriteLine("Press any key to leave the room and disconnect");

                Console.Read();

                client.LeaveRoom(roomName).ContinueWith(_ =>
                {
                    client.Disconnect();

                    wh.Set();
                });
            });

            wh.Wait();
        }