public void Open(string userId, FizzSessionRepository sessionRepository)
        {
            if (_connection != null)
            {
                return;
            }

            if (string.IsNullOrEmpty(userId))
            {
                throw FizzException.ERROR_INVALID_USER_ID;
            }
            if (sessionRepository == null)
            {
                throw FizzException.ERROR_INVALID_SESSION_REPOSITORY;
            }

            _userId      = userId;
            _sessionRepo = sessionRepository;
            _sessionRepo.OnSessionUpdate += OnSessionUpdate;

            lock (synclock)
            {
                _connection                  = CreateConnection();
                _connection.Connected       += OnConnConnected;
                _connection.Disconnected    += OnConnDisconnected;
                _connection.MessageReceived += OnMessage;
                _connection.ConnectAsync();
            }

            _closeCallback = null;
        }
Ejemplo n.º 2
0
        public void Close()
        {
            if (_connection == null)
            {
                return;
            }

            lock (synclock)
            {
                _sessionRepo.OnSessionUpdate -= OnSessionUpdate;
                _sessionRepo = null;
                var conn = _connection;
                _connection = null;
                conn.DisconnectAsync();
            }
        }
        public void Close(Action cb)
        {
            _closeCallback = cb;
            if (_connection == null)
            {
                FizzUtils.DoCallback(_closeCallback);
                _closeCallback = null;
                return;
            }

            lock (synclock)
            {
                _sessionRepo.OnSessionUpdate -= OnSessionUpdate;
                _sessionRepo = null;
                var conn = _connection;
                _connection = null;
                conn.DisconnectAsync();
            }
        }
        private void OnSessionUpdate()
        {
            try
            {
                if (_connection != null)
                {
                    var conn = _connection;
                    _connection = null;
                    conn.DisconnectAsync();
                }

                _connection                  = CreateConnection();
                _connection.Connected       += OnConnConnected;
                _connection.Disconnected    += OnConnDisconnected;
                _connection.MessageReceived += OnMessage;
                _connection.ConnectAsync();
            }
            catch (Exception e)
            {
                FizzLogger.E("Reconnect Session " + e);
            }
        }
Ejemplo n.º 5
0
        public void Open(string userId, FizzSessionRepository sessionRepository)
        {
            if (_connection != null)
            {
                return;
            }

            if (string.IsNullOrEmpty(userId))
            {
                throw FizzException.ERROR_INVALID_USER_ID;
            }
            if (sessionRepository == null)
            {
                throw FizzException.ERROR_INVALID_SESSION_REPOSITORY;
            }
            //if (string.IsNullOrEmpty(session._subscriberId))
            //{
            //    throw ERROR_INVALID_SUBSCRIBER_ID;
            //}
            //if (string.IsNullOrEmpty(session._token))
            //{
            //    throw ERROR_INVALID_SESSION_TOKEN;
            //}

            _userId      = userId;
            _sessionRepo = sessionRepository;
            _sessionRepo.OnSessionUpdate += OnSessionUpdate;

            lock (synclock)
            {
                _connection                  = CreateConnection();
                _connection.Connected       += OnConnConnected;
                _connection.Disconnected    += OnConnDisconnected;
                _connection.MessageReceived += OnMessage;
                _connection.ConnectAsync();
            }
        }