예제 #1
0
        private Task<LogOnInfo> Connect(JabbRClient client, JabbrCommand command)
        {
            if (string.IsNullOrWhiteSpace(command.UserId))
                return client.Connect(command.Username, command.Password);

            return client.Connect(command.UserId);
        }
예제 #2
0
        private void BroadCastToRooms(JabbrCommand command, Task<User> u, JabbRClient client)
        {
            var user = u.Result;

            foreach (string room in command.Rooms)
                SendMessagesToRoom(command, client, user, room);
        }
예제 #3
0
        public void Send(JabbrCommand command)
        {
            var client = new JabbRClient(command.Host);

            var connect = Connect(client, command);
            connect.ContinueWith(c =>
                                     {
                                         client.GetUserInfo()
                                             .ContinueWith(u => BroadCastToRooms(command, u, client));
                                     });
        }
예제 #4
0
        private void SendMessagesToRoom(JabbrCommand command, JabbRClient client, User user, string roomName)
        {
            client.GetRoomInfo(roomName).
                ContinueWith(r =>
                                 {
                                     Room info = r.Result;
                                     bool userInRoom = info.Users.Any(usr => usr.Name == user.Name);

                                     if (userInRoom)
                                     {
                                         Send(client,roomName, command.GetMessages());
                                         return;
                                     }

                                     Action leave = () => client.LeaveRoom(roomName);

                                     client.JoinRoom(roomName)
                                         .ContinueWith(j => Send(client, roomName, command.GetMessages(), leave));
                                 });
        }
예제 #5
0
        public JabbrCommand GetCommand(string repo)
        {
            dynamic @default = Value.@default ?? Json.Convert("{}");
            dynamic specific = Value[repo] ?? Json.Convert("{}");

            if(@default == null && specific == null)
                throw new InvalidOperationException("Invalid configuration");

            var command = new JabbrCommand
                       {
                           Host = specific.jabbr ?? @default.jabbr,
                           UserId = specific.userid ?? @default.userid,
                           Username = specific.user ?? @default.user,
                           Password = specific.password ?? @default.password,
                           Template = specific.template ?? @default.template ?? DEFAULTTEMPLATE
                       };

            foreach(string room in (specific.rooms ?? @default.rooms))
                command.Rooms.Add(room);

            command.Validate();

            return command;
        }