<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using AppBrix.Backgammon.Bots;
using AppBrix.Caching;
using AppBrix.Cloning;
using AppBrix.Configuration;
using AppBrix.Container;
using AppBrix.Events;
using AppBrix.Events.Async;
using AppBrix.Factory;
using AppBrix.Lifecycle;
using AppBrix.Logging;
using AppBrix.Logging.Console;
using AppBrix.Logging.File;
using AppBrix.Modules;
using AppBrix.Time;
using AppBrix.Web.Client;
using AppBrix.Web.Server;

namespace AppBrix.Backgammon.ConsoleApp
{
    /// <summary>
    /// Initializes application configuration.
    /// This module should be first on the list in order to configure the application's configuration.
    /// </summary>
    public class ConfigInitializerModule : IModule, IInstallable
    {
        #region Public and overriden methods
        public void Install(IInstallContext context)
        {
            this.InitializeAppConfig(context.App.ConfigManager);
            context.RequestedAction = RequestedAction.Restart;
        }

        public void Upgrade(IUpgradeContext context)
        {
        }

        public void Uninstall(IUninstallContext context)
        {
            throw new NotSupportedException($@"Module {nameof(ConfigInitializerModule)} does not support uninstallation.");
        }

        public void Initialize(IInitializeContext context)
        {
        }

        public void Uninitialize()
        {
        }
        #endregion

        #region Private methods
        private void InitializeAppConfig(IConfigManager manager)
        {
            var config = manager.Get<AppConfig>();
            if (config.Modules.Count > 1)
                throw new InvalidOperationException($@"Module {nameof(ConfigInitializerModule)} found other modules registered besides itself.");

            foreach (var module in ConfigInitializerModule.Modules)
            {
                var element = ModuleConfigElement.Create(module);
                if (ConfigInitializerModule.DisabledModules.Contains(module))
                    element.Status = ModuleStatus.Disabled;
                config.Modules.Add(element);
            }
        }
        #endregion

        #region Private fields and constants
        private static readonly IEnumerable<Type> Modules = new List<Type>()
        {
            typeof(AsyncEventsModule),
            typeof(BackgammonModule),
            typeof(BotsModule),
            typeof(CachingModule),
            typeof(CloningModule),
            typeof(ContainerModule),
            typeof(EventsModule),
            typeof(FactoryModule),
            typeof(LoggingModule),
            typeof(ConsoleLoggerModule),
            typeof(FileLoggerModule),
            typeof(TimeModule),
            typeof(WebClientModule),
            typeof(WebServerModule)
        };

        private static readonly HashSet<Type> DisabledModules = new HashSet<Type>()
        {
            typeof(CachingModule),
            typeof(CloningModule),
            typeof(FileLoggerModule),
            typeof(WebClientModule),
            typeof(WebServerModule)
        };
        #endregion
    }
}<commit_msg>Added JsonCachingModule and MemoryCachingModule to the config.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using AppBrix.Backgammon.Bots;
using AppBrix.Caching;
using AppBrix.Cloning;
using AppBrix.Configuration;
using AppBrix.Container;
using AppBrix.Events;
using AppBrix.Events.Async;
using AppBrix.Factory;
using AppBrix.Lifecycle;
using AppBrix.Logging;
using AppBrix.Logging.Console;
using AppBrix.Logging.File;
using AppBrix.Modules;
using AppBrix.Time;
using AppBrix.Web.Client;
using AppBrix.Web.Server;
using AppBrix.Caching.Memory;
using AppBrix.Caching.Json;

namespace AppBrix.Backgammon.ConsoleApp
{
    /// <summary>
    /// Initializes application configuration.
    /// This module should be first on the list in order to configure the application's configuration.
    /// </summary>
    public class ConfigInitializerModule : IModule, IInstallable
    {
        #region Public and overriden methods
        public void Install(IInstallContext context)
        {
            this.InitializeAppConfig(context.App.ConfigManager);
            context.RequestedAction = RequestedAction.Restart;
        }

        public void Upgrade(IUpgradeContext context)
        {
        }

        public void Uninstall(IUninstallContext context)
        {
            throw new NotSupportedException($@"Module {nameof(ConfigInitializerModule)} does not support uninstallation.");
        }

        public void Initialize(IInitializeContext context)
        {
        }

        public void Uninitialize()
        {
        }
        #endregion

        #region Private methods
        private void InitializeAppConfig(IConfigManager manager)
        {
            var config = manager.Get<AppConfig>();
            if (config.Modules.Count > 1)
                throw new InvalidOperationException($@"Module {nameof(ConfigInitializerModule)} found other modules registered besides itself.");

            foreach (var module in ConfigInitializerModule.Modules)
            {
                var element = ModuleConfigElement.Create(module);
                if (ConfigInitializerModule.DisabledModules.Contains(module))
                    element.Status = ModuleStatus.Disabled;
                config.Modules.Add(element);
            }
        }
        #endregion

        #region Private fields and constants
        private static readonly IEnumerable<Type> Modules = new List<Type>()
        {
            typeof(AsyncEventsModule),
            typeof(BackgammonModule),
            typeof(BotsModule),
            typeof(CachingModule),
            typeof(JsonCachingModule),
            typeof(MemoryCachingModule),
            typeof(CloningModule),
            typeof(ContainerModule),
            typeof(EventsModule),
            typeof(FactoryModule),
            typeof(LoggingModule),
            typeof(ConsoleLoggerModule),
            typeof(FileLoggerModule),
            typeof(TimeModule),
            typeof(WebClientModule),
            typeof(WebServerModule)
        };

        private static readonly HashSet<Type> DisabledModules = new HashSet<Type>()
        {
            typeof(CachingModule),
            typeof(JsonCachingModule),
            typeof(MemoryCachingModule),
            typeof(CloningModule),
            typeof(FileLoggerModule),
            typeof(WebClientModule),
            typeof(WebServerModule)
        };
        #endregion
    }
}
{'fraction_non_alphanumeric': 0.07935062964648763, 'fraction_numerical': 0.00030344409042633893, 'mean_word_length': 2.332659251769464, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '6438236', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1635, 'n_words': 368}