public static bool is_resolved() { if (ApplicationParameters.get_merged_assembly_name() == ApplicationParameters.default_merged_assembly_name) { return(true); } string log4net_file = "log4net.dll"; bool log4net_dll_exists = false; if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, log4net_file))) { log4net_dll_exists = true; } if (!log4net_dll_exists) { //try to resolve it anywhere try { DefaultAssemblyLoader.load_assembly(log4net_file); log4net_dll_exists = true; } catch (Exception) { //the file doesn't exist } } return(log4net_dll_exists); }
public void WhenGetAssemblies_ShouldReturnAssemblies() { var loader = new DefaultAssemblyLoader(); var assemblies = loader.GetAssemblies(); assemblies.First(a => a.FullName == GetType().GetTypeInfo().Assembly.FullName); }
public async Task Unload_No_PathToAssembly_Throws_ArgumentNullException() { var loader = new DefaultAssemblyLoader(() => null); var loadContext = new PluginLoadContext("Path To Plugin", this.GetType(), "netcoreapp3.1"); loadContext.FullPathToPluginAssembly = null; await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => loader.Unload(loadContext)); }
public void ShouldLoad_Assembly_FileByStringName() { var loader = new DefaultAssemblyLoader(); var assembly = loader.LoadFromFile("BetterModules.Sample.Module.dll"); Assert.IsNotNull(assembly); Assert.IsTrue(assembly.FullName.StartsWith("BetterModules.Sample.Module")); }
public void AddHintDirectory(string hintDirectory) { if (assemblyLoader == null) { assemblyLoader = new DefaultAssemblyLoader(); } assemblyLoader.AddHintDirectory(hintDirectory); }
public void ShouldLoad_Assembly_GetLoadableTypes() { var type = GetType(); var assembly = type.Assembly; var loader = new DefaultAssemblyLoader(); var types = loader.GetLoadableTypes(assembly); Assert.IsNotNull(types); Assert.Greater(types.Count(), 1); Assert.IsTrue(types.Contains(GetType())); }
public void ShouldLoad_Assembly_GetLoadableTypes_Generic() { var type = GetType(); var assembly = type.Assembly; var loader = new DefaultAssemblyLoader(); var testBaseType = typeof(TestBase); var types = loader.GetLoadableTypes(assembly, testBaseType); Assert.IsNotNull(types); Assert.Greater(types.Count(), 1); Assert.IsTrue(types.Contains(GetType())); Assert.IsTrue(types.All(testBaseType.IsAssignableFrom)); }
public async Task Load_Works() { var mockLoadContext = this.mockRepository.Create <IAssemblyLoadContext>(); var assemblyShim = this.mockRepository.Create <IAssemblyShim>(); var loader = new DefaultAssemblyLoader(() => mockLoadContext.Object); var loadContext = new PluginLoadContext("/home/maarten/assembly.dll", this.GetType(), "netcoreapp3.1"); mockLoadContext.Setup(c => c.LoadPluginAssembly(loadContext)).ReturnsAsync(assemblyShim.Object); var assembly = await loader.Load(loadContext); Assert.AreEqual(assemblyShim.Object, assembly); }
/// <inheritdoc /> protected override void Dispose(bool disposing) { if (assemblyLoader != null) { assemblyLoader.Dispose(); assemblyLoader = null; } if (currentDirectorySwitcher != null) { currentDirectorySwitcher.Dispose(); currentDirectorySwitcher = null; } base.Dispose(disposing); }
public ISessionFactory build_session_factory(Action <Configuration> additional_function) { string top_namespace = configuration_holder.DatabaseType.Substring(0, configuration_holder.DatabaseType.IndexOf(',')); top_namespace = top_namespace.Substring(0, top_namespace.LastIndexOf('.')); string assembly_name = configuration_holder.DatabaseType.Substring(configuration_holder.DatabaseType.IndexOf(',') + 1); try { string key = configuration_holder.DatabaseType.Substring(0, configuration_holder.DatabaseType.IndexOf(',')) + ", " + ApplicationParameters.get_merged_assembly_name(); return(build_session_factory(func_dictionary[key](), DefaultAssemblyLoader.load_assembly(ApplicationParameters.get_merged_assembly_name()), top_namespace, additional_function)); } catch (Exception) { is_merged = false; return(build_session_factory(func_dictionary[configuration_holder.DatabaseType](), DefaultAssemblyLoader.load_assembly(assembly_name), top_namespace, additional_function)); } }
public void Dispose() { if (serverChannel != null) { serverChannel.Dispose(); serverChannel = null; } if (callbackChannel != null) { callbackChannel.Dispose(); callbackChannel = null; } if (assemblyLoader != null) { assemblyLoader.Dispose(); assemblyLoader = null; } }
/// <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()); }
/// <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); } }
public ISessionFactory build_session_factory(Action <Configuration> additional_function) { string top_namespace = configuration_holder.DatabaseType.Substring(0, configuration_holder.DatabaseType.IndexOf(',')); top_namespace = top_namespace.Substring(0, top_namespace.LastIndexOf('.')); string assembly_name = configuration_holder.DatabaseType.Substring(configuration_holder.DatabaseType.IndexOf(',') + 1); try { string key = configuration_holder.DatabaseType.Substring(0, configuration_holder.DatabaseType.IndexOf(',')) + ", " + ApplicationParameters.get_merged_assembly_name(); return(build_session_factory(func_dictionary[key](), Assembly.GetExecutingAssembly(), top_namespace, additional_function)); //return build_session_factory(func_dictionary[key](), DefaultAssemblyLoader.load_assembly(ApplicationParameters.get_merged_assembly_name()), //top_namespace, additional_function); } catch (Exception ex) { // Changed from warning to debug. I may not be using session factory and this warning just adds noise. Log.bound_to(this).log_a_debug_event_containing("Had an error building session factory from merged, attempting unmerged. The error:{0}{1}", System.Environment.NewLine, ex.ToString()); return(build_session_factory(func_dictionary[configuration_holder.DatabaseType](), DefaultAssemblyLoader.load_assembly(assembly_name), top_namespace, additional_function)); } }
public async Task Unload_UnRooted_PathToAssembly_Throws_ArgumentNullException() { var loader = new DefaultAssemblyLoader(() => null); var loadContext = new PluginLoadContext("../testpath", this.GetType(), "netcoreapp3.1"); await Assert.ThrowsExceptionAsync <AssemblyLoadingException>(() => loader.Unload(loadContext)); }
public async Task Unload_No_Context_Throws_ArgumentNullException() { var loader = new DefaultAssemblyLoader(() => null); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => loader.Unload(null)); }