Skip to content

Commit

Permalink
Code reorganisation on webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Quiles committed Aug 30, 2017
1 parent 32dc79d commit 9c41a1a
Show file tree
Hide file tree
Showing 35 changed files with 220 additions and 230 deletions.
13 changes: 0 additions & 13 deletions Skeleton.Abstraction/Dependency/IOwinBootstrapper.cs

This file was deleted.

1 change: 0 additions & 1 deletion Skeleton.Abstraction/Skeleton.Abstraction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<Compile Include="Data\IDatabaseTransaction.cs" />
<Compile Include="Data\ISqlCommand.cs" />
<Compile Include="Dependency\DependencyLifetime.cs" />
<Compile Include="Dependency\IOwinBootstrapper.cs" />
<Compile Include="Domain\IEntityDescriptor.cs" />
<Compile Include="Domain\IEntityAuditable.cs" />
<Compile Include="Domain\IValidationRule.cs" />
Expand Down
8 changes: 2 additions & 6 deletions Skeleton.Infrastructure.Data/ExponentialRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class ExponentialRetryPolicy

internal static readonly TimeSpan DefaultMaxBackoff = TimeSpan.FromSeconds(30.0);
internal static readonly TimeSpan DefaultMinBackoff = TimeSpan.FromSeconds(1.0);
internal static readonly bool FirstFastRetry = true;

private int _currentRetry;

internal ExponentialRetryPolicy(IDatabaseConfiguration configuration, ILogger logger)
Expand Down Expand Up @@ -83,11 +83,7 @@ internal async Task<T> ExecuteAsync<T>(Func<Task<T>> func)
private TimeSpan CalculateExponentialBackoff()
{
var defaultInterval = TimeSpan.FromSeconds(_configuration.RetryInterval);

if (FirstFastRetry && _currentRetry == 0)
return defaultInterval;

int randomInterval = GetRandomInterval(defaultInterval);
var randomInterval = GetRandomInterval(defaultInterval);
var delta = (int)(Math.Pow(2.0, _currentRetry) * randomInterval);
var interval = (int)Math.Min(checked(DefaultMinBackoff.TotalMilliseconds + delta), DefaultMaxBackoff.TotalMilliseconds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public sealed class DatabaseConfiguration :
HideObjectMethodsBase,
IDatabaseConfiguration
{
private static readonly int DefaultTimeout = 300;
private static readonly int DefaultRetryCount = 10;
private static readonly int DefaultRetryInterval = 1;
private static readonly string DefaultProvider = "System.Data.SqlClient";
private static readonly string DefaultName = "Default";
private const int DefaultTimeout = 300;
private const int DefaultRetryCount = 10;
private const int DefaultRetryInterval = 1;
private const string DefaultProvider = "System.Data.SqlClient";
private const string DefaultName = "Default";

private int _commandTimeout;
private int _retryCount;
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Infrastructure.Orm/SqlBuilder/QueryEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void EvaluateOrderBy()
var orderByFields = _query.OrderBy.Split(',');
foreach (var field in orderByFields)
{
if (field.StartsWith("-", StringComparison.InvariantCultureIgnoreCase))
if (field.StartsWith("-", StringComparison.OrdinalIgnoreCase))
{
var propertyName = field.Substring(1);
var evaluatedExpression = EvaluateProperty(propertyName);
Expand Down
16 changes: 9 additions & 7 deletions Skeleton.Tests.Common/AppConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Skeleton.Web.Client;
using System;
using System;

namespace Skeleton.Tests.Common
{
public static class AppConfiguration
{
public const string CustomersResource = "customers";
public const string CachedCustomersResource = "cachedcustomers";
public const string AsyncCustomersResource = "asynccustomers";
public const string AsyncCachedCustomersResource = "asynccachedcustomers";
public const string LogResource = "log";
public const string CustomersResource = "api/customers";
public const string CachedCustomersResource = "api/cachedcustomers";
public const string AsyncCustomersResource = "api/asynccustomers";
public const string AsyncCachedCustomersResource = "api/asynccachedcustomers";

public static bool AppVeyorBuild => Environment.GetEnvironmentVariable("AppVeyor")?.ToUpperInvariant() == "TRUE";

Expand All @@ -20,5 +18,9 @@ public static class AppConfiguration
public static string Host => "localhost";
public static int Port => 8081;
public static Uri BaseAddress => new UriBuilder("http", Host, Port).Uri;
public static Uri CustomersUri => new Uri(BaseAddress, new Uri(CustomersResource, UriKind.Relative));
public static Uri CachedCustomersUri => new Uri(BaseAddress, new Uri(CachedCustomersResource, UriKind.Relative));
public static Uri AsyncCustomersUri => new Uri(BaseAddress, new Uri(AsyncCustomersResource, UriKind.Relative));
public static Uri AsyncCachedCustomersUri => new Uri(BaseAddress, new Uri(AsyncCachedCustomersResource, UriKind.Relative));
}
}
4 changes: 0 additions & 4 deletions Skeleton.Tests.Common/OwinTestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public void Start(Uri baseUrl)
var startup = new OwinStartup();
_server = startup.StartServer(baseUrl,
bootstrapper => bootstrapper
.UseSwagger()
.UseCheckModelForNull()
.UseValidateModelState()
.UseGlobalExceptionHandling()
.UseSqlServer(_databaseConfigurator)
.WithOrm());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HttpClientAsyncCachedEntityReaderTests
private const int PageSize = 50;
private const int NumberOfPages = 5;

private readonly RestClient _client = new RestClient(new Uri(AppConfiguration.BaseAddress, "api/asynccachedcustomers"));
private readonly RestClient _client = new RestClient(AppConfiguration.AsyncCachedCustomersUri);

[Test]
public async Task CachedEntityReader_GetAllAsync()
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Tests.Web/HttpClientAsyncEntityReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HttpClientAsyncEntityReaderTests
private const int PageSize = 50;
private const int NumberOfPages = 5;

private readonly RestClient _client = new RestClient(new Uri(AppConfiguration.BaseAddress, "api/asynccustomers"));
private readonly RestClient _client = new RestClient(AppConfiguration.AsyncCustomersUri);

[Test]
public async Task EntityReader_GetAllAsync()
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Tests.Web/HttpClientAsyncEntityWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Skeleton.Tests.Web
[TestFixture]
public class HttpClientAsyncEntityWriterTests
{
private readonly RestClient _client = new RestClient(new Uri(AppConfiguration.BaseAddress, "api/asynccustomers"));
private readonly RestClient _client = new RestClient(AppConfiguration.AsyncCustomersUri);

[Test]
public async Task EntityWriter_UpdateAsync()
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Tests.Web/HttpClientCachedEntityReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class HttpClientCachedEntityReaderTests
private const int PageSize = 50;
private const int NumberOfPages = 5;

private readonly RestClient _client = new RestClient(new Uri(AppConfiguration.BaseAddress, "api/cachedcustomers"));
private readonly RestClient _client = new RestClient(AppConfiguration.CachedCustomersUri);

[Test]
public void EntityReader_GetAll()
Expand Down
6 changes: 2 additions & 4 deletions Skeleton.Tests.Web/HttpClientEntityReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using NUnit.Framework;
using Skeleton.Tests.Common;
using Skeleton.Web.Client;
using System;
using System.Linq;
using System.Net;

Expand All @@ -13,8 +12,7 @@ public class HttpClientEntityReaderTests
private const int PageSize = 50;
private const int NumberOfPages = 5;

private readonly RestClient _client = new RestClient(new Uri(AppConfiguration.BaseAddress, "api/customers"));

private readonly RestClient _client = new RestClient(AppConfiguration.CustomersUri);

[Test]
public void EntityReader_GetAll()
Expand Down Expand Up @@ -90,7 +88,7 @@ public void EntityReader_Retry()
{
var request = new RestRequest()
.AddResource("retry");
var response = _client.Get(request);
_client.Get(request);

Assert.IsTrue(_client.RetryPolicy.RetryCount == 5);
}
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Tests.Web/HttpClientEntityWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Skeleton.Tests.Web
[TestFixture]
public class HttpClientEntityWriterTests
{
private readonly RestClient _client = new RestClient(new Uri(AppConfiguration.BaseAddress, "api/customers"), new NoRetryPolicy());
private readonly RestClient _client = new RestClient(AppConfiguration.CustomersUri);

[Test]
public void EntityWriter_Update()
Expand Down
1 change: 0 additions & 1 deletion Skeleton.Tests.Web/HttpClientHealthCheckTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using NUnit.Framework;
using Skeleton.Tests.Common;
using Skeleton.Web.Client;
using System;

namespace Skeleton.Tests.Web
{
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Web.Client/ClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static bool RemoveClient(string key)
private static void EnsureKeyNotNullOrEmpty(string key)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentException(nameof(key));
throw new ArgumentException("Key cannot be null or empty", nameof(key));
}
}
}
7 changes: 4 additions & 3 deletions Skeleton.Web.Client/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Skeleton.Web.Client
{
public sealed class RestRequest : IRestRequest
{
private const string Message = "Resource cannot be null or empty";
private readonly static SupportedFormatters Formatters = new SupportedFormatters();

public RestRequest()
Expand All @@ -18,7 +19,7 @@ public RestRequest()
public RestRequest(string resource)
{
if (string.IsNullOrEmpty(resource))
throw new ArgumentException(nameof(resource));
throw new ArgumentException(Message, nameof(resource));

Resource = EnsureTrailingSlash(resource);
}
Expand Down Expand Up @@ -75,7 +76,7 @@ public IRestRequest AsGet()
public IRestRequest AddResource(string resource)
{
if (string.IsNullOrEmpty(resource))
throw new ArgumentException(nameof(resource));
throw new ArgumentException(Message, nameof(resource));

if (!string.IsNullOrEmpty(Resource))
Resource = EnsureTrailingSlash(Resource);
Expand All @@ -88,7 +89,7 @@ public IRestRequest AddResource(string resource)
public IRestRequest AddQueryParameter(string key, object value)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentException(nameof(key));
throw new ArgumentException(Message, nameof(key));

if (value == null)
throw new ArgumentNullException(nameof(value));
Expand Down
2 changes: 1 addition & 1 deletion Skeleton.Web.Server/Configuration/CompressionMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Owin;
using Skeleton.Core;
using Skeleton.Web.Server.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
5 changes: 1 addition & 4 deletions Skeleton.Web.Server/Configuration/RequestIdMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Microsoft.Owin;
using Skeleton.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skeleton.Web.Server.Helpers;
using System.Threading.Tasks;

namespace Skeleton.Web.Server.Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Owin;
using Skeleton.Abstraction;
using Skeleton.Core;
using Skeleton.Web.Server.Helpers;
using System.Diagnostics;
using System.Threading.Tasks;

Expand Down
2 changes: 0 additions & 2 deletions Skeleton.Web.Server/Configuration/RequireSslMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Skeleton.Web.Server.Configuration
{
public sealed class RequireSslMiddleware: OwinMiddleware
{
private readonly OwinMiddleware _next;

public RequireSslMiddleware(OwinMiddleware next)
: base(next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Skeleton.Abstraction.Domain;
using Skeleton.Abstraction.Orm;
using Skeleton.Core;
using Skeleton.Web.Server.Helpers;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
Expand Down
3 changes: 2 additions & 1 deletion Skeleton.Web.Server/Controllers/DiscoverController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Skeleton.Web.Server.Helpers;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

Expand Down
1 change: 1 addition & 0 deletions Skeleton.Web.Server/Controllers/EntityReaderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Skeleton.Abstraction.Domain;
using Skeleton.Abstraction.Orm;
using Skeleton.Core;
using Skeleton.Web.Server.Helpers;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Description;
Expand Down
1 change: 1 addition & 0 deletions Skeleton.Web.Server/Controllers/LogController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Skeleton.Abstraction;
using Skeleton.Web.Server.Helpers;
using System.Web.Http;

namespace Skeleton.Web.Server.Controllers
Expand Down
Binary file removed Skeleton.Web.Server/GlobalSuppressions.cs
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;
using System.IO.Compression;

namespace Skeleton.Web.Server.Configuration
namespace Skeleton.Web.Server.Helpers
{
public class DeflateCompressor : ICompressor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;
using System.IO.Compression;

namespace Skeleton.Web.Server.Configuration
namespace Skeleton.Web.Server.Helpers
{
public class GZipCompressor : ICompressor
{
Expand Down
Loading

0 comments on commit 9c41a1a

Please sign in to comment.