PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/ProcessRunner.cs

#
C# | 111 lines | 80 code | 20 blank | 11 comment | 13 complexity | 3422e387440178baada97e7aff4bdc86 MD5 | raw file
Possible License(s): GPL-2.0
  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. using System;
  7. using System.IO;
  8. using System.Diagnostics;
  9. using System.Reflection;
  10. using System.Runtime.Remoting;
  11. using System.Runtime.Remoting.Proxies;
  12. using System.Runtime.Remoting.Services;
  13. using System.Runtime.Remoting.Channels;
  14. using System.Runtime.Remoting.Channels.Tcp;
  15. using NUnit.Core;
  16. namespace NUnit.Util
  17. {
  18. /// <summary>
  19. /// Summary description for ProcessRunner.
  20. /// </summary>
  21. public class ProcessRunner : ProxyTestRunner
  22. {
  23. static Logger log = InternalTrace.GetLogger(typeof(ProcessRunner));
  24. private TestAgent agent;
  25. private RuntimeFramework runtimeFramework;
  26. #region Constructors
  27. public ProcessRunner() : base( 0 ) { }
  28. public ProcessRunner( int runnerID ) : base( runnerID ) { }
  29. #endregion
  30. #region Properties
  31. public RuntimeFramework RuntimeFramework
  32. {
  33. get { return runtimeFramework; }
  34. }
  35. #endregion
  36. public override bool Load(TestPackage package)
  37. {
  38. log.Info("Loading " + package.Name);
  39. Unload();
  40. runtimeFramework = package.Settings["RuntimeFramework"] as RuntimeFramework;
  41. if ( runtimeFramework == null )
  42. runtimeFramework = RuntimeFramework.CurrentFramework;
  43. bool enableDebug = package.GetSetting("EnableDebug", false);
  44. bool loaded = false;
  45. try
  46. {
  47. if (this.agent == null)
  48. {
  49. this.agent = Services.TestAgency.GetAgent(
  50. runtimeFramework,
  51. 30000,
  52. enableDebug);
  53. if (this.agent == null)
  54. return false;
  55. }
  56. if ( this.TestRunner == null )
  57. this.TestRunner = agent.CreateRunner(this.runnerID);
  58. loaded = base.Load (package);
  59. return loaded;
  60. }
  61. finally
  62. {
  63. // Clean up if the load failed
  64. if ( !loaded ) Unload();
  65. }
  66. }
  67. public override void Unload()
  68. {
  69. if (Test != null)
  70. {
  71. log.Info("Unloading " + Path.GetFileName(Test.TestName.Name));
  72. this.TestRunner.Unload();
  73. this.TestRunner = null;
  74. }
  75. }
  76. #region IDisposable Members
  77. public override void Dispose()
  78. {
  79. // Do this first, because the next step will
  80. // make the downstream runner inaccessible.
  81. base.Dispose();
  82. if (this.agent != null)
  83. {
  84. log.Info("Stopping remote agent");
  85. agent.Stop();
  86. this.agent = null;
  87. }
  88. }
  89. #endregion
  90. }
  91. }