예제 #1
0
        public void AddHintDirectory(string hintDirectory)
        {
            if (assemblyLoader == null)
                assemblyLoader = new DefaultAssemblyLoader();

            assemblyLoader.AddHintDirectory(hintDirectory);
        }
예제 #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();
        }
예제 #3
0
        /// <summary>
        /// Creates a local host.
        /// </summary>
        /// <param name="hostSetup">The host setup.</param>
        /// <param name="logger">The logger for host message output.</param>
        /// <param name="debuggerManager">The debugger manager.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>, <paramref name="logger"/>
        /// or <paramref name="debuggerManager"/> is null.</exception>
        public LocalHost(HostSetup hostSetup, ILogger logger, IDebuggerManager debuggerManager)
            : base(hostSetup, logger)
        {
            if (debuggerManager == null)
                throw new ArgumentNullException("debuggerManager");

            this.debuggerManager = debuggerManager;

            if (! string.IsNullOrEmpty(hostSetup.WorkingDirectory))
                currentDirectorySwitcher = new CurrentDirectorySwitcher(hostSetup.WorkingDirectory);

            if (hostSetup.HintDirectories.Count != 0)
            {
                assemblyLoader = new DefaultAssemblyLoader();
                GenericCollectionUtils.ForEach(hostSetup.HintDirectories, assemblyLoader.AddHintDirectory);
            }
        }
예제 #4
0
        public void Dispose()
        {
            if (serverChannel != null)
            {
                serverChannel.Dispose();
                serverChannel = null;
            }

            if (callbackChannel != null)
            {
                callbackChannel.Dispose();
                callbackChannel = null;
            }

            if (assemblyLoader != null)
            {
                assemblyLoader.Dispose();
                assemblyLoader = null;
            }
        }
예제 #5
0
        /// <inheritdoc />
        protected override void Dispose(bool disposing)
        {
            if (assemblyLoader != null)
            {
                assemblyLoader.Dispose();
                assemblyLoader = null;
            }

            if (currentDirectorySwitcher != null)
            {
                currentDirectorySwitcher.Dispose();
                currentDirectorySwitcher = null;
            }

            base.Dispose(disposing);
        }