Skip to content

Commit

Permalink
#296 coming up with ideas for this config merging
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPallister committed Apr 15, 2018
1 parent 7ca8288 commit 3ae2b28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

namespace Ocelot.DependencyInjection
{
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Configuration.File;
using Newtonsoft.Json;

public static class ConfigurationBuilderExtensions
{
[Obsolete("Please set BaseUrl in ocelot.json GlobalConfiguration.BaseUrl")]
Expand All @@ -21,6 +27,21 @@ public static IConfigurationBuilder AddOcelotBaseUrl(this IConfigurationBuilder

public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder)
{
const string pattern = "(?i)ocelot(.*).json$";

var reg = new Regex(pattern);

var files = Directory.GetFiles(".")
.Where(path => reg.IsMatch(path))
.ToList();

foreach (var file in files)
{
var lines = File.ReadAllText(file);
var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);

}

//var load all files with ocelot*.json
//merge these files into one
//save it as ocelot.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public void should_merge_files()
};

var globalJson = JsonConvert.SerializeObject(globalConfig);
//File.WriteAllText("ocelot.global.json", globalJson);
File.WriteAllText("ocelot.global.json", globalJson);

var reRouteJson = JsonConvert.SerializeObject(reRoute);
//File.WriteAllText("ocelot.reRoute.json", reRouteJson);
File.WriteAllText("ocelot.reRoute.json", reRouteJson);

IConfigurationBuilder builder = new ConfigurationBuilder();
//builder.AddOcelot();
builder.AddOcelot();

}

Expand Down

0 comments on commit 3ae2b28

Please sign in to comment.