mirror of https://github.com/winsw/winsw
parent
1fc681af14
commit
dcec99c261
|
@ -648,6 +648,12 @@ namespace WinSW.Configuration
|
||||||
{
|
{
|
||||||
var result = new List<string>(0);
|
var result = new List<string>(0);
|
||||||
var extensions = this.ExtensionsConfiguration;
|
var extensions = this.ExtensionsConfiguration;
|
||||||
|
|
||||||
|
if (extensions is null)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
var extensionConfigListObject = new ObjectQuery(extensions).ToList<object>();
|
var extensionConfigListObject = new ObjectQuery(extensions).ToList<object>();
|
||||||
|
|
||||||
foreach (var item in extensionConfigListObject)
|
foreach (var item in extensionConfigListObject)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using WinSW.Configuration;
|
using WinSW.Configuration;
|
||||||
|
using WinSW.Util;
|
||||||
|
|
||||||
namespace WinSW.Extensions
|
namespace WinSW.Extensions
|
||||||
{
|
{
|
||||||
|
@ -10,7 +11,7 @@ namespace WinSW.Extensions
|
||||||
public WinSWExtensionDescriptor Descriptor { get; set; }
|
public WinSWExtensionDescriptor Descriptor { get; set; }
|
||||||
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||||
|
|
||||||
public virtual void Configure(IWinSWConfiguration descriptor, object settings)
|
public virtual void Configure(IWinSWConfiguration descriptor, ObjectQuery settings)
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,12 @@ namespace WinSW.Extensions
|
||||||
var result = new List<WinSWExtensionConfiguration>(0);
|
var result = new List<WinSWExtensionConfiguration>(0);
|
||||||
|
|
||||||
var extensions = this.serviceDescriptor.ExtensionsConfiguration;
|
var extensions = this.serviceDescriptor.ExtensionsConfiguration;
|
||||||
|
|
||||||
|
if (extensions is null)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
var extensionNodes = new ObjectQuery(extensions).ToList<object>();
|
var extensionNodes = new ObjectQuery(extensions).ToList<object>();
|
||||||
|
|
||||||
foreach (var extension in extensionNodes)
|
foreach (var extension in extensionNodes)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using WinSW.Configuration;
|
using WinSW.Configuration;
|
||||||
|
using WinSW.Util;
|
||||||
|
|
||||||
namespace WinSW.Extensions
|
namespace WinSW.Extensions
|
||||||
{
|
{
|
||||||
|
@ -26,7 +27,7 @@ namespace WinSW.Extensions
|
||||||
/// Init handler. Extension should load it's config during that step
|
/// Init handler. Extension should load it's config during that step
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="descriptor">Service descriptor</param>
|
/// <param name="descriptor">Service descriptor</param>
|
||||||
void Configure(IWinSWConfiguration descriptor, object settings);
|
void Configure(IWinSWConfiguration descriptor, ObjectQuery settings);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start handler. Called during startup of the service before the child process.
|
/// Start handler. Called during startup of the service before the child process.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
using WinSW.Util;
|
||||||
|
|
||||||
namespace WinSW.Extensions
|
namespace WinSW.Extensions
|
||||||
{
|
{
|
||||||
public class WinSWExtensionConfiguration
|
public class WinSWExtensionConfiguration
|
||||||
|
@ -8,9 +10,9 @@ namespace WinSW.Extensions
|
||||||
|
|
||||||
public string ClassName { get; set; }
|
public string ClassName { get; set; }
|
||||||
|
|
||||||
public object Settings { get; set; }
|
public ObjectQuery Settings { get; set; }
|
||||||
|
|
||||||
public WinSWExtensionConfiguration(string id, bool enabled, string className, object settings)
|
public WinSWExtensionConfiguration(string id, bool enabled, string className, ObjectQuery settings)
|
||||||
{
|
{
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Enabled = enabled;
|
this.Enabled = enabled;
|
||||||
|
|
|
@ -136,10 +136,6 @@ namespace WinSW.Extensions
|
||||||
throw new ExtensionException(id, "Cannot get the configuration entry");
|
throw new ExtensionException(id, "Cannot get the configuration entry");
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine(configNode.Id);
|
|
||||||
Console.WriteLine(configNode.ClassName);
|
|
||||||
Console.WriteLine(configNode.Enabled);
|
|
||||||
|
|
||||||
var descriptor = new WinSWExtensionDescriptor(configNode.Id, configNode.ClassName, configNode.Enabled);
|
var descriptor = new WinSWExtensionDescriptor(configNode.Id, configNode.ClassName, configNode.Enabled);
|
||||||
if (descriptor.Enabled)
|
if (descriptor.Enabled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -179,14 +179,12 @@ namespace WinSW.Plugins.RunawayProcessKiller
|
||||||
return parameters.Environment;
|
return parameters.Environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Configure(IWinSWConfiguration descriptor, object settings)
|
public override void Configure(IWinSWConfiguration descriptor, ObjectQuery settings)
|
||||||
{
|
{
|
||||||
var configQuery = new ObjectQuery(settings);
|
this.Pidfile = settings.Get("pidfile").ToString();
|
||||||
|
this.StopTimeout = TimeSpan.FromMilliseconds(int.Parse(settings.Get("stopTimeOut").ToString()));
|
||||||
this.Pidfile = configQuery.On("pidfile").ToString();
|
this.StopParentProcessFirst = settings.Get("StopParentFirst").ToBoolean();
|
||||||
this.StopTimeout = TimeSpan.FromMilliseconds(int.Parse(configQuery.On("stopTimeOut").ToString()));
|
this.CheckWinSWEnvironmentVariable = settings.Get("checkWinSWEnvironmentVariable").ToBoolean();
|
||||||
this.StopParentProcessFirst = configQuery.On("StopParentFirst").ToBoolean();
|
|
||||||
this.CheckWinSWEnvironmentVariable = configQuery.On("checkWinSWEnvironmentVariable").ToBoolean();
|
|
||||||
this.ServiceId = descriptor.Id;
|
this.ServiceId = descriptor.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,18 +26,16 @@ namespace WinSW.Plugins.SharedDirectoryMapper
|
||||||
this._entries.Add(config);
|
this._entries.Add(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Configure(IWinSWConfiguration descriptor, object settings)
|
public override void Configure(IWinSWConfiguration descriptor, ObjectQuery settings)
|
||||||
{
|
{
|
||||||
var configObject = new ObjectQuery(settings);
|
var maps = settings.Get("mapping").ToList<object>();
|
||||||
|
|
||||||
var maps = configObject.On("mapping").ToList<object>();
|
|
||||||
|
|
||||||
foreach (var map in maps)
|
foreach (var map in maps)
|
||||||
{
|
{
|
||||||
var mapObject = new ObjectQuery(map);
|
var mapObject = new ObjectQuery(map);
|
||||||
var enable = mapObject.On("enabled").ToBoolean();
|
var enable = mapObject.Get("enabled").ToBoolean();
|
||||||
var label = mapObject.On("label").ToString();
|
var label = mapObject.Get("label").ToString();
|
||||||
var uncpath = mapObject.On("uncpath").ToString();
|
var uncpath = mapObject.Get("uncpath").ToString();
|
||||||
|
|
||||||
var config = new SharedDirectoryMapperConfig(enable, label, uncpath);
|
var config = new SharedDirectoryMapperConfig(enable, label, uncpath);
|
||||||
this._entries.Add(config);
|
this._entries.Add(config);
|
||||||
|
|
|
@ -3,6 +3,7 @@ using WinSW;
|
||||||
using WinSW.Configuration;
|
using WinSW.Configuration;
|
||||||
using WinSW.Extensions;
|
using WinSW.Extensions;
|
||||||
using WinSW.Plugins.RunawayProcessKiller;
|
using WinSW.Plugins.RunawayProcessKiller;
|
||||||
|
using WinSW.Util;
|
||||||
using winswTests.Extensions;
|
using winswTests.Extensions;
|
||||||
|
|
||||||
namespace winswTests
|
namespace winswTests
|
||||||
|
@ -27,7 +28,7 @@ extensions:
|
||||||
enabled: yes
|
enabled: yes
|
||||||
classname: ""{this.testExtension}""
|
classname: ""{this.testExtension}""
|
||||||
settings:
|
settings:
|
||||||
pidfile: foo/bar/pid.txt
|
pidfile: pid.txt
|
||||||
stopTimeOut: 5000
|
stopTimeOut: 5000
|
||||||
StopParentFirst: true";
|
StopParentFirst: true";
|
||||||
|
|
||||||
|
@ -50,5 +51,19 @@ extensions:
|
||||||
Assert.AreEqual(5000, extension.StopTimeout.TotalMilliseconds, "Loaded Stop Timeout is not equal to the expected one");
|
Assert.AreEqual(5000, extension.StopTimeout.TotalMilliseconds, "Loaded Stop Timeout is not equal to the expected one");
|
||||||
Assert.AreEqual(true, extension.StopParentProcessFirst, "Loaded StopParentFirst is not equal to the expected one");
|
Assert.AreEqual(true, extension.StopParentProcessFirst, "Loaded StopParentFirst is not equal to the expected one");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Sample_test()
|
||||||
|
{
|
||||||
|
ExtensionConfigurationProvider provider = new ExtensionConfigurationProvider(this._testServiceDescriptor);
|
||||||
|
var config = provider.GetExtenstionConfiguration("killOnStartup");
|
||||||
|
var pid = config.Settings.On("pidfile").ToString();
|
||||||
|
var stopTimeOut = config.Settings.Get("stopTimeOut").ToString();
|
||||||
|
var StopParentFirst = config.Settings.Get("StopParentFirst").ToString();
|
||||||
|
|
||||||
|
System.Console.WriteLine(pid);
|
||||||
|
System.Console.WriteLine(stopTimeOut);
|
||||||
|
System.Console.WriteLine(StopParentFirst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue