diff --git a/cli/Squidex.CLI/Squidex.CLI.sln b/cli/Squidex.CLI/Squidex.CLI.sln index 98f75d56..d6829cf5 100644 --- a/cli/Squidex.CLI/Squidex.CLI.sln +++ b/cli/Squidex.CLI/Squidex.CLI.sln @@ -5,10 +5,6 @@ VisualStudioVersion = 15.0.28307.168 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.CLI", "Squidex.CLI\Squidex.CLI.csproj", "{2D435C5F-73FB-47F6-BEDA-49E9F9D8E9F7}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.ClientLibrary", "..\..\csharp\Squidex.ClientLibrary\Squidex.ClientLibrary\Squidex.ClientLibrary.csproj", "{B623BB78-2560-4186-9CAE-01ECAD2BA466}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGeneration", "..\..\csharp\Squidex.ClientLibrary\CodeGeneration\CodeGeneration.csproj", "{F6C236D0-E84A-4B8C-9609-9FC15E95F683}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,14 +15,6 @@ Global {2D435C5F-73FB-47F6-BEDA-49E9F9D8E9F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {2D435C5F-73FB-47F6-BEDA-49E9F9D8E9F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {2D435C5F-73FB-47F6-BEDA-49E9F9D8E9F7}.Release|Any CPU.Build.0 = Release|Any CPU - {B623BB78-2560-4186-9CAE-01ECAD2BA466}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B623BB78-2560-4186-9CAE-01ECAD2BA466}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B623BB78-2560-4186-9CAE-01ECAD2BA466}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B623BB78-2560-4186-9CAE-01ECAD2BA466}.Release|Any CPU.Build.0 = Release|Any CPU - {F6C236D0-E84A-4B8C-9609-9FC15E95F683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F6C236D0-E84A-4B8C-9609-9FC15E95F683}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F6C236D0-E84A-4B8C-9609-9FC15E95F683}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F6C236D0-E84A-4B8C-9609-9FC15E95F683}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj b/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj index 7cb592c4..de8e2fc3 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj +++ b/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj @@ -10,8 +10,9 @@ - + + @@ -22,9 +23,5 @@ - - - - diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Asset.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Asset.cs index eb533e88..9bcfde33 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Asset.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Asset.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Collections.Generic; namespace Squidex.ClientLibrary diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetEntities.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetEntities.cs index 040e2da9..7eb699d6 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetEntities.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetEntities.cs @@ -5,8 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System.Collections.Generic; - namespace Squidex.ClientLibrary { public sealed class AssetEntities : EntitiesBase diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Squidex.ClientLibrary.csproj b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Squidex.ClientLibrary.csproj index 7f90e3ca..522322e5 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Squidex.ClientLibrary.csproj +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Squidex.ClientLibrary.csproj @@ -10,7 +10,7 @@ https://raw.githubusercontent.com/Squidex/squidex/master/media/logo-squared.png https://github.com/Squidex/squidex/blob/master/LICENSE.txt https://github.com/Squidex/squidex/ - 2.0 + 2.3 true diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexAssetClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexAssetClient.cs index 2da1d3a6..2cfdcb20 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexAssetClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexAssetClient.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Collections.Generic; using System.IO; using System.Net; @@ -19,8 +18,8 @@ namespace Squidex.ClientLibrary { public sealed class SquidexAssetClient : SquidexClientBase { - public SquidexAssetClient(Uri serviceUrl, string applicationName, string schemaName, HttpMessageHandler messageHandler) - : base(serviceUrl, applicationName, schemaName, messageHandler) + public SquidexAssetClient(string applicationName, HttpClient httpClient) + : base(applicationName, httpClient) { } @@ -157,12 +156,12 @@ public async Task DeleteAssetAsync(string id) private string BuildAssetsUrl(string path = "") { - return $"api/assets/{path}"; + return $"assets/{path}"; } private string BuildAppAssetsUrl(string path = "") { - return $"api/apps/{ApplicationName}/assets/{path}"; + return $"apps/{ApplicationName}/assets/{path}"; } private static MultipartFormDataContent BuildRequest(string contentName, string contentMimeType, Stream stream) diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs index 3a2426ec..0a039e48 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; @@ -20,8 +19,8 @@ public sealed class SquidexClient : SquidexClientBase { public string SchemaName { get; } - public SquidexClient(Uri serviceUrl, string applicationName, string schemaName, HttpMessageHandler messageHandler) - : base(serviceUrl, applicationName, schemaName, messageHandler) + public SquidexClient(string applicationName, string schemaName, HttpClient httpClient) + : base(applicationName, httpClient) { Guard.NotNullOrEmpty(schemaName, nameof(schemaName)); @@ -73,6 +72,7 @@ public async Task GetAsync(string id, QueryContext context = null) Guard.NotNullOrEmpty(id, nameof(id)); var response = await RequestAsync(HttpMethod.Get, BuildContentUrl($"{id}/"), context: context); + return await response.Content.ReadAsJsonAsync(); } @@ -184,7 +184,7 @@ public async Task DeleteAsync(TEntity entity) private string BuildContentUrl(string path = "") { - return $"api/content/{ApplicationName}/{SchemaName}/{path}"; + return $"content/{ApplicationName}/{SchemaName}/{path}"; } } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientBase.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientBase.cs index 0a02d056..c5f5498f 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientBase.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientBase.cs @@ -12,47 +12,37 @@ namespace Squidex.ClientLibrary { - public abstract class SquidexClientBase + public abstract class SquidexClientBase : IDisposable { - private readonly HttpMessageHandler messageHandler; - - protected Uri ServiceUrl { get; } + private readonly HttpClient httpClient; protected string ApplicationName { get; } - protected SquidexClientBase(Uri serviceUrl, string applicationName, string schemaName, HttpMessageHandler messageHandler) + protected SquidexClientBase(string applicationName, HttpClient httpClient) { - Guard.NotNull(serviceUrl, nameof(serviceUrl)); - Guard.NotNull(messageHandler, nameof(messageHandler)); Guard.NotNullOrEmpty(applicationName, nameof(applicationName)); - - this.messageHandler = messageHandler; + Guard.NotNull(httpClient, nameof(httpClient)); ApplicationName = applicationName; - ServiceUrl = serviceUrl; + this.httpClient = httpClient; } protected async Task RequestAsync(HttpMethod method, string path, HttpContent content = null, QueryContext context = null) { - using (var httpClient = new HttpClient(messageHandler)) + using (var request = BuildRequest(method, path, content, context)) { - var uri = new Uri(ServiceUrl, path); - - using (var request = BuildRequest(method, uri, content, context)) - { - var response = await httpClient.SendAsync(request); + var response = await httpClient.SendAsync(request); - await EnsureResponseIsValidAsync(response); + await EnsureResponseIsValidAsync(response); - return response; - } + return response; } } - protected static HttpRequestMessage BuildRequest(HttpMethod method, Uri uri, HttpContent content, QueryContext context = null) + protected static HttpRequestMessage BuildRequest(HttpMethod method, string path, HttpContent content, QueryContext context = null) { - var request = new HttpRequestMessage(method, uri); + var request = new HttpRequestMessage(method, path); if (content != null) { @@ -95,5 +85,10 @@ protected async Task EnsureResponseIsValidAsync(HttpResponseMessage response) throw new SquidexException(message); } } + + public void Dispose() + { + httpClient?.Dispose(); + } } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs index 269ed11f..7fa29388 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs @@ -19,7 +19,6 @@ public sealed class SquidexClientManager private readonly string applicationName; private readonly Uri serviceUrl; private readonly IAuthenticator authenticator; - private readonly HttpMessageHandler messageHandler; public string App { @@ -45,8 +44,6 @@ public SquidexClientManager(Uri serviceUrl, string applicationName, IAuthenticat this.authenticator = authenticator; this.applicationName = applicationName; this.serviceUrl = serviceUrl; - - messageHandler = new AuthenticatingHttpClientHandler(authenticator); } public string GenerateImageUrl(string id) @@ -127,7 +124,7 @@ public IUsersClient CreateUsersClient() public SquidexAssetClient GetAssetClient() { - return new SquidexAssetClient(serviceUrl, applicationName, string.Empty, messageHandler); + return new SquidexAssetClient(applicationName, CreateHttpClient()); } public SquidexClient GetClient(string schemaName) @@ -136,14 +133,14 @@ public SquidexClient GetClient(string schemaName { Guard.NotNullOrEmpty(schemaName, nameof(schemaName)); - return new SquidexClient(serviceUrl, applicationName, schemaName, messageHandler); + return new SquidexClient(applicationName, schemaName, CreateHttpClient()); } private HttpClient CreateHttpClient() { var url = new Uri(serviceUrl, "/api/"); - return new HttpClient(messageHandler) { BaseAddress = url }; + return new HttpClient(new AuthenticatingHttpClientHandler(authenticator), false) { BaseAddress = url }; } } }