/// <summary> /// Compiles the code and runs the test against the submitted code. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompileAndRunResponse"/>. /// </returns> /// <exception cref="FaultException">Unhandled exception /// </exception> public CompileAndRunResponse CompileAndRunTests(CompileAndRunRequest request) { string pathToDlls = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); Trace.WriteLine(AppDomain.CurrentDomain.FriendlyName); AppDomainSetup domainSetup = new AppDomainSetup { /*PrivateBinPath = Assembly.GetExecutingAssembly().CodeBase */ }; domainSetup.ApplicationBase = pathToDlls; this.testDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, domainSetup, this.GetPermissionSet()); try { return(this.Run(request)); } catch (Exception exception) { // Throw the unhandled exception as fault throw new FaultException(exception.Message); } finally { this.Cleanup(); } }
/// <summary> /// Runs a test in another application domain. /// </summary> /// <param name="args"> /// The arguments to pass to the runner inside the application domain. /// </param> /// <returns> /// The exception that occurred in the test, or null if no exception occurred. /// </returns> public CompileAndRunResponse Run(CompileAndRunRequest args) { this.testDomain.Load(Assembly.GetExecutingAssembly().GetName()); var instance = (CompilerService)this.testDomain.CreateInstanceAndUnwrap( typeof(CompilerService).Assembly.FullName, typeof(CompilerService).FullName); return(instance.CompileAndRunTestsInOtherDomain(args)); }
/// <summary> /// The compile and run tests in other domain. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompileAndRunResponse"/>. /// </returns> /// <exception cref="FaultException">Unhandled exception /// </exception> public CompileAndRunResponse CompileAndRunTestsInOtherDomain(CompileAndRunRequest request) { Trace.WriteLine(AppDomain.CurrentDomain.FriendlyName); var compileResponse = this.Compile(request); if (!string.IsNullOrEmpty(compileResponse.CompileResult.Error)) { return(new CompileAndRunResponse { CompileResult = compileResponse.CompileResult }); } this.CreateDomainAndUnwrapObject(compileResponse.CompileResult.LoadedStream, compileResponse.CompileResult.AssemblyFileName); // Ready to run the tests. CoreExtensions.Host.InstallBuiltins(); // run the test in safe mode so that service doesn't go in faulted state. try { var runnerResult = new InMemoryNunitTestRunner().RunTests( new TestRunRequest { TestAssembly = Assembly.Load(CsharpRulesAssemblyName) }); return(new CompileAndRunResponse { TestResult = runnerResult, CompileResult = new CompileResult() }); } catch (Exception exception) { // Throw the unhandled exception as fault throw new FaultException(exception.Message); } }
/// <summary> /// Compiles the code and runs the test against the submitted code. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompileAndRunResponse"/>. /// </returns> /// <exception cref="FaultException">Unhandled exception /// </exception> public CompileAndRunResponse CompileAndRunTests(CompileAndRunRequest request) { string pathToDlls = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); Trace.WriteLine(AppDomain.CurrentDomain.FriendlyName); AppDomainSetup domainSetup = new AppDomainSetup { /*PrivateBinPath = Assembly.GetExecutingAssembly().CodeBase */ }; domainSetup.ApplicationBase = pathToDlls; this.testDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, domainSetup, this.GetPermissionSet()); try { return this.Run(request); } catch (Exception exception) { // Throw the unhandled exception as fault throw new FaultException(exception.Message); } finally { this.Cleanup(); } }
/// <summary> /// Runs a test in another application domain. /// </summary> /// <param name="args"> /// The arguments to pass to the runner inside the application domain. /// </param> /// <returns> /// The exception that occurred in the test, or null if no exception occurred. /// </returns> public CompileAndRunResponse Run(CompileAndRunRequest args) { this.testDomain.Load(Assembly.GetExecutingAssembly().GetName()); var instance = (CompilerService)this.testDomain.CreateInstanceAndUnwrap( typeof(CompilerService).Assembly.FullName, typeof(CompilerService).FullName); return instance.CompileAndRunTestsInOtherDomain(args); }
/// <summary> /// The compile and run tests in other domain. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompileAndRunResponse"/>. /// </returns> /// <exception cref="FaultException">Unhandled exception /// </exception> public CompileAndRunResponse CompileAndRunTestsInOtherDomain(CompileAndRunRequest request) { Trace.WriteLine(AppDomain.CurrentDomain.FriendlyName); var compileResponse = this.Compile(request); if (!string.IsNullOrEmpty(compileResponse.CompileResult.Error)) { return new CompileAndRunResponse { CompileResult = compileResponse.CompileResult }; } this.CreateDomainAndUnwrapObject(compileResponse.CompileResult.LoadedStream, compileResponse.CompileResult.AssemblyFileName); // Ready to run the tests. CoreExtensions.Host.InstallBuiltins(); // run the test in safe mode so that service doesn't go in faulted state. try { var runnerResult = new InMemoryNunitTestRunner().RunTests( new TestRunRequest { TestAssembly = Assembly.Load(CsharpRulesAssemblyName) }); return new CompileAndRunResponse { TestResult = runnerResult, CompileResult = new CompileResult() }; } catch (Exception exception) { // Throw the unhandled exception as fault throw new FaultException(exception.Message); } }