<commit_before>﻿using HTCSharp.Core.Interfaces.Plugin;
using HTCSharp.Core.IO;
using HTCSharp.Core.Logging;
using HTCSharp.Core.Utils;
using McMaster.NETCore.Plugins;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace HTCSharp.Core.Managers {
    public class PluginManager {
        private static readonly ILog _Logger = LogManager.GetILog(MethodBase.GetCurrentMethod().DeclaringType);

        private List<IHTCPlugin> Plugins;
        private string PluginsPath;

        public PluginManager(string path) {
            PluginsPath = path;
            Plugins = new List<IHTCPlugin>();
        }

        public IHTCPlugin[] GetPlugins { get { return Plugins.ToArray(); } }

        public void Call_OnLoad() {
            foreach (IHTCPlugin plugin in Plugins) {
                _Logger.Info($"Loading: {plugin.PluginName}({plugin.PluginVersion})");
                plugin.OnLoad();
            }
        }

        public void Call_OnEnable() {
            foreach (IHTCPlugin plugin in Plugins) {
                plugin.OnEnable();
                _Logger.Info($"Enabled: {plugin.PluginName}({plugin.PluginVersion})");
            }
        }

        public void Call_OnDisable() {
            foreach (IHTCPlugin plugin in Plugins) {
                plugin.OnDisable();
                _Logger.Info($"Disabled: {plugin.PluginName}({plugin.PluginVersion})");
            }
        }

        public void ConstructPlugins() {
            if(!Directory.Exists(PluginsPath)) {
                _Logger.Fatal($"Plugins path '{PluginsPath}' does not exist!");
                Environment.Exit(2);
            }
            var loaders = new List<PluginLoader>();
            foreach (var pluginConfig in IOUtils.GetFilesExceptionFix(PluginsPath, "*.config", System.IO.SearchOption.AllDirectories)) {
                if (File.Exists(pluginConfig)) {
                    var loader = PluginLoader.CreateFromConfigFile(pluginConfig, sharedTypes: new[] { typeof(IHTCPlugin), typeof(IHttpEvents), typeof(Models.Http.HTCHttpContext) });
                    loaders.Add(loader);
                }
            }
            Plugins = new List<IHTCPlugin>();
            foreach (var loader in loaders) {
                foreach (var pluginType in loader
                    .LoadDefaultAssembly()
                    .GetTypes()
                    .Where(t => typeof(IHTCPlugin).IsAssignableFrom(t) && !t.IsAbstract)) {
                    IHTCPlugin plugin = (IHTCPlugin)Activator.CreateInstance(pluginType);
                    Plugins.Add(plugin);
                }
            }
        }
    }
}<commit_msg>Change plugin loading method<commit_after>﻿using HTCSharp.Core.Interfaces.Plugin;
using HTCSharp.Core.IO;
using HTCSharp.Core.Logging;
using HTCSharp.Core.Utils;
using McMaster.NETCore.Plugins;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace HTCSharp.Core.Managers {
    public class PluginManager {
        private static readonly ILog _Logger = LogManager.GetILog(MethodBase.GetCurrentMethod().DeclaringType);

        private List<IHTCPlugin> Plugins;
        private string PluginsPath;

        public PluginManager(string path) {
            PluginsPath = path;
            Plugins = new List<IHTCPlugin>();
        }

        public IHTCPlugin[] GetPlugins { get { return Plugins.ToArray(); } }

        public void Call_OnLoad() {
            foreach (IHTCPlugin plugin in Plugins) {
                _Logger.Info($"Loading: {plugin.PluginName}({plugin.PluginVersion})");
                plugin.OnLoad();
            }
        }

        public void Call_OnEnable() {
            foreach (IHTCPlugin plugin in Plugins) {
                plugin.OnEnable();
                _Logger.Info($"Enabled: {plugin.PluginName}({plugin.PluginVersion})");
            }
        }

        public void Call_OnDisable() {
            foreach (IHTCPlugin plugin in Plugins) {
                plugin.OnDisable();
                _Logger.Info($"Disabled: {plugin.PluginName}({plugin.PluginVersion})");
            }
        }

        public void ConstructPlugins() {
            if(!Directory.Exists(PluginsPath)) {
                _Logger.Fatal($"Plugins path '{PluginsPath}' does not exist!");
                Environment.Exit(2);
            }
            var loaders = new List<PluginLoader>();
            foreach (var pluginConfig in IOUtils.GetFilesExceptionFix(PluginsPath, "*.config", System.IO.SearchOption.AllDirectories)) {
                if (File.Exists(pluginConfig)) {
                    
                    var loader = PluginLoader.CreateFromAssemblyFile(pluginConfig, sharedTypes: new[] { typeof(IHTCPlugin), typeof(IHttpEvents), typeof(Models.Http.HTCHttpContext) });
                    loaders.Add(loader);
                }
            }
            Plugins = new List<IHTCPlugin>();
            foreach (var loader in loaders) {
                foreach (var pluginType in loader
                    .LoadDefaultAssembly()
                    .GetTypes()
                    .Where(t => typeof(IHTCPlugin).IsAssignableFrom(t) && !t.IsAbstract)) {
                    var plugin = (IHTCPlugin)Activator.CreateInstance(pluginType);
                    Plugins.Add(plugin);
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.10477771628850766, 'fraction_numerical': 0.00036893562073418186, 'mean_word_length': 1.9972360420121613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '236031', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1391, 'n_words': 285}