Added ability to read configuration .json files from a directory.
This commit is contained in:
@@ -34,7 +34,7 @@ namespace TimberWinR.ServiceHost
|
||||
serviceConfigurator.WhenStarted(myService => myService.Start());
|
||||
serviceConfigurator.WhenStopped(myService => myService.Stop());
|
||||
});
|
||||
|
||||
|
||||
hostConfigurator.AddCommandLineDefinition("configFile", c => arguments.ConfigFile = c);
|
||||
hostConfigurator.AddCommandLineDefinition("logLevel", c => arguments.LogLevel = c);
|
||||
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.1")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.1")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
|
||||
@@ -79,24 +79,39 @@ namespace TimberWinR
|
||||
get { return _filters; }
|
||||
}
|
||||
|
||||
public static Configuration FromFile(string jsonConfFile)
|
||||
{
|
||||
Configuration c = new Configuration();
|
||||
|
||||
public static Configuration FromDirectory(string jsonDirectory)
|
||||
{
|
||||
Configuration c = null;
|
||||
|
||||
foreach (string jsonConfFile in Directory.GetFiles(jsonDirectory, "*.json"))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(jsonConfFile))
|
||||
{
|
||||
c = FromFile(jsonConfFile, c);
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Configuration FromFile(string jsonConfFile, Configuration c = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(jsonConfFile))
|
||||
{
|
||||
string json = File.ReadAllText(jsonConfFile);
|
||||
|
||||
return FromString(json);
|
||||
return FromString(json, c);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Configuration FromString(string json)
|
||||
public static Configuration FromString(string json, Configuration c = null)
|
||||
{
|
||||
Configuration c = new Configuration();
|
||||
|
||||
if (c == null)
|
||||
c = new Configuration();
|
||||
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
TextReader re = new StringReader(json);
|
||||
JsonTextReader reader = new JsonTextReader(re);
|
||||
@@ -126,7 +141,6 @@ namespace TimberWinR
|
||||
c._elasticsearchOutputs = x.TimberWinR.Outputs.Elasticsearch.ToList();
|
||||
}
|
||||
|
||||
|
||||
if (x.TimberWinR.Filters != null)
|
||||
c._filters = x.TimberWinR.AllFilters.ToList();
|
||||
|
||||
|
||||
@@ -55,18 +55,29 @@ namespace TimberWinR
|
||||
|
||||
LogManager.GlobalThreshold = LogLevel.FromString(logLevel);
|
||||
|
||||
var fi = new FileInfo(jsonConfigFile);
|
||||
if (!fi.Exists)
|
||||
throw new FileNotFoundException("Missing config file", jsonConfigFile);
|
||||
|
||||
LogManager.GetCurrentClassLogger().Info("Initialized, Reading Config: {0}", fi.FullName);
|
||||
|
||||
// Is it a directory?
|
||||
if (Directory.Exists(jsonConfigFile))
|
||||
{
|
||||
Config = Configuration.FromDirectory(jsonConfigFile);
|
||||
LogManager.GetCurrentClassLogger().Info("Initialized, Reading Configurations From {0}", jsonConfigFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fi = new FileInfo(jsonConfigFile);
|
||||
|
||||
if (!fi.Exists)
|
||||
throw new FileNotFoundException("Missing config file", jsonConfigFile);
|
||||
|
||||
LogManager.GetCurrentClassLogger().Info("Initialized, Reading Config: {0}", fi.FullName);
|
||||
Config = Configuration.FromFile(jsonConfigFile);
|
||||
}
|
||||
|
||||
LogManager.GetCurrentClassLogger().Info("Log Directory {0}", logfileDir);
|
||||
LogManager.GetCurrentClassLogger().Info("Logging Level: {0}", LogManager.GlobalThreshold);
|
||||
|
||||
LogManager.GetCurrentClassLogger().Info("Logging Level: {0}", LogManager.GlobalThreshold);
|
||||
|
||||
// Read the Configuration file
|
||||
Config = Configuration.FromFile(jsonConfigFile);
|
||||
|
||||
|
||||
if (Config.RedisOutputs != null)
|
||||
{
|
||||
foreach (var ro in Config.RedisOutputs)
|
||||
|
||||
Reference in New Issue
Block a user