Esempio n. 1
0
        /// <summary>
        /// Initializes the runtime.
        /// </summary>
        /// <param name="registry">The registry.</param>
        /// <param name="pluginLoader">The plugin loader.</param>
        /// <param name="assemblyLoader">The assembly loader.</param>
        /// <param name="runtimeSetup">The runtime setup options.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="registry"/>,
        /// <paramref name="pluginLoader"/>, <paramref name="assemblyLoader"/> or
        /// <paramref name="runtimeSetup" /> is null.</exception>
        public DefaultRuntime(IRegistry registry, IPluginLoader pluginLoader,
                              IAssemblyLoader assemblyLoader, RuntimeSetup runtimeSetup)
        {
            if (registry == null)
            {
                throw new ArgumentNullException("registry");
            }
            if (pluginLoader == null)
            {
                throw new ArgumentNullException("pluginLoader");
            }
            if (assemblyLoader == null)
            {
                throw new ArgumentNullException(@"assemblyResolverManager");
            }
            if (runtimeSetup == null)
            {
                throw new ArgumentNullException(@"runtimeSetup");
            }

            this.registry       = registry;
            this.pluginLoader   = pluginLoader;
            this.assemblyLoader = assemblyLoader;
            this.runtimeSetup   = runtimeSetup.Copy();

            dispatchLogger    = new DispatchLogger();
            pluginDirectories = new List <string>();
            conditionContext  = new RuntimeConditionContext();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the runtime.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Loads plugins and initalizes the runtime component model.  The
        /// specifics of the system can be configured by editing the appropriate
        /// *.plugin files to register new components and facilities as required.
        /// </para>
        /// </remarks>
        /// <param name="setup">The runtime setup parameters.</param>
        /// <param name="logger">The logger to attach, or null if none.</param>
        /// <returns>An object that when disposed automatically calls <see cref="Shutdown" />.
        /// This is particularly useful in combination with the C# "using" statement
        /// or its equivalent.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="setup"/> is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the runtime has already been initialized.</exception>
        public static IDisposable Initialize(RuntimeSetup setup, ILogger logger)
        {
            if (setup == null)
                throw new ArgumentNullException("setup");

            if (RuntimeAccessor.IsInitialized)
                throw new InvalidOperationException("The runtime has already been initialized.");

            var registry = new Registry();
            var assemblyLoader = new DefaultAssemblyLoader();
            var pluginLoader = new CachingPluginLoader();
            IRuntime runtime = new DefaultRuntime(registry, pluginLoader, assemblyLoader, setup); // TODO: make me configurable via setup
            if (logger != null)
                runtime.AddLogListener(logger);

            try
            {
                RuntimeAccessor.SetRuntime(runtime);

                runtime.Initialize();

                if (!UnhandledExceptionPolicy.HasReportUnhandledExceptionHandler)
                    UnhandledExceptionPolicy.ReportUnhandledException += HandleUnhandledExceptionNotification;
            }
            catch (Exception)
            {
                RuntimeAccessor.SetRuntime(null);
                throw;
            }

            return new AutoShutdown();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a deep copy of the runtime setup parameters.
        /// </summary>
        /// <returns>The copy.</returns>
        public RuntimeSetup Copy()
        {
            RuntimeSetup copy = new RuntimeSetup();

            copy.pluginDirectories.AddRange(pluginDirectories);
            copy.runtimePath = runtimePath;
            copy.installationConfiguration = installationConfiguration;
            copy.configurationFilePath     = configurationFilePath;
            return(copy);
        }
Esempio n. 4
0
        public Runner()
        {
            // Create a runtime setup.
            // There are a few things you can tweak here if you need.
            _setup = new Gallio.Runtime.RuntimeSetup();
            //_setup.RuntimePath = @"C:\Users\ack\bin\GallioBundle-3.2.750.0\bin"; // @"C:\Users\ack\bin\Gallio2"; //Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //@"C:\Users\ack\bin\GallioBundle-3.2.750.0\bin";
            var binPath = new BinPathLocator().Locate();

            _isInitialized = File.Exists(Path.Combine(binPath, "Gallio.dll"));
            if (!_isInitialized)
            {
                return;
            }
            _setup.RuntimePath = binPath; //@"C:\Users\ack\src\AutoTest.Net\lib\Gallio";

            // Create a logger.
            // You can use the NullLogger but you will probably want a wrapper around your own ILogger thingy.
            _logger = Gallio.Runtime.Logging.NullLogger.Instance;

            // Initialize the runtime.
            // You only do this once.
            lock (_gallioLock)
            {
                if (!_runtimeInitialized)
                {
                    RuntimeBootstrap.Initialize(_setup, _logger);
                    _runtimeInitialized = true;
                }
            }

            // Create a test framework selector.
            // This is used by Gallio to filter the set of frameworks it will support.
            // You can set a predicate Filter here.  I've hardcoded MbUnit here but you could leave the filter out and set it to null.
            // The fallback mode tells Gallio what to do if it does not recognize the test framework associated with the test assembly.
            // Strict means don't do anything.  You might want to use Default or Approximate.  See docs.
            // You can also set options, probably don't care.
            var testFrameworkSelector = new TestFrameworkSelector()
            {
                Filter       = testFrameworkHandle => testFrameworkHandle.Id == "MbUnit.TestFramework",
                FallbackMode = TestFrameworkFallbackMode.Strict
            };

            // Now we need to get a suitably configured ITestDriver...
            var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve <ITestFrameworkManager>();

            _testDriver = testFrameworkManager.GetTestDriver(testFrameworkSelector, _logger);
        }
Esempio n. 5
0
        public Runner()
        {
            // Create a runtime setup.
            // There are a few things you can tweak here if you need.
            _setup = new Gallio.Runtime.RuntimeSetup();
            //_setup.RuntimePath = @"C:\Users\ack\bin\GallioBundle-3.2.750.0\bin"; // @"C:\Users\ack\bin\Gallio2"; //Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //@"C:\Users\ack\bin\GallioBundle-3.2.750.0\bin";
            var binPath = new BinPathLocator().Locate();
            _isInitialized = File.Exists(Path.Combine(binPath, "Gallio.dll"));
            if (!_isInitialized)
                return;
            _setup.RuntimePath = binPath; //@"C:\Users\ack\src\AutoTest.Net\lib\Gallio";

            // Create a logger.
            // You can use the NullLogger but you will probably want a wrapper around your own ILogger thingy.
            _logger = Gallio.Runtime.Logging.NullLogger.Instance;

            // Initialize the runtime.
            // You only do this once.
            lock (_gallioLock)
            {
                if (!_runtimeInitialized)
                {
                    RuntimeBootstrap.Initialize(_setup, _logger);
                    _runtimeInitialized = true;
                }
            }

            // Create a test framework selector.
            // This is used by Gallio to filter the set of frameworks it will support.
            // You can set a predicate Filter here.  I've hardcoded MbUnit here but you could leave the filter out and set it to null.
            // The fallback mode tells Gallio what to do if it does not recognize the test framework associated with the test assembly.
            // Strict means don't do anything.  You might want to use Default or Approximate.  See docs.
            // You can also set options, probably don't care.
            var testFrameworkSelector = new TestFrameworkSelector()
            {
                Filter = testFrameworkHandle => testFrameworkHandle.Id == "MbUnit.TestFramework",
                FallbackMode = TestFrameworkFallbackMode.Strict
            };

            // Now we need to get a suitably configured ITestDriver...
            var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>();
            _testDriver = testFrameworkManager.GetTestDriver(testFrameworkSelector, _logger);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes the runtime.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Loads plugins and initalizes the runtime component model.  The
        /// specifics of the system can be configured by editing the appropriate
        /// *.plugin files to register new components and facilities as required.
        /// </para>
        /// </remarks>
        /// <param name="setup">The runtime setup parameters.</param>
        /// <param name="logger">The logger to attach, or null if none.</param>
        /// <returns>An object that when disposed automatically calls <see cref="Shutdown" />.
        /// This is particularly useful in combination with the C# "using" statement
        /// or its equivalent.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="setup"/> is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the runtime has already been initialized.</exception>
        public static IDisposable Initialize(RuntimeSetup setup, ILogger logger)
        {
            if (setup == null)
            {
                throw new ArgumentNullException("setup");
            }

            if (RuntimeAccessor.IsInitialized)
            {
                throw new InvalidOperationException("The runtime has already been initialized.");
            }

            var      registry       = new Registry();
            var      assemblyLoader = new DefaultAssemblyLoader();
            var      pluginLoader   = new CachingPluginLoader();
            IRuntime runtime        = new DefaultRuntime(registry, pluginLoader, assemblyLoader, setup); // TODO: make me configurable via setup

            if (logger != null)
            {
                runtime.AddLogListener(logger);
            }

            try
            {
                RuntimeAccessor.SetRuntime(runtime);

                runtime.Initialize();

                if (!UnhandledExceptionPolicy.HasReportUnhandledExceptionHandler)
                {
                    UnhandledExceptionPolicy.ReportUnhandledException += HandleUnhandledExceptionNotification;
                }
            }
            catch (Exception)
            {
                RuntimeAccessor.SetRuntime(null);
                throw;
            }

            return(new AutoShutdown());
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes the runtime.
        /// </summary>
        /// <param name="registry">The registry.</param>
        /// <param name="pluginLoader">The plugin loader.</param>
        /// <param name="assemblyLoader">The assembly loader.</param>
        /// <param name="runtimeSetup">The runtime setup options.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="registry"/>,
        /// <paramref name="pluginLoader"/>, <paramref name="assemblyLoader"/> or
        /// <paramref name="runtimeSetup" /> is null.</exception>
        public DefaultRuntime(IRegistry registry, IPluginLoader pluginLoader,
            IAssemblyLoader assemblyLoader, RuntimeSetup runtimeSetup)
        {
            if (registry == null)
                throw new ArgumentNullException("registry");
            if (pluginLoader == null)
                throw new ArgumentNullException("pluginLoader");
            if (assemblyLoader == null)
                throw new ArgumentNullException(@"assemblyResolverManager");
            if (runtimeSetup == null)
                throw new ArgumentNullException(@"runtimeSetup");

            this.registry = registry;
            this.pluginLoader = pluginLoader;
            this.assemblyLoader = assemblyLoader;
            this.runtimeSetup = runtimeSetup.Copy();

            dispatchLogger = new DispatchLogger();
            pluginDirectories = new List<string>();
            conditionContext = new RuntimeConditionContext();
        }
Esempio n. 8
0
 /// <summary>
 /// Creates a deep copy of the runtime setup parameters.
 /// </summary>
 /// <returns>The copy.</returns>
 public RuntimeSetup Copy()
 {
     RuntimeSetup copy = new RuntimeSetup();
     copy.pluginDirectories.AddRange(pluginDirectories);
     copy.runtimePath = runtimePath;
     copy.installationConfiguration = installationConfiguration;
     copy.configurationFilePath = configurationFilePath;
     return copy;
 }