using System.Reflection; using HopFrame.Core.Config; using HopFrame.Web.Components.Layout; using HopFrame.Web.Models; using HopFrame.Web.Plugins; using HopFrame.Web.Plugins.Annotations; using HopFrame.Web.Plugins.Internal; namespace HopFrame.Web; public static class HopFrameConfiguratorExtensions { /// /// Creates an entry to the side menu and dashboard with a custom url /// /// The configurator for the HopFrame config that is being created /// The name of the navigation entry /// The target url of the navigation entry public static CustomViewConfigurator AddCustomView(this HopFrameConfigurator configurator, string name, string url) { var view = new CustomView { Name = name, Url = url }; HopFrameLayout.CustomViews.Add(view); return new CustomViewConfigurator(view); } /// The delegate for configuring the view /// public static HopFrameConfigurator AddCustomView(this HopFrameConfigurator configurator, string name, string url, Action configuratorDelegate) { var viewConfigurator = AddCustomView(configurator, name, url); configuratorDelegate.Invoke(viewConfigurator); return configurator; } /// /// Registers a plugin /// /// The configurator for the HopFrame config that is being created /// The plugin that should be registered public static HopFrameConfigurator AddPlugin(this HopFrameConfigurator configurator) where TPlugin : class { PluginOrchestrator.RegisterPlugin(configurator.ServiceCollection, typeof(TPlugin)); var methods = typeof(TPlugin).GetMethods() .Where(method => method.IsStatic) .Where(method => method.GetCustomAttributes(true) .Any(attr => attr is PluginConfiguratorAttribute)) .Where(method => method.GetParameters().Length < 2); foreach (var method in methods) { if (method.GetParameters().Length > 0) method.Invoke(null, [configurator]); else method.Invoke(null, []); } return configurator; } public static HopFrameConfigurator AddExporters(this HopFrameConfigurator configurator) { configurator.AddPlugin(); return configurator; } }