Esempio n. 1
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));
                                     });
        }
Esempio n. 2
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. 3
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. 4
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();
            }
        }