private HalHttpClient CreateHalHttpClient(HttpClient httpClient = null)
        {
            var client = new HalHttpClient(_parser, httpClient);

            try
            {
                Configure(client);
                return client;
            }
            catch (Exception)
            {
                client.Dispose(); // client is unusable ...
                throw;
            }
        }
        private void SetRoot(HalHttpClient client, Uri baseAddress, bool refresh)
        {
            try
            {
                if (refresh || (_root == null))
                    client.GetAsync(baseAddress)
                        .ContinueWith(x => _root = x.Result, TaskContinuationOptions.NotOnFaulted)
                        .Wait();

                client.Root = _root;
            }
            catch (AggregateException ex)
            {
                client.Dispose(); // client is unusable ...
                throw new Exception("Could not GET the root response from '" + baseAddress + "'.", ex.InnerExceptions.FirstOrDefault());
            }
        }
예제 #3
0
		private async Task<IHalHttpClient> CreateHalHttpClientAsync(HttpClient httpClient, CachingBehavior apiRootCachingBehavior)
		{
			var wrapped = new HalHttpClient(Parser, httpClient);

			try
			{
				Configure(wrapped.Configuration);

				var decorated = Decorate(wrapped) ?? wrapped;

				switch (apiRootCachingBehavior)
				{
					case CachingBehavior.Never:
						break;
					case CachingBehavior.PerClient:
						var apiRootResource = await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false);
						wrapped.CachedApiRootResource = apiRootResource;
						break;
					case CachingBehavior.Once:
						_cachedApiRootResource = _cachedApiRootResource ?? await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false);
						wrapped.CachedApiRootResource = _cachedApiRootResource;
						break;
					default:
						throw new ArgumentOutOfRangeException(nameof(apiRootCachingBehavior), apiRootCachingBehavior, null);
				}

				return decorated;
			}
			catch (Exception)
			{
				wrapped.Dispose(); // client is unusable ...
				throw;
			}
		}
예제 #4
0
		private IHalHttpClient CreateHalHttpClient(HttpClient httpClient)
		{
			if (httpClient == null)
				throw new ArgumentNullException(nameof(httpClient));

			var wrapped = new HalHttpClient(Parser, httpClient);

			try
			{
				Configure(wrapped.Configuration);

				var decorated = Decorate(wrapped) ?? wrapped;

				return decorated;
			}
			catch (Exception)
			{
				wrapped.Dispose(); // client is unusable ...
				throw;
			}
		}