Beispiel #1
0
        private ApiMessageHandler GetMessageHandler(ICredentials credentials)
        {
            var messageHandler = new ApiMessageHandler(true);

            messageHandler.Credentials     = credentials;
            messageHandler.PreAuthenticate = true;

            return(messageHandler);
        }
Beispiel #2
0
        /// <summary>The get compute api client.</summary>
        /// <param name="geoKey">The geo Key.</param>
        /// <param name="credentials">The User credentials</param>
        /// <param name="logFile">The Log File Path</param>
        /// <param name="connectionName">The Connection Name</param>
        /// <returns>The <see cref="IComputeApiClient"/>.</returns>
        private IComputeApiClient GetComputeApiClient(Uri baseUri, ApiMessageHandler messageHandler)
        {
            // Handle disposing the message handler
            var httpClient = new HttpClientAdapter(
                new HttpClient(messageHandler, disposeHandler: true)
            {
                BaseAddress = baseUri,
                Timeout     = TimeSpan.FromMinutes(5),
            });

            // we will not try to login again, assuming the clientId remains the same accross the regions
            return(new ComputeApiClient(httpClient));
        }
        // internal TraceHttpRequest OnRequestStarted;

        /// <summary>
        /// Initialises a new instance of the <see cref="ComputeServiceConnection"/> class.
        ///     Create a new compute service connection.
        /// </summary>
        /// <param name="apiClient">
        /// The CaaS API client represented by the connection.
        /// </param>
        public ComputeServiceConnection(IComputeApiClient apiClient, ApiMessageHandler messageHandler)
        {
            MessageHandler = messageHandler;
            if (apiClient == null)
            {
                throw new ArgumentNullException("apiClient");
            }
            ApiClient = apiClient;

            MessageHandler.LogEventHandler += (requestMethod, requestUri, responseStatusCode, timeTaken, userName, requestContent, responseContent) =>
            {
                OnRequestStart?.Invoke(requestMethod, requestUri, responseStatusCode, timeTaken, userName, requestContent, responseContent);
            };
        }