<commit_before>﻿using Microsoft.Extensions.Logging;
using NetFusion.Bootstrap.Container;
using NetFusion.Bootstrap.Exceptions;
using NetFusion.Common;
using System;
using System.Collections.Generic;
using System.Linq;

namespace NetFusion.Bootstrap.Plugins
{
    /// <summary>
    /// Class containing information that can be used by a given module.
    /// </summary>
    public class ModuleContext
    {
        private readonly CompositeApplication _compositeApp;

        /// <summary>
        /// The plug-in representing the application host.
        /// </summary>
        public Plugin AppHost { get; }

        /// <summary>
        /// The plug-in where the module is defined.
        /// </summary>
        public Plugin Plugin { get; }

        public ILoggerFactory LoggerFactory { get; }

        /// <summary>
        /// Logger with plug-in context.
        /// </summary>
        public ILogger Logger { get; }

        /// <summary>
        /// All plug-in modules.
        /// </summary>
        public IEnumerable<IPluginModule> AllPluginModules { get; }

        /// <summary>
        /// The plug-in types that can be accessed by the module limited to
        /// the set based on its type of plug-in.
        /// </summary>
        public IEnumerable<Type> AllPluginTypes { get; }

        /// <summary>
        /// The plug-in types limited to just those associated with application
        /// centric plug-ins.  The module is within an application centric plug-in,
        /// then this list will be the same as AllPluginTypes.
        /// </summary>
        public IEnumerable<Type> AllAppPluginTypes { get; }

        /// <summary>
        /// The plug-in types limited to just those associated with a core plug-in.
        /// If this property is called by a module contained within an application
        /// centric plug-in an empty list will be returned.
        /// </summary>
        public IEnumerable<Type> AllCorePluginTypes { get; }

        internal ModuleContext(
            ILoggerFactory loggerFactory,
            CompositeApplication compositeApp, 
            Plugin plugin)
        {
            Check.NotNull(loggerFactory, nameof(loggerFactory));
            Check.NotNull(compositeApp, nameof(compositeApp));
            Check.NotNull(plugin, nameof(plugin));

            _compositeApp = compositeApp;

            this.AppHost = compositeApp.AppHostPlugin;
            this.AllPluginModules = compositeApp.AllPluginModules;
            this.Plugin = plugin;
            this.LoggerFactory = loggerFactory;
            this.Logger = loggerFactory.CreateLogger(plugin.GetType());

            this.AllPluginTypes = FilteredTypesByPluginType();
            this.AllAppPluginTypes = GetAppPluginTypes();
            this.AllCorePluginTypes = GetCorePluginTypes();
        }

        private IList<Type> FilteredTypesByPluginType()
        {
            // Core plug-in can access types from all other plug-in types.
            if (this.Plugin.PluginType == PluginTypes.CorePlugin)
            {<commit_msg>Removed the AllCorePluginTypes property from the ModuleContext.  There is really no reason why a plug-in module would need to just reference just core plugin types.<commit_after>﻿using Microsoft.Extensions.Logging;
using NetFusion.Bootstrap.Container;
using NetFusion.Bootstrap.Exceptions;
using NetFusion.Common;
using System;
using System.Collections.Generic;
using System.Linq;

namespace NetFusion.Bootstrap.Plugins
{
    /// <summary>
    /// Class containing information that can be used by a given module.
    /// </summary>
    public class ModuleContext
    {
        private readonly CompositeApplication _compositeApp;

        /// <summary>
        /// The plug-in representing the application host.
        /// </summary>
        public Plugin AppHost { get; }

        /// <summary>
        /// The plug-in where the module is defined.
        /// </summary>
        public Plugin Plugin { get; }

        public ILoggerFactory LoggerFactory { get; }

        /// <summary>
        /// Logger with plug-in context.
        /// </summary>
        public ILogger Logger { get; }

        /// <summary>
        /// All plug-in modules.
        /// </summary>
        public IEnumerable<IPluginModule> AllPluginModules { get; }

        /// <summary>
        /// The plug-in types that can be accessed by the module limited to
        /// the set based on its type of plug-in.
        /// </summary>
        public IEnumerable<Type> AllPluginTypes { get; }

        /// <summary>
        /// The plug-in types limited to just those associated with application
        /// centric plug-ins.  If the module is within an application centric plug-in,
        /// then this list will be the same as AllPluginTypes.
        /// </summary>
        public IEnumerable<Type> AllAppPluginTypes { get; }

        internal ModuleContext(
            ILoggerFactory loggerFactory,
            CompositeApplication compositeApp, 
            Plugin plugin)
        {
            Check.NotNull(loggerFactory, nameof(loggerFactory));
            Check.NotNull(compositeApp, nameof(compositeApp));
            Check.NotNull(plugin, nameof(plugin));

            _compositeApp = compositeApp;

            this.AppHost = compositeApp.AppHostPlugin;
            this.AllPluginModules = compositeApp.AllPluginModules;
            this.Plugin = plugin;
            this.LoggerFactory = loggerFactory;
            this.Logger = loggerFactory.CreateLogger(plugin.GetType());

            this.AllPluginTypes = FilteredTypesByPluginType();
            this.AllAppPluginTypes = GetAppPluginTypes();
        }

        private IList<Type> FilteredTypesByPluginType()
        {
            // Core plug-in can access types from all other plug-in types.
            if (this.Plugin.PluginType == PluginTypes.CorePlugin)
            {
{'fraction_non_alphanumeric': 0.09437819420783645, 'fraction_numerical': 0.0, 'mean_word_length': 2.040393578456758, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, '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': '6982720', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1448, 'n_words': 447}