Added priority support

Also improved the test harness a bit.
pull/37/merge
Kohsuke Kawaguchi 2014-01-08 22:30:17 -08:00
parent 7359e59e81
commit a4ee776bcc
4 changed files with 53 additions and 22 deletions

View File

@ -421,6 +421,10 @@ namespace winsw
process.Start();
WriteEvent("Started " + process.Id);
var priority = descriptor.Priority;
if (priority != ProcessPriorityClass.Normal)
process.PriorityClass = priority;
// monitor the completion of the process
StartThread(delegate()
{

View File

@ -72,6 +72,21 @@ namespace winsw
dom.Load(BasePath + ".xml");
}
/// <summary>
/// Loads descriptor from existing DOM
/// </summary>
public ServiceDescriptor(XmlDocument dom)
{
this.dom = dom;
}
public static ServiceDescriptor FromXML(string xml)
{
var dom = new XmlDocument();
dom.LoadXml(xml);
return new ServiceDescriptor(dom);
}
private string SingleElement(string tagName)
{
return SingleElement(tagName, false);
@ -571,5 +586,19 @@ namespace winsw
return SingleTimeSpanElement(dom, "stoptimeout", TimeSpan.FromSeconds(15));
}
}
/// <summary>
/// Desired process priority or null if not specified.
/// </summary>
public ProcessPriorityClass Priority
{
get
{
var p = SingleElement("priority",true);
if (p == null) return ProcessPriorityClass.Normal; // default value
return (ProcessPriorityClass)Enum.Parse(typeof(ProcessPriorityClass), p, true);
}
}
}
}

View File

@ -1,29 +1,15 @@
using NUnit.Framework;
using winsw;
using winsw;
using System.Diagnostics;
using System.Xml;
namespace winswTests
{
public class ServiceDescriptorExtended : ServiceDescriptor
{
public ServiceDescriptorExtended(string descriptorXml)
{
LoadTestXml(descriptorXml);
}
private void LoadTestXml(string xml)
{
dom.LoadXml(xml);
}
}
[TestFixture]
public class ServiceDescriptorTests
{
private ServiceDescriptorExtended extendedServiceDescriptor;
private ServiceDescriptor extendedServiceDescriptor;
private const string ExpectedWorkingDirectory = @"Z:\Path\SubPath";
private const string Username = "User";
@ -49,9 +35,8 @@ namespace winswTests
+ ExpectedWorkingDirectory
+ "</workingdirectory>"
+ @"<logpath>C:\logs</logpath>"
+ "</service>";
extendedServiceDescriptor = new ServiceDescriptorExtended(SeedXml);
+ "</service>";
extendedServiceDescriptor = ServiceDescriptor.FromXML(SeedXml);
}
[Test]
@ -73,6 +58,19 @@ namespace winswTests
{
System.Diagnostics.Debug.WriteLine("_extendedServiceDescriptor.WorkingDirectory :: " + extendedServiceDescriptor.WorkingDirectory);
Assert.That(extendedServiceDescriptor.ServiceAccountPassword, Is.EqualTo(Password));
}
[Test]
public void Priority()
{
var sd = ServiceDescriptor.FromXML("<service><id>test</id><priority>normal</priority></service>");
Assert.That(sd.Priority, Is.EqualTo(ProcessPriorityClass.Normal));
sd = ServiceDescriptor.FromXML("<service><id>test</id><priority>idle</priority></service>");
Assert.That(sd.Priority, Is.EqualTo(ProcessPriorityClass.Idle));
sd = ServiceDescriptor.FromXML("<service><id>test</id></service>");
Assert.That(sd.Priority, Is.EqualTo(ProcessPriorityClass.Normal));
}
}
}

View File

@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C# Express 2008
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "winsw", "winsw.csproj", "{0DE77F55-ADE5-43C1-999A-0BC81153B039}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "winswTests", "Tests\winswTests\winswTests.csproj", "{93843402-842B-44B4-B303-AEE829BE0B43}"