after hours of pissing around on the mac...gave up..so got this configured how i wanted in VS2015 now to see if it works on the mac

This commit is contained in:
TomPallister
2016-07-03 20:39:08 +01:00
parent 3777e8c0c8
commit c512a772d4
36 changed files with 359 additions and 206 deletions

View File

@ -0,0 +1,12 @@
namespace Ocelot.Library.Infrastructure.Responses
{
public abstract class Error
{
public Error(string message)
{
Message = message;
}
public string Message { get; private set; }
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Responses
{
public class ErrorResponse : Response
{
public ErrorResponse(List<Error> errors) : base(errors)
{
}
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Responses
{
public class ErrorResponse<T> : Response<T>
{
public ErrorResponse(List<Error> errors) : base(errors)
{
}
}
}

View File

@ -0,0 +1,9 @@
namespace Ocelot.Library.Infrastructure.Responses
{
public class OkResponse : Response
{
public OkResponse()
{
}
}
}

View File

@ -0,0 +1,9 @@
namespace Ocelot.Library.Infrastructure.Responses
{
public class OkResponse<T> : Response<T>
{
public OkResponse(T data) : base(data)
{
}
}
}

View File

@ -0,0 +1,19 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Responses
{
public abstract class Response
{
protected Response()
{
Errors = new List<Error>();
}
protected Response(List<Error> errors)
{
Errors = errors ?? new List<Error>();
}
public List<Error> Errors { get; private set; }
}
}

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Responses
{
public abstract class Response<T> : Response
{
protected Response(T data)
{
Data = data;
}
protected Response(List<Error> errors) : base(errors)
{
}
public T Data { get; private set; }
}
}

View File

@ -0,0 +1,10 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Router
{
public interface IRouterService
{
Response AddRoute(string apiKey, string upstreamApiBaseUrl);
Response<Route> GetRoute(string apiKey);
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Router
{
public class InMemoryRouterService : IRouterService
{
private readonly Dictionary<string, string> _routes;
public InMemoryRouterService()
{
_routes = new Dictionary<string,string>();
}
public Response AddRoute(string apiKey, string upstreamApiBaseUrl)
{
if(_routes.ContainsKey(apiKey))
{
return new ErrorResponse(new List<Error>(){new RouteKeyAlreadyExists("This key has already been used")});
}
_routes.Add(apiKey, upstreamApiBaseUrl);
return new OkResponse();
}
public Response<Route> GetRoute(string apiKey)
{
Console.WriteLine("looking for {0}", apiKey);
string upstreamApiBaseUrl = null;
if(_routes.TryGetValue(apiKey, out upstreamApiBaseUrl))
{
return new OkResponse<Route>(new Route(apiKey, upstreamApiBaseUrl));
}
Console.WriteLine("Couldnt find it");
return new ErrorResponse<Route>(new List<Error>(){new RouteKeyDoesNotExist("This key does not exist")});
}
}
}

View File

@ -0,0 +1,14 @@
namespace Ocelot.Library.Infrastructure.Router
{
public class Route
{
public Route(string apiKey, string upstreamRoute)
{
ApiKey = apiKey;
UpstreamRoute = upstreamRoute;
}
public string ApiKey {get;private set;}
public string UpstreamRoute {get;private set;}
}
}

View File

@ -0,0 +1,12 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Router
{
public class RouteKeyAlreadyExists : Error
{
public RouteKeyAlreadyExists(string message)
: base(message)
{
}
}
}

View File

@ -0,0 +1,12 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Router
{
public class RouteKeyDoesNotExist : Error
{
public RouteKeyDoesNotExist(string message)
: base(message)
{
}
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Middleware
{
public static class ProxyExtensions
{
public static IApplicationBuilder UseProxy(this IApplicationBuilder builder)
{
return builder.UseMiddleware<ProxyMiddleware>();
}
}
}

View File

@ -0,0 +1,20 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Middleware
{
public class ProxyMiddleware
{
private readonly RequestDelegate _next;
public ProxyMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
await _next.Invoke(context);
}
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Middleware
{
public static class RequestLoggerExtensions
{
public static IApplicationBuilder UseRequestLogger(this IApplicationBuilder builder)
{
return builder.UseMiddleware<RequestLoggerMiddleware>();
}
}
}

View File

@ -0,0 +1,25 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Ocelot.Library.Middleware
{
public class RequestLoggerMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger _logger;
public RequestLoggerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
{
_next = next;
_logger = loggerFactory.CreateLogger<RequestLoggerMiddleware>();
}
public async Task Invoke(HttpContext context)
{
_logger.LogInformation("Handling request: " + context.Request.Path);
await _next.Invoke(context);
_logger.LogInformation("Finished handling request.");
}
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>d6df4206-0dba-41d8-884d-c3e08290fdbb</ProjectGuid>
<RootNamespace>Ocelot.Library</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ocelot.Library")]
[assembly: AssemblyTrademark("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d6df4206-0dba-41d8-884d-c3e08290fdbb")]

View File

@ -0,0 +1,30 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.AspNetCore.Http": "1.0.0"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
}