コード例 #1
0
ファイル: AblyRest.cs プロジェクト: jeddawson/ably-dotnet
        /// <summary>Initializes the rest client and validates the passed in options</summary>
        private void InitializeAbly()
        {
            if (Options == null)
            {
                Logger.Error("No options provider to Ably rest");
                throw new AblyException("Invalid options");
            }

            Logger = Options.Logger ?? IO.Ably.DefaultLogger.LoggerInstance;

            if (Options.LogLevel.HasValue)
            {
                Logger.LogLevel = Options.LogLevel.Value;
            }

            if (Options.LogHander != null)
            {
                Logger.LoggerSink = Options.LogHander;
            }

            Logger.Debug("Protocol set to: " + Protocol);
            MessageHandler = new MessageHandler(Protocol);

            HttpClient         = new AblyHttpClient(new AblyHttpOptions(Options));
            ExecuteHttpRequest = HttpClient.Execute;
            AblyAuth           = new AblyAuth(Options, this);
            Channels           = new RestChannels(this);
        }
コード例 #2
0
ファイル: AblyRest.cs プロジェクト: jeddawson/ably-dotnet
        internal async Task <AblyResponse> ExecuteRequest(AblyRequest request)
        {
            Logger.Debug("Sending {0} request to {1}", request.Method, request.Url);

            if (request.SkipAuthentication == false)
            {
                await AblyAuth.AddAuthHeader(request);
            }

            try
            {
                MessageHandler.SetRequestBody(request);
                return(await ExecuteHttpRequest(request));
            }
            catch (AblyException ex)
            {
                if (Logger.IsDebug)
                {
                    Logger.Debug("Error Executing request. Message: " + ex.Message);
                }

                if (ex.ErrorInfo.IsUnAuthorizedError &&
                    ex.ErrorInfo.IsTokenError && AblyAuth.TokenRenewable)
                {
                    if (Logger.IsDebug)
                    {
                        Logger.Debug("Handling UnAuthorized Error and repeating request.");
                    }

                    await AblyAuth.AuthoriseAsync(null, new AuthOptions()
                    {
                        Force = true
                    });

                    await AblyAuth.AddAuthHeader(request);

                    return(await ExecuteHttpRequest(request));
                }
                throw;
            }
            catch (Exception ex)
            {
                if (Logger.IsDebug)
                {
                    Logger.Debug("Error Executing request. Message: " + ex.Message);
                }

                throw new AblyException(ex);
            }
        }