mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:10:50 +08:00 
			
		
		
		
	#296 still hacking this idea around
This commit is contained in:
		@@ -32,19 +32,32 @@ namespace Ocelot.DependencyInjection
 | 
				
			|||||||
            var reg = new Regex(pattern);
 | 
					            var reg = new Regex(pattern);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var files = Directory.GetFiles(".")
 | 
					            var files = Directory.GetFiles(".")
 | 
				
			||||||
                .Where(path => reg.IsMatch(path))
 | 
					                .Where(path => reg.IsMatch(path)).Where(x => x.Count(s => s == '.') == 3)
 | 
				
			||||||
                .ToList();
 | 
					                .ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            FileConfiguration ocelotConfig = new FileConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach (var file in files)
 | 
					            foreach (var file in files)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
					                if(files.Count > 1 && file == "./ocelot.json")
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var lines = File.ReadAllText(file);
 | 
					                var lines = File.ReadAllText(file);
 | 
				
			||||||
                var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);
 | 
					                var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if(file ==  "./ocelot.global.json")
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    ocelotConfig.GlobalConfiguration = config.GlobalConfiguration;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                ocelotConfig.Aggregates.AddRange(config.Aggregates);
 | 
				
			||||||
 | 
					                ocelotConfig.ReRoutes.AddRange(config.ReRoutes);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //var load all files with ocelot*.json
 | 
					            var json = JsonConvert.SerializeObject(ocelotConfig);
 | 
				
			||||||
            //merge these files into one
 | 
					            File.WriteAllText("ocelot.json", json);
 | 
				
			||||||
            //save it as ocelot.json
 | 
					 | 
				
			||||||
            builder.AddJsonFile("ocelot.json");
 | 
					            builder.AddJsonFile("ocelot.json");
 | 
				
			||||||
            return builder;
 | 
					            return builder;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,11 +73,11 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
            File.WriteAllText("ocelot.global.json", globalJson);
 | 
					            File.WriteAllText("ocelot.global.json", globalJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var reRouteJson = JsonConvert.SerializeObject(reRoute);
 | 
					            var reRouteJson = JsonConvert.SerializeObject(reRoute);
 | 
				
			||||||
            File.WriteAllText("ocelot.reRoute.json", reRouteJson);
 | 
					            File.WriteAllText("ocelot.reRoutes.json", reRouteJson);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            IConfigurationBuilder builder = new ConfigurationBuilder();
 | 
					            IConfigurationBuilder builder = new ConfigurationBuilder();
 | 
				
			||||||
            builder.AddOcelot();
 | 
					            builder.AddOcelot();
 | 
				
			||||||
            
 | 
					            var configRoot = builder.Build();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void GivenTheBaseUrl(string baseUrl)
 | 
					        private void GivenTheBaseUrl(string baseUrl)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user