Skip to content

Commit

Permalink
Added priority support
Browse files Browse the repository at this point in the history
Also improved the test harness a bit.
  • Loading branch information
kohsuke committed Jan 9, 2014
1 parent 7359e59 commit a4ee776
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ private void StartProcess(Process process, string arguments, String executable)
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()
{
Expand Down
29 changes: 29 additions & 0 deletions ServiceDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public ServiceDescriptor()
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);
Expand Down Expand Up @@ -571,5 +586,19 @@ public TimeSpan StopTimeout
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);
}
}
}
}
40 changes: 19 additions & 21 deletions Tests/winswTests/ServiceDescriptorTests.cs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -49,9 +35,8 @@ public void SetUp()
+ ExpectedWorkingDirectory
+ "</workingdirectory>"
+ @"<logpath>C:\logs</logpath>"
+ "</service>";

extendedServiceDescriptor = new ServiceDescriptorExtended(SeedXml);
+ "</service>";
extendedServiceDescriptor = ServiceDescriptor.FromXML(SeedXml);
}

[Test]
Expand All @@ -73,6 +58,19 @@ public void VerifyPassword()
{
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));
}
}
}
2 changes: 1 addition & 1 deletion winsw.sln
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down

0 comments on commit a4ee776

Please sign in to comment.