PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/ProcessRunner.cs

#
C# | 111 lines | 80 code | 20 blank | 11 comment | 13 complexity | 3422e387440178baada97e7aff4bdc86 MD5 | raw file
  1// ****************************************************************
  2// Copyright 2007, Charlie Poole
  3// This is free software licensed under the NUnit license. You may
  4// obtain a copy of the license at http://nunit.org
  5// ****************************************************************
  6
  7using System;
  8using System.IO;
  9using System.Diagnostics;
 10using System.Reflection;
 11using System.Runtime.Remoting;
 12using System.Runtime.Remoting.Proxies;
 13using System.Runtime.Remoting.Services;
 14using System.Runtime.Remoting.Channels;
 15using System.Runtime.Remoting.Channels.Tcp;
 16using NUnit.Core;
 17
 18namespace NUnit.Util
 19{
 20	/// <summary>
 21	/// Summary description for ProcessRunner.
 22	/// </summary>
 23	public class ProcessRunner : ProxyTestRunner
 24	{
 25        static Logger log = InternalTrace.GetLogger(typeof(ProcessRunner));
 26
 27		private TestAgent agent;
 28
 29        private RuntimeFramework runtimeFramework;
 30
 31		#region Constructors
 32		public ProcessRunner() : base( 0 ) { }
 33
 34		public ProcessRunner( int runnerID ) : base( runnerID ) { }
 35		#endregion
 36
 37        #region Properties
 38        public RuntimeFramework RuntimeFramework
 39        {
 40            get { return runtimeFramework; }
 41        }
 42        #endregion
 43
 44        public override bool Load(TestPackage package)
 45		{
 46            log.Info("Loading " + package.Name);
 47			Unload();
 48
 49            runtimeFramework = package.Settings["RuntimeFramework"] as RuntimeFramework;
 50            if ( runtimeFramework == null )
 51                 runtimeFramework = RuntimeFramework.CurrentFramework;
 52
 53            bool enableDebug = package.GetSetting("EnableDebug", false);
 54
 55            bool loaded = false;
 56
 57			try
 58			{
 59                if (this.agent == null)
 60                {
 61                    this.agent = Services.TestAgency.GetAgent(
 62                        runtimeFramework,
 63                        30000,
 64                        enableDebug);
 65
 66                    if (this.agent == null)
 67                        return false;
 68                }
 69	
 70				if ( this.TestRunner == null )
 71					this.TestRunner = agent.CreateRunner(this.runnerID);
 72
 73				loaded = base.Load (package);
 74                return loaded;
 75			}
 76			finally
 77			{
 78                // Clean up if the load failed
 79				if ( !loaded ) Unload();
 80			}
 81		}
 82
 83        public override void Unload()
 84        {
 85            if (Test != null)
 86            {
 87                log.Info("Unloading " + Path.GetFileName(Test.TestName.Name));
 88                this.TestRunner.Unload();
 89                this.TestRunner = null;
 90            }
 91		}
 92
 93		#region IDisposable Members
 94
 95		public override void Dispose()
 96		{
 97            // Do this first, because the next step will
 98            // make the downstream runner inaccessible.
 99            base.Dispose();
100
101            if (this.agent != null)
102            {
103                log.Info("Stopping remote agent");
104                agent.Stop();
105                this.agent = null;
106            }
107        }
108
109		#endregion
110	}
111}