Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Squidex/squidex-samples into sync
Browse files Browse the repository at this point in the history
# Conflicts:
#	csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Generated.cs
#	csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Squidex.ClientLibrary.csproj
  • Loading branch information
SebastianStehle committed Jan 29, 2019
2 parents 0b88fdf + 0e2564b commit a88e11c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 57 deletions.
12 changes: 0 additions & 12 deletions cli/Squidex.CLI/Squidex.CLI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<PackageReference Include="ConsoleTables" Version="2.2.0" />
<PackageReference Include="CommandDotNet" Version="2.7.7-beta" />
<PackageReference Include="CommandDotNet.IoC.MicrosoftDependencyInjection" Version="1.0.9" />
<PackageReference Include="CsvHelper" Version="12.1.1" />
<PackageReference Include="CsvHelper" Version="12.1.2" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="Squidex.ClientLibrary" Version="2.3.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

Expand All @@ -22,9 +23,5 @@
<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\csharp\Squidex.ClientLibrary\Squidex.ClientLibrary\Squidex.ClientLibrary.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System;
using System.Collections.Generic;

namespace Squidex.ClientLibrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Collections.Generic;

namespace Squidex.ClientLibrary
{
public sealed class AssetEntities : EntitiesBase<Asset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageIconUrl>https://raw.githubusercontent.com/Squidex/squidex/master/media/logo-squared.png</PackageIconUrl>
<PackageLicense>https://github.com/Squidex/squidex/blob/master/LICENSE.txt</PackageLicense>
<PackageProjectUrl>https://github.com/Squidex/squidex/</PackageProjectUrl>
<Version>2.0</Version>
<Version>2.3</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +19,8 @@ public sealed class SquidexClient<TEntity, TData> : 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));

Expand Down Expand Up @@ -73,6 +72,7 @@ public async Task<TEntity> 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<TEntity>();
}

Expand Down Expand Up @@ -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}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpResponseMessage> 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)
{
Expand Down Expand Up @@ -95,5 +85,10 @@ protected async Task EnsureResponseIsValidAsync(HttpResponseMessage response)
throw new SquidexException(message);
}
}

public void Dispose()
{
httpClient?.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down Expand Up @@ -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<TEntity, TData> GetClient<TEntity, TData>(string schemaName)
Expand All @@ -136,14 +133,14 @@ public SquidexClient<TEntity, TData> GetClient<TEntity, TData>(string schemaName
{
Guard.NotNullOrEmpty(schemaName, nameof(schemaName));

return new SquidexClient<TEntity, TData>(serviceUrl, applicationName, schemaName, messageHandler);
return new SquidexClient<TEntity, TData>(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 };
}
}
}

0 comments on commit a88e11c

Please sign in to comment.