Update YamlConfigurations.cs

pull/461/head
Buddhika Chathuranga 2020-06-02 19:49:10 +05:30
parent 24131906ac
commit d489020134
2 changed files with 25 additions and 19 deletions

View File

@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace winsw.Configuration
namespace winsw.Configuration
{
public class YamlConfiguration
{
readonly ServiceAccount? serviceAccount;
readonly BasicConfigs? basicConfigs;
public string? id { get; set; }
public string? name { get; set; }
public string? description { get; set; }
public string? executable { get; set; }
public string? workingdirectory { get; set; }
public ServiceAccount? serviceaccount { get; set; }
public Log? log { get; set; }
}
public class ServiceAccount
@ -18,11 +20,13 @@ namespace winsw.Configuration
public string allowservicelogon { get; set; }
}
public class BasicConfigs
public class Log
{
public string id { get; set; }
public string name { get; set; }
public string description { get; set; }
public string executable { get; set; }
public string sizeThreshold { get; set; }
public string keepFiles { get; set; }
public string pattern { get; set; }
public string autoRollAtTime { get; set; }
public string period { get; set; }
public string mod { get; set; }
}
}

View File

@ -1,11 +1,14 @@
using System;
using System.IO;
using winsw.Configuration;
using YamlDotNet.Serialization;
namespace winsw
{
public class ServiceDescriptorYaml
{
protected readonly YamlConfiguration configurations = new YamlConfiguration();
public static DefaultWinSWSettings Defaults { get; } = new DefaultWinSWSettings();
public string BasePath { get; set; }
@ -24,11 +27,11 @@ namespace winsw
DirectoryInfo d = new DirectoryInfo(Path.GetDirectoryName(p));
while (true)
{
if (File.Exists(Path.Combine(d.FullName, baseName + ".yaml")))
if (File.Exists(Path.Combine(d.FullName, baseName + ".yml")))
break;
if (d.Parent is null)
throw new FileNotFoundException("Unable to locate " + baseName + ".yaml file within executable directory or any parents");
throw new FileNotFoundException("Unable to locate " + baseName + ".yml file within executable directory or any parents");
d = d.Parent;
}
@ -36,14 +39,13 @@ namespace winsw
BaseName = baseName;
BasePath = Path.Combine(d.FullName, BaseName);
using(var reader = new StreamReader(BasePath + ".yaml"))
using(var reader = new StreamReader(BasePath + ".yml"))
{
var file = reader.ReadToEnd();
Console.WriteLine(file);
}
var deserializer = new DeserializerBuilder().Build();
// yaml <> object - deserialization and schema validation
// Set environment data
configurations = deserializer.Deserialize<YamlConfiguration>(file);
}
}
}
}