using System; using System.IO; using StellaOps.Notify.WebService.Options; using StellaOps.Plugin.Hosting; namespace StellaOps.Notify.WebService.Hosting; internal static class NotifyPluginHostFactory { public static PluginHostOptions Build(NotifyWebServiceOptions options, string contentRootPath) { ArgumentNullException.ThrowIfNull(options); ArgumentNullException.ThrowIfNull(contentRootPath); var hostOptions = new PluginHostOptions { BaseDirectory = options.Plugins.BaseDirectory ?? Path.Combine(contentRootPath, ".."), PluginsDirectory = options.Plugins.Directory ?? Path.Combine("plugins", "notify"), PrimaryPrefix = "StellaOps.Notify" }; if (!Path.IsPathRooted(hostOptions.BaseDirectory)) { hostOptions.BaseDirectory = Path.GetFullPath(Path.Combine(contentRootPath, hostOptions.BaseDirectory)); } if (!Path.IsPathRooted(hostOptions.PluginsDirectory)) { hostOptions.PluginsDirectory = Path.Combine(hostOptions.BaseDirectory, hostOptions.PluginsDirectory); } foreach (var pattern in options.Plugins.SearchPatterns) { hostOptions.SearchPatterns.Add(pattern); } foreach (var prefix in options.Plugins.OrderedPlugins) { hostOptions.PluginOrder.Add(prefix); } return hostOptions; } }