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)
{
}
}
}