示例#1
0
        public Task <UserViewModel> SignIn(string token)
        {
            var taskCompletionSource = new TaskCompletionSource <UserViewModel>();

            Task <string> tokenAuthentication = Task.Factory.StartNew(() => AuthenticateToken(token));

            tokenAuthentication.ContinueWith(
                failedTokenTask => HandleSigninException(failedTokenTask.Exception, taskCompletionSource),
                TaskContinuationOptions.OnlyOnFaulted);
            tokenAuthentication.ContinueWith(tokenTask =>
            {
                Task <LogOnInfo> signinTask = _client.Connect(tokenTask.Result);
                SetupSigninTaskContinuations(signinTask, taskCompletionSource);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(taskCompletionSource.Task);
        }
        async void Connect()
        {
            _client = new JabbRClient(this.Account.Url);
            _client.AddMessageContent += HandleAddMessageContent;
            //client.Disconnected += HandleDisconnected;
            _client.FlagChanged       += HandleFlagChanged;
            _client.JoinedRoom        += HandleJoinedRoom;
            _client.Kicked            += HandleKicked;
            _client.LoggedOut         += HandleLoggedOut;
            _client.MeMessageReceived += HandleMeMessageReceived;
            _client.MessageReceived   += HandleMessageReceived;
            _client.NoteChanged       += HandleNoteChanged;
            _client.OwnerAdded        += HandleOwnerAdded;
            _client.OwnerRemoved      += HandleOwnerRemoved;
            _client.PrivateMessage    += HandlePrivateMessage;
            //_client.RoomCountChanged += HandleRoomCountChanged;
            //client.StateChanged += HandleStateChanged;
            _client.TopicChanged        += HandleTopicChanged;
            _client.UserActivityChanged += HandleUserActivityChanged;
            _client.UserJoined          += HandleUserJoined;
            _client.UserLeft            += HandleUserLeft;
            _client.UsernameChanged     += HandleUsernameChanged;
            _client.UsersInactive       += HandleUsersInactive;
            _client.UserTyping          += HandleUserTyping;

            LogOnInfo logonInfo = null;

            try
            {
                logonInfo = await _client.Connect(Account.Username, Account.Password);
            }
            catch (Exception ex)
            {
                Log("Connect Exception: " + ex);
            }

            if (logonInfo != null)
            {
                this.UserId = logonInfo.UserId;

                //Add us into the result's Rooms
                foreach (var r in logonInfo.Rooms)
                {
                    Mvx.Trace("Rooms In: " + r.Name);
                    RoomsIn.Add(r);
                }

                Log("Connected> " + this.UserId ?? "" + " -> Rooms: " + RoomsIn.Count);
                _messenger.Publish(new JabbrConnectedMessage(this, this, this.UserId, RoomsIn));
            }
        }
示例#3
0
        /// <summary>
        /// Connects to the chat session
        /// </summary>
        public void PowerUp()
        {
            if (!_isActive)
            {
                client.Connect(Name, _password).ContinueWith(task =>
                {
                    if (!task.IsFaulted)
                    {
                        LogOnInfo info = task.Result;
                        IntializeSprockets();
                    }
                    else
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(task.Exception);
                    }
                }).Wait();
                _isActive = true;
            }
            else
            {
                throw new InvalidOperationException("Bot is already powered up. Call ShutDown first");
            }
            //if (!_connection.IsActive)
            //{
            //    InitializeContainer();

            //    _chat.On<dynamic, string>("addMessage", ProcessMessage);

            //    _chat.On("leave", OnLeave);

            //    _chat.On("addUser", OnJoin);

            //    _chat.On<IEnumerable<string>>("logOn", OnLogOn);

            //    // Start the connection and wait

            //    _connection.Start(new AutoTransport()).Wait();

            //    // Join the chat
            //    var success = _chat.Invoke<bool>("Join").Result;

            //    if (!success)
            //    {
            //        // Setup the name of the bot
            //        Send(String.Format("/nick {0} {1}", Name, _password));

            //        IntializeSprockets();
            //    }
            //}
        }
示例#4
0
 public void StartUp()
 {
     _client.Connect(Name, _password).ContinueWith(task =>
     {
         if (!task.IsFaulted)
         {
             InitializeSprockets();
         }
         else
         {
             Console.WriteLine(task.Exception);
             new LogEvent(task.Exception.GetBaseException().ToString()).Raise();
         }
     }).Wait();
 }
示例#5
0
        public override async Task Run()
        {
            if (!_isConfigured)
            {
                throw new AdapterNotConfiguredException();
            }
            Logger.Info(string.Format("Logging into JabbR..."));

            SetupJabbrClient();

            var result = await _client.Connect(_nick, _password);

            _client.StateChanged += OnClientStateChanged;

            Logger.Info(string.Format("Logged on successfully. {0} is currently in the following rooms:", _nick));
            foreach (var room in result.Rooms)
            {
                Logger.Info(string.Format(" - " + room.Name + (room.Private ? " (private)" : string.Empty) + (_logRooms.Contains(room.Name) ? " (logging)" : string.Empty)));
                Rooms.Add(room.Name);
                if (_logRooms.Contains(room.Name))
                {
                    LogRooms.Add(room.Name);
                }
            }

            foreach (var room in _rooms.Union(_logRooms).Distinct().Where(room => !result.Rooms.Select(r => r.Name).Contains(room)))
            {
                try
                {
                    await _client.JoinRoom(room);

                    Rooms.Add(room);
                    Logger.Info(string.Format("Successfully joined room {0}", room));
                }
                catch (Exception e)
                {
                    Logger.Info(string.Format("Could not join room {0}: {1}", room, e.Message));
                }
            }

            foreach (var logRoom in _logRooms)
            {
                if (!LogRooms.Contains(logRoom))
                {
                    LogRooms.Add(logRoom);
                }
            }
        }
示例#6
0
文件: Bot.cs 项目: sethwebster/Jabbot
 public void StartUp()
 {
     _client.Connect(Name, _password).ContinueWith(task =>
     {
         if (!task.IsFaulted)
         {
             InitializeSprockets();
             WriteDebugInfo("Bot started. Initialized " + _sprockets.Count + " sprockets successfully.");
         }
         else
         {
             Console.WriteLine(task.Exception);
             WriteDebugInfo(task.Exception.GetBaseException().ToString());
         }
     }).Wait();
 }
示例#7
0
        public void PowerUp()
        {
            client.MessageReceived += (message, room) =>
            {
                Console.WriteLine("{0} {1} {2}", room, message.Content, message.User.Name);
                if (message.User.Name != Name)
                {
                    client.Send("Received " + message.Content + " from " + message.User.Name + " in " + room, room);
                }
            };


            client.Connect(Name, _password).ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    client.JoinRoom("twitterbot");
                }
                else
                {
                    Console.WriteLine(task.Exception);
                }
            });
        }
示例#8
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();
        }
示例#9
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,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHD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i4RUpAK0YzZApLY9BLvPVVb493F5LbPRoADBkIIwXuHsZbOGZtFPFq7G8PEcIhdNrMlax2AoeKbaK9t3uP9Si/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();
        }
示例#10
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();
        }
示例#11
0
        static void Main(string[] args)
        {

            




            string server = "http://jabbr.net/";
            string roomName = "test";

            var appDomain = "";






            var client = new JabbRClient(server, new SignalR.Client.Transports.LongPollingTransport());

            client.Connect("c47bba43-4992-4725-abc8-4dc9a6f3723d")
                .Then(logOnInfo =>
                {

                })
                    .OnError(ex =>
                    {

                    })
                    .Then(() =>
                    {

                    });

            //// 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();
        }
示例#12
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,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHD0lEQV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AK0YzZApLY9BLvPVVb493F5LbPRoADBkIIwXuHsZbOGZtFPFq7G8PEcIhdNrMlax2AoeKbaK9t3uP9Si/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();
        }
示例#13
0
        public async Task Connect()
        {
            await client.Connect(serverConfig.UserName, serverConfig.Password);

            Console.WriteLine("Connected to {0}.", serverConfig.ServerId);
        }