Esempio n. 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);
        }
Esempio n. 2
0
 public override async void Attach(IRobot robo, CancellationToken token)
 {
     // Connect JabbR Client
     var client = new JabbRClient(Host.AbsoluteUri);
     try
     {
         robo.Log.Trace("Connecting to JabbR");
         var logOnInfo = await client.Connect(UserName, Password);
         robo.Log.Trace("Connection Established");
         robo.Log.Info("Jabbin in JabbR");
         await new JabbrListenerWorker(logOnInfo, client, Rooms, robo, UserName).Run(token);
     }
     catch (SecurityException)
     {
         robo.Log.Error("Invalid User Name or Password");
     }
     catch (Exception ex)
     {
         robo.Log.Error(ex.Message);
     }
 }
Esempio n. 3
0
        public override async Task Connect()
        {
            OnConnecting(EventArgs.Empty);

            if (string.IsNullOrEmpty(Address))
            {
                OnConnectError(new ConnectionErrorEventArgs(this, new Exception("Address is empty")));
                return;
            }
            if (UseSocialLogin)
            {
                if (string.IsNullOrEmpty(UserId))
                {
                    OnConnectError(new ConnectionErrorEventArgs(this, new NotAuthenticatedException("Not authenticated to this server")));
                    return;
                }
            }
            else if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
            {
                OnConnectError(new ConnectionErrorEventArgs(this, new NotAuthenticatedException("Username or password are not specified")));
                return;
            }

            //ServicePointManager.FindServicePoint (new Uri (Address)).ConnectionLimit = 100;

            // force long polling on mono, until SSE works reliably
            IClientTransport transport;
            if (EtoEnvironment.Platform.IsMono)
                transport = new LongPollingTransport();
            else
                transport = new AutoTransport(new DefaultHttpClient());

            Client = new jab.JabbRClient(Address, null, transport);

            if (UseSocialLogin)
            {
                throw new NotSupportedException();
            }

            bool connected = false;
            try
            {
                var logOnInfo = await Client.Connect(UserName, Password);
#if DEBUG
                var settings = Path.Combine(EtoEnvironment.GetFolderPath(EtoSpecialFolder.ApplicationSettings), "jabbreto.log");
                Client.Connection.TraceWriter = new TextWriterTraceListener(settings).Writer;
                Client.Connection.TraceLevel = TraceLevels.All;
#endif
                highlighRegex = null;
                connected = true;
                HookupEvents();

                this.OnGlobalMessageReceived (new NotificationEventArgs(new NotificationMessage (string.Format ("Using {0} transport", Client.Connection.Transport.Name))));
                var userInfo = await Client.GetUserInfo();
                this.CurrentUser = new JabbRUser(this, userInfo);
                loadingRooms = logOnInfo.Rooms.Select(r => new JabbRRoom(this, r)).ToList();
                InitializeChannels(loadingRooms);
                OnConnected(EventArgs.Empty);
            }
            catch (Exception ex)
            {
                Debug.Print(string.Format("Error: {0}", ex.GetBaseException().Message));
                OnConnectError(new ConnectionErrorEventArgs(this, ex));
                if (connected)
                    Client.Disconnect();
            }

            // load all room initial channel info/history
            while (true)
            {
                JabbRRoom room;
                lock (loadingRooms)
                {
                    if (loadingRooms.Count > 0)
                    {
                        room = loadingRooms[0];
                        loadingRooms.Remove(room);
                    }
                    else
                        break;
                }
                //Debug.WriteLine(string.Format("Loading messages for room {0}", room.Name));
                await room.LoadRoomInfo();
            }
        }
Esempio n. 4
0
		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));
			}
		}
Esempio n. 5
0
		public override void Connect ()
		{
			OnConnecting (EventArgs.Empty);

			if (string.IsNullOrEmpty (Address)) {
				OnConnectError (new ConnectionErrorEventArgs (this, new Exception ("Address is empty")));
				return;
			}
			if (UseSocialLogin) {
				if (string.IsNullOrEmpty (UserId)) {
					OnConnectError (new ConnectionErrorEventArgs (this, new NotAuthenticatedException ("Not authenticated to this server")));
					return;
				}
			} else if (string.IsNullOrEmpty (UserName) || string.IsNullOrEmpty (Password)) {
				OnConnectError (new ConnectionErrorEventArgs (this, new NotAuthenticatedException ("Username or password are not specified")));
				return;
			}

			ServicePointManager.FindServicePoint(new Uri(Address)).ConnectionLimit = 100;
			
			Client = new jab.JabbRClient (Address);//, new ServerSentEventsTransport());//new LongPollingTransport ());
			HookupEvents ();
			 
			if (UseSocialLogin) {
				connect = Client.Connect (UserId);
			} else {
				connect = Client.Connect (UserName, Password);
			}
				
			connect.ContinueWith (connectTask => {
				if (connectTask.IsFaulted) {
					Debug.WriteLine ("Error: {0}", connectTask.Exception);
					OnConnectError (new ConnectionErrorEventArgs(this, connectTask.Exception));
					return;
				}
				var logOnInfo = connectTask.Result;
				
				Client.GetUserInfo ().ContinueWith (userTask => {
					if (userTask.Exception != null) {
						OnConnectError (new ConnectionErrorEventArgs(this, connectTask.Exception));
						Client.Disconnect ();
						return;
					}
					this.CurrentUser = new JabbRUser (userTask.Result);
					
					InitializeChannels (logOnInfo.Rooms.Select (r => new JabbRRoom (this, r)));
					connect = null;
					OnConnected (EventArgs.Empty);
					
				});
			});
		}
Esempio n. 6
0
        public override async Task Connect()
        {
            OnConnecting(EventArgs.Empty);

            if (string.IsNullOrEmpty(Address))
            {
                OnConnectError(new ConnectionErrorEventArgs(this, new Exception("Address is empty")));
                return;
            }
            if (UseSocialLogin)
            {
                if (string.IsNullOrEmpty(UserId))
                {
                    OnConnectError(new ConnectionErrorEventArgs(this, new NotAuthenticatedException("Not authenticated to this server")));
                    return;
                }
            }
            else if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
            {
                OnConnectError(new ConnectionErrorEventArgs(this, new NotAuthenticatedException("Username or password are not specified")));
                return;
            }

            //ServicePointManager.FindServicePoint (new Uri (Address)).ConnectionLimit = 100;

            // force long polling on mono, until SSE works reliably
            Func <IClientTransport> transport;

            /*if (EtoEnvironment.Platform.IsMono)
             *  transport = () => new LongPollingTransport();
             * else*/
            transport = () => new AutoTransport(new DefaultHttpClient());

            Client = new jab.JabbRClient(Address, transport);
#if DEBUG
            var settings = Path.Combine(EtoEnvironment.GetFolderPath(EtoSpecialFolder.ApplicationSettings), "jabbr.log");
            Client.TraceWriter = new TextWriterTraceListener(settings).Writer;
            Client.TraceLevel  = TraceLevels.All;
#endif

            if (UseSocialLogin)
            {
                throw new NotSupportedException();
            }

            bool connected = false;
            try
            {
                var logOnInfo = await Client.Connect(UserName, Password);

                highlighRegex = null;
                connected     = true;
                HookupEvents();

                OnGlobalMessageReceived(new NotificationEventArgs(new NotificationMessage(string.Format("Using {0} transport", Client.Connection.Transport.Name))));
                var userInfo = await Client.GetUserInfo();

                CurrentUser  = new JabbRUser(this, userInfo);
                loadingRooms = logOnInfo.Rooms.Select(r => new JabbRRoom(this, r)).ToList();
                InitializeChannels(loadingRooms);

                if (EtoEnvironment.Platform.IsMono)
                {
                    var keepAliveTime = TimeSpan.FromMinutes(5);
                    if (timer != null)
                    {
                        timer.Dispose();
                    }
                    timer = new Timer(state => Client.Send(new jm.ClientMessage
                    {
                        Id      = Guid.NewGuid().ToString(),
                        Content = string.Format("/where {0}", CurrentUser.Name)
                    }), null, keepAliveTime, keepAliveTime);
                }

                OnConnected(EventArgs.Empty);
            }
            catch (Exception ex)
            {
                Debug.Print(string.Format("Error: {0}", ex.GetBaseException().Message));
                OnConnectError(new ConnectionErrorEventArgs(this, ex));
                if (connected)
                {
                    Client.Disconnect();
                }
            }

            // load all room initial channel info/history
            while (true)
            {
                JabbRRoom room;
                lock (loadingRooms)
                {
                    if (loadingRooms.Count > 0)
                    {
                        room = loadingRooms[0];
                        loadingRooms.Remove(room);
                    }
                    else
                    {
                        break;
                    }
                }
                //Debug.WriteLine(string.Format("Loading messages for room {0}", room.Name));
                await room.LoadRoomInfo();
            }
        }