コード例 #1
0
ファイル: RestClient.cs プロジェクト: lampersky/azure-signalr
        private HttpRequestMessage BuildRequest(RestApiEndpoint api, HttpMethod httpMethod, string productInfo, string methodName = null, object[] args = null)
        {
            var payload = httpMethod == HttpMethod.Post ? new PayloadMessage {
                Target = methodName, Arguments = args
            } : null;

            return(GenerateHttpRequest(api.Audience, api.Query, httpMethod, payload, api.Token, productInfo));
        }
コード例 #2
0
ファイル: RestClient.cs プロジェクト: Azure/azure-signalr
 private void AddTracingId(RestApiEndpoint api)
 {
     var id = MessageWithTracingIdHelper.Generate();
     if (api.Query == null)
     {
         api.Query = new Dictionary<string, StringValues>();
     }
     api.Query.Add(Constants.Headers.AsrsMessageTracingId, id.ToString());
 }
コード例 #3
0
        private async Task AuthorizeWithTokenAsync(string accessToken, CancellationToken token = default)
        {
            var api = new RestApiEndpoint(AuthorizeUrl, accessToken);

            await new RestClient().SendAsync(
                api,
                HttpMethod.Get,
                "",
                handleExpectedResponseAsync: HandleHttpResponseAsync,
                cancellationToken: token);
        }
コード例 #4
0
ファイル: AadAccessKey.cs プロジェクト: Azure/azure-signalr
        private async Task AuthorizeWithTokenAsync(string endpoint, int?port, string accessToken, CancellationToken token = default)
        {
            if (port != null && port != 443)
            {
                endpoint += $":{port}";
            }
            var api = new RestApiEndpoint(endpoint + "/api/v1/auth/accessKey", accessToken);

            await new RestClient().SendAsync(
                api,
                HttpMethod.Get,
                "",
                handleExpectedResponseAsync: HandleHttpResponseAsync,
                cancellationToken: token);
        }
コード例 #5
0
ファイル: RestClient.cs プロジェクト: lampersky/azure-signalr
        public Task SendAsync(
            RestApiEndpoint api,
            HttpMethod httpMethod,
            string productInfo,
            string methodName = null,
            object[] args     = null,
            Func <HttpResponseMessage, bool> handleExpectedResponse = null,
            CancellationToken cancellationToken = default)
        {
            if (handleExpectedResponse == null)
            {
                return(SendAsync(api, httpMethod, productInfo, methodName, args, handleExpectedResponseAsync: null, cancellationToken));
            }

            return(SendAsync(api, httpMethod, productInfo, methodName, args, response => Task.FromResult(handleExpectedResponse(response)), cancellationToken));
        }
コード例 #6
0
ファイル: RestClient.cs プロジェクト: Azure/azure-signalr
        public async Task SendAsync(
            RestApiEndpoint api,
            HttpMethod httpMethod,
            string productInfo,
            string methodName = null,
            object[] args = null,
            Func<HttpResponseMessage, Task<bool>> handleExpectedResponseAsync = null,
            CancellationToken cancellationToken = default)
        {
            using var httpClient = _httpClientFactory.CreateClient();
            using var request = BuildRequest(api, httpMethod, productInfo, methodName, args);
            HttpResponseMessage response = null;

            try
            {
                response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
                if (handleExpectedResponseAsync == null)
                {
                    await ThrowExceptionOnResponseFailureAsync(response);
                }
                else
                {
                    if (!await handleExpectedResponseAsync(response))
                    {
                        await ThrowExceptionOnResponseFailureAsync(response);
                    }
                }
            }
            catch (HttpRequestException ex)
            {
                throw new AzureSignalRInaccessibleEndpointException(request.RequestUri.ToString(), ex);
            }
            finally
            {
                response?.Dispose();
            }
        }