Merge pull request #205 from m3rlinez/master
[mono.git] / mcs / nunit24 / ClientUtilities / util / ProcessRunner.cs
1 // ****************************************************************\r
2 // Copyright 2007, Charlie Poole\r
3 // This is free software licensed under the NUnit license. You may\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
5 // ****************************************************************\r
6 \r
7 using System;\r
8 using System.IO;\r
9 using System.Diagnostics;\r
10 using System.Reflection;\r
11 using System.Runtime.Remoting;\r
12 using System.Runtime.Remoting.Proxies;\r
13 using System.Runtime.Remoting.Services;\r
14 using System.Runtime.Remoting.Channels;\r
15 using System.Runtime.Remoting.Channels.Tcp;\r
16 using NUnit.Core;\r
17 \r
18 namespace NUnit.Util\r
19 {\r
20         /// <summary>\r
21         /// Summary description for ProcessRunner.\r
22         /// </summary>\r
23         public class ProcessRunner : ProxyTestRunner, IDisposable\r
24         {\r
25                 private TestAgent agent;\r
26 \r
27                 #region Constructors\r
28                 public ProcessRunner() : base( 0 ) { }\r
29 \r
30                 public ProcessRunner( int runnerID ) : base( runnerID ) { }\r
31                 #endregion\r
32 \r
33                 public override bool Load(TestPackage package)\r
34                 {\r
35                         if ( this.agent == null )\r
36                                 this.agent = Services.TestAgency.GetAgent( AgentType.ProcessAgent, 5000 );              \r
37         \r
38                         if ( this.TestRunner == null )\r
39                                 this.TestRunner = agent.CreateRunner(this.runnerID);\r
40 \r
41                         return base.Load (package);\r
42                 }\r
43 \r
44                 #region IDisposable Members\r
45                 public void Dispose()\r
46                 {\r
47                         if ( TestRunner != null )\r
48                                 this.TestRunner.Unload();\r
49 \r
50                         if ( this.agent != null )\r
51                                 Services.TestAgency.ReleaseAgent(this.agent);\r
52 \r
53                         this.TestRunner = null;\r
54                         this.agent = null;\r
55                 }\r
56                 #endregion\r
57         }\r
58 }\r