Skip to content

Commit

Permalink
netstandard2.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
davidni committed May 10, 2018
1 parent aa3de16 commit b1641e0
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Ocelot.Configuration.File;
using Ocelot.Infrastructure;
using Ocelot.Infrastructure.Extensions;
using Ocelot.Logging;
using Ocelot.Middleware;
using Ocelot.Responses;
Expand Down
1 change: 1 addition & 0 deletions src/Ocelot/Configuration/File/FileAuthenticationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text;
using Ocelot.Infrastructure.Extensions;

namespace Ocelot.Configuration.File
{
Expand Down
1 change: 1 addition & 0 deletions src/Ocelot/Configuration/File/FileRateLimitRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ocelot.Infrastructure.Extensions;

namespace Ocelot.Configuration.File
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/FileConfigurationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<IActionResult> Post([FromBody]FileConfiguration fileConfigurat
if (test != null)
{
var node = (INode)test;
var result = node.Accept(new UpdateFileConfiguration(fileConfiguration));
var result = await node.Accept(new UpdateFileConfiguration(fileConfiguration));
if (result.GetType() == typeof(Rafty.Concensus.ErrorResponse<UpdateFileConfiguration>))
{
return new BadRequestObjectResult("There was a problem. This error message sucks raise an issue in GitHub.");
Expand Down
1 change: 1 addition & 0 deletions src/Ocelot/Headers/AddHeadersToResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Ocelot.Headers
using System.Collections.Generic;
using Ocelot.Configuration.Creator;
using Ocelot.Infrastructure;
using Ocelot.Infrastructure.Extensions;
using Ocelot.Logging;
using Ocelot.Middleware;

Expand Down
32 changes: 32 additions & 0 deletions src/Ocelot/Infrastructure/Extensions/NetCoreSupportExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Ocelot.Infrastructure.Extensions
{
/// <summary>
/// Trivial implementations of methods present in .NET Core 2 but not supported on .NET Standard 2.0.
/// </summary>
internal static class NetCoreSupportExtensions
{
internal static void AppendJoin<T>(this StringBuilder builder, char separator, IEnumerable<T> values)
{
builder.Append(string.Join(separator.ToString(), values));
}

internal static string[] Split(this string input, string separator, StringSplitOptions options = StringSplitOptions.None)
{
return input.Split(new[] { separator }, options);
}

internal static bool StartsWith(this string input, char value)
{
return input.StartsWith(value.ToString());
}

internal static bool EndsWith(this string input, char value)
{
return input.EndsWith(value.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CookieStickySessions(ILoadBalancer loadBalancer, string key, int keyExpir
{
if (stickySession.Expiry < DateTime.UtcNow)
{
_stored.Remove(stickySession.Key, out _);
_stored.TryRemove(stickySession.Key, out _);
_loadBalancer.Release(stickySession.HostAndPort);
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/Ocelot/Ocelot.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
<NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
<NoPackageAnalysis>true</NoPackageAnalysis>
Expand All @@ -25,14 +25,22 @@
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" />
<PackageReference Include="Butterfly.Client" Version="0.0.8" />
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="FluentValidation" Version="7.5.2" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.MiddlewareAnalysis" Version="2.0.2" />
<PackageReference Include="Microsoft.Data.SQLite" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.0.1">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.1" />
Expand All @@ -48,6 +56,6 @@
<PackageReference Include="Polly" Version="5.8.0" />
<PackageReference Include="Pivotal.Discovery.Client" Version="1.1.0" />
<PackageReference Include="IdentityServer4" Version="2.1.3" />
<PackageReference Include="Rafty" Version="0.4.2" />
<PackageReference Include="Rafty" Version="0.4.3" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion src/Ocelot/Raft/FileFsm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Rafty.FiniteStateMachine;
using Rafty.Infrastructure;
Expand All @@ -17,7 +18,7 @@ public FileFsm(NodeId nodeId)
_id = nodeId.Id.Replace("/","").Replace(":","");
}

public void Handle(LogEntry log)
public Task Handle(LogEntry log)
{
try
{
Expand All @@ -28,6 +29,8 @@ public void Handle(LogEntry log)
{
Console.WriteLine(exception);
}

return Task.CompletedTask;
}
}
}
13 changes: 7 additions & 6 deletions src/Ocelot/Raft/HttpPeer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Ocelot.Configuration;
using Ocelot.Middleware;
Expand Down Expand Up @@ -35,7 +36,7 @@ public HttpPeer(string hostAndPort, HttpClient httpClient, IBaseUrlFinder finder

public string Id {get; private set;}

public RequestVoteResponse Request(RequestVote requestVote)
public async Task<RequestVoteResponse> Request(RequestVote requestVote)
{
if(_token == null)
{
Expand All @@ -48,15 +49,15 @@ public RequestVoteResponse Request(RequestVote requestVote)
var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/requestvote", content).GetAwaiter().GetResult();
if(response.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<RequestVoteResponse>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), _jsonSerializerSettings);
return JsonConvert.DeserializeObject<RequestVoteResponse>(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings);
}
else
{
return new RequestVoteResponse(false, requestVote.Term);
}
}

public AppendEntriesResponse Request(AppendEntries appendEntries)
public async Task<AppendEntriesResponse> Request(AppendEntries appendEntries)
{
try
{
Expand All @@ -71,7 +72,7 @@ public AppendEntriesResponse Request(AppendEntries appendEntries)
var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/appendEntries", content).GetAwaiter().GetResult();
if(response.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<AppendEntriesResponse>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(),_jsonSerializerSettings);
return JsonConvert.DeserializeObject<AppendEntriesResponse>(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings);
}
else
{
Expand All @@ -85,7 +86,7 @@ public AppendEntriesResponse Request(AppendEntries appendEntries)
}
}

public Response<T> Request<T>(T command)
public async Task<Response<T>> Request<T>(T command)
where T : ICommand
{
Console.WriteLine("SENDING REQUEST....");
Expand All @@ -107,7 +108,7 @@ public Response<T> Request<T>(T command)
else
{
Console.WriteLine("REQUEST NOT OK....");
return new ErrorResponse<T>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), command);
return new ErrorResponse<T>(await response.Content.ReadAsStringAsync(), command);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Ocelot/Raft/OcelotFiniteStateMachine.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Ocelot.Configuration.Setter;
using Rafty.FiniteStateMachine;
using Rafty.Log;
Expand All @@ -14,12 +15,12 @@ public OcelotFiniteStateMachine(IFileConfigurationSetter setter)
_setter = setter;
}

public void Handle(LogEntry log)
public async Task Handle(LogEntry log)
{
//todo - handle an error
//hack it to just cast as at the moment we know this is the only command :P
var hack = (UpdateFileConfiguration)log.CommandData;
_setter.Set(hack.Configuration).GetAwaiter().GetResult();
await _setter.Set(hack.Configuration);
}
}
}
Loading

0 comments on commit b1641e0

Please sign in to comment.