Beispiel #1
0
        public void Open(string userId, IFizzAuthRestClient client, FizzSessionRepository sessionRepository)
        {
            IfClosed(() =>
            {
                if (string.IsNullOrEmpty(userId))
                {
                    throw FizzException.ERROR_INVALID_USER_ID;
                }
                if (client == null)
                {
                    throw ERROR_INVALID_REST_CLIENT;
                }
                if (sessionRepository == null)
                {
                    throw FizzException.ERROR_INVALID_SESSION_REPOSITORY;
                }

                if (_userId == userId)
                {
                    return;
                }

                _userId     = userId;
                _restClient = client;

                _messageListener.Open(userId, sessionRepository);
            });
        }
        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;
        }
Beispiel #3
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();
            }
        }
Beispiel #5
0
        public void Open(string userId, IFizzLanguageCode locale, FizzServices services, Action <FizzException> callback)
        {
            try
            {
                if (State == FizzClientState.Opened)
                {
                    FizzUtils.DoCallback(null, callback);
                    return;
                }

                FizzSessionRepository sessionRepo = new FizzSessionRepository(userId, locale.Code, _sessionClient);
                _authClient.Open(sessionRepo, ex =>
                {
                    if (ex == null)
                    {
                        if (services.HasFlag(FizzServices.Chat))
                        {
                            _chat.Open(userId, _authClient, sessionRepo);
                        }
                        if (services.HasFlag(FizzServices.Analytics))
                        {
                            _ingestionClient.Open(userId, sessionRepo.Session._serverTS, _authClient);
                        }
                        if (services.HasFlag(FizzServices.Moderation))
                        {
                            _moderationClient.Open(_authClient);
                        }

                        State = FizzClientState.Opened;
                        FizzUtils.DoCallback(null, callback);
                    }
                    else
                    {
                        FizzUtils.DoCallback(ex, callback);
                    }
                });
            }
            catch (FizzException ex)
            {
                FizzUtils.DoCallback(ex, callback);
            }
        }
Beispiel #6
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();
            }
        }