public FacadeTaskResult Execute(IFacadeTaskServer facadeTaskServer, IFacadeLogger facadeLogger, FacadeTask facadeTask, FacadeTaskExecutorConfiguration facadeTaskExecutorConfiguration)
        {
            ILogger logger = new FacadeLoggerWrapper(facadeLogger);
            try
            {
                RuntimeAccessor.Instance.AddLogListener(logger);

                return facadeTask.Execute(facadeTaskServer, facadeLogger, facadeTaskExecutorConfiguration);
            }
            finally
            {
                RuntimeAccessor.Instance.RemoveLogListener(logger);
            }
        }
        public FacadeTaskResult Execute(IFacadeTaskServer facadeTaskServer, IFacadeLogger facadeLogger, FacadeTask facadeTask, FacadeTaskExecutorConfiguration facadeTaskExecutorConfiguration)
        {
            ILogger logger = new FacadeLoggerWrapper(facadeLogger);

            try
            {
                RuntimeAccessor.Instance.AddLogListener(logger);

                return(facadeTask.Execute(facadeTaskServer, facadeLogger, facadeTaskExecutorConfiguration));
            }
            finally
            {
                RuntimeAccessor.Instance.RemoveLogListener(logger);
            }
        }
        private FacadeTaskResult RunTests()
        {
            var logger = new FacadeLoggerWrapper(facadeLogger);
            var runner = TestRunnerUtils.CreateTestRunnerByName(StandardTestRunnerFactoryNames.IsolatedAppDomain);

            // Set parameters.
            var testPackage = new TestPackage();
            foreach (var assemblyLocation in assemblyLocations)
                testPackage.AddFile(new FileInfo(assemblyLocation));

            testPackage.ShadowCopy = facadeTaskExecutorConfiguration.ShadowCopy;

            if (facadeTaskExecutorConfiguration.AssemblyFolder != null)
            {
                testPackage.ApplicationBaseDirectory = new DirectoryInfo(facadeTaskExecutorConfiguration.AssemblyFolder);
                testPackage.WorkingDirectory = new DirectoryInfo(facadeTaskExecutorConfiguration.AssemblyFolder);
            }

            var testRunnerOptions = new TestRunnerOptions();

            var testExplorationOptions = new TestExplorationOptions();

            var filters = GenericCollectionUtils.ConvertAllToArray<string, Filter<string>>(explicitTestIds, 
                testId => new EqualityFilter<string>(testId));
            var filterSet = new FilterSet<ITestDescriptor>(new IdFilter<ITestDescriptor>(new OrFilter<string>(filters)));
            var testExecutionOptions = new TestExecutionOptions { FilterSet = filterSet };

            // Install the listeners.
            runner.Events.TestStepStarted += TestStepStarted;
            runner.Events.TestStepFinished += TestStepFinished;
            runner.Events.TestStepLifecyclePhaseChanged += TestStepLifecyclePhaseChanged;

            // Run the tests.
            try
            {
                try
                {
                    runner.Initialize(testRunnerOptions, logger, CreateProgressMonitor());
                    Report report = runner.Run(testPackage, testExplorationOptions, testExecutionOptions, CreateProgressMonitor());

                    if (sessionId != null)
                        SessionCache.SaveSerializedReport(sessionId, report);

                    return FacadeTaskResult.Success;
                }
                catch (Exception ex)
                {
                    if (sessionId != null)
                        SessionCache.ClearSerializedReport(sessionId);

                    logger.Log(LogSeverity.Error, "A fatal exception occurred during test execution.", ex);
                    return FacadeTaskResult.Exception;
                }
                finally
                {
                    SubmitFailureForRemainingPendingTasks();
                }
            }
            finally
            {
                runner.Dispose(CreateProgressMonitor());
            }
        }