/// <summary> /// The overlay plugin settings. /// </summary> /// <param name="pluginPath"> /// The plugin Path. /// </param> private void OverlayPluginSettings(string pluginPath) { if (PluginAssemblies.Count == 0) { PluginLogger.LogInfo("No plugins detected so no pluginsettings to overlay"); } foreach (var assembly in PluginAssemblies) { var locations = GetPluginSettingsPaths(pluginPath, assembly); foreach (var settingsFile in locations) { if (!File.Exists(settingsFile)) { PluginLogger.LogDebug($"Skipping plugin settings file [{settingsFile}]: It does not exist"); continue; } if (!PerformOverlay(settingsFile)) { PluginLogger.LogFail("OverlayPluginSettings", $"Failed to overlay [{settingsFile}]. Check config file"); } } } }
/// <summary> /// The load stf plugins. /// </summary> /// <param name="stfPluginPath"> /// The stf plugin path. /// </param> /// <param name="pluginPatterns"> /// The plugin Patterns. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int LoadStfPlugins(string stfPluginPath, string pluginPatterns = "*stf.*.dll") { if (!Directory.Exists(stfPluginPath)) { return(0); } PluginLogger.LogHeader("looking for plugins at [{0}]", stfPluginPath); var patterns = pluginPatterns.Split(';'); foreach (var pattern in patterns) { var stfPluginDllFileNames = Directory.GetFiles(stfPluginPath, pattern); var assemblies = new List <Assembly>(stfPluginDllFileNames.Length); foreach (var stfPluginDllFileName in stfPluginDllFileNames) { var stfPluginDllAssemblyName = AssemblyName.GetAssemblyName(stfPluginDllFileName); var assembly = Assembly.Load(stfPluginDllAssemblyName); assemblies.Add(assembly); } foreach (var assembly in assemblies) { if (assembly == null) { continue; } var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsInterface || type.IsAbstract) { continue; } if (type.GetInterface(typeof(IStfPlugin).FullName) != null) { RegisterPlugin(type); PluginAssemblies.Add(assembly); } } } } OverlayPluginSettings(stfPluginPath); PluginLogger.LogInfo("Done looking for plugins"); return(container.Registrations.Count()); }
/// <summary> /// The perform overlay. /// </summary> /// <param name="settingsFilePath"> /// The settings file path. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool PerformOverlay(string settingsFilePath) { PluginLogger.LogInfo($"Applying plugin settings: [{settingsFilePath}]"); try { StfConfiguration.OverLay(settingsFilePath); } catch (Exception ex) { PluginLogger.LogError($"Error when overlaying plugin settings: {ex.Message}"); return(false); } return(true); }
/// <summary> /// The register type. /// </summary> /// <param name="typeToRegister"> /// The type to register. /// </param> private void RegisterPlugin(Type typeToRegister) { var interfaceName = $"I{typeToRegister.Name}"; var mainInterface = typeToRegister.GetInterface(interfaceName); if (mainInterface == null) { PluginLogger.LogWarning("Registering type [{0}] with no matching interface", typeToRegister.Name); container.RegisterType( typeToRegister, new InjectionProperty("StfContainer"), new InjectionProperty("StfLogger")); return; } PluginLogger.LogInfo("Registering type [{0}] with matching interface [{1}]", typeToRegister.Name, interfaceName); container.RegisterMyType(mainInterface, typeToRegister); }