<commit_before>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;

namespace DatabaseMigrateExt
{
    public class ExtMigrationRunner
    {
        internal string RootNamespace { get; set; }
        internal SortedList<int, string> DatabaseKeys { get; set; } = new SortedList<int, string>();
        internal SortedList<int, DatabaseScriptType> DatabaseLayers { get; set; } = new SortedList<int, DatabaseScriptType>();
        internal Assembly MigrationAssembly { get; set; }

        /// <summary>
        /// Initialize default settings
        /// </summary>
        /// <returns></returns>
        public static ExtMigrationRunner Initialize()
        {
            var runner = new ExtMigrationRunner();

            #region Initialize RootNamespace

            var rootNamespaceFromAppSetting = ConfigurationManager.AppSettings["mgr:RootNamespace"];
            runner.RootNamespace = rootNamespaceFromAppSetting;

            #endregion

            #region Initialize DatabaseKeys

            if (runner.DatabaseKeys == null)
            {
                runner.DatabaseKeys = new SortedList<int, string>();
            }
            var databaseKeys = ConfigurationManager.AppSettings["mgr:DatabaseKeys"];
            if (databaseKeys != null)
            {
                var databaseKeyArr = databaseKeys.Split(',');
                if (databaseKeyArr.Any())
                {
                    for (var i = 0; i < databaseKeyArr.Length; i++)
                    {
                        runner.DatabaseKeys.Add(i, databaseKeyArr[i].Trim());
                    }
                }

            }

            #endregion

            #region Initialize DatabaseLayers

            if (runner.DatabaseLayers == null)
            {
                runner.DatabaseLayers = new SortedList<int, DatabaseScriptType>();
            }

            var layers = Enum.GetValues(typeof(DatabaseScriptType))
                .OfType<DatabaseScriptType>().OrderBy(x => x);

            foreach (var layer in layers)
            {
                runner.DatabaseLayers.Add((int)layer, layer);
            }

            #endregion

            #region Initialize MigrationAssembly

            var usedAttrAssemblies = AppDomain.CurrentDomain.GetAssemblies()
                .Where(assy => assy != typeof(ExtMigrationRunner).Assembly)
                .FirstOrDefault(assy => assy.GetTypes()
                    .Select(type => Attribute.IsDefined(type, typeof(BaseExtMgrAttribute)))
                    .Any(x => x));

            if (usedAttrAssemblies != null)
            {
                runner.MigrationAssembly = usedAttrAssemblies;
            }

            #endregion

            return runner;
        }
    }
}
<commit_msg>fix codefactor<commit_after>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;

namespace DatabaseMigrateExt
{
    public class ExtMigrationRunner
    {
        internal string RootNamespace { get; set; }
        internal SortedList<int, string> DatabaseKeys { get; set; } = new SortedList<int, string>();
        internal SortedList<int, DatabaseScriptType> DatabaseLayers { get; set; } = new SortedList<int, DatabaseScriptType>();
        internal Assembly MigrationAssembly { get; set; }

        /// <summary>
        /// Initialize default settings
        /// </summary>
        /// <returns></returns>
        public static ExtMigrationRunner Initialize()
        {
            var runner = new ExtMigrationRunner();

            #region Initialize RootNamespace

            var rootNamespaceFromAppSetting = ConfigurationManager.AppSettings["mgr:RootNamespace"];
            runner.RootNamespace = rootNamespaceFromAppSetting;

            #endregion

            #region Initialize DatabaseKeys

            if (runner.DatabaseKeys == null)
            {
                runner.DatabaseKeys = new SortedList<int, string>();
            }
            var databaseKeys = ConfigurationManager.AppSettings["mgr:DatabaseKeys"];
            if (databaseKeys != null)
            {
                var databaseKeyArr = databaseKeys.Split(',');
                if (databaseKeyArr.Any())
                {
                    for (var i = 0; i < databaseKeyArr.Length; i++)
                    {
                        runner.DatabaseKeys.Add(i, databaseKeyArr[i].Trim());
                    }
                }
            }

            #endregion

            #region Initialize DatabaseLayers

            if (runner.DatabaseLayers == null)
            {
                runner.DatabaseLayers = new SortedList<int, DatabaseScriptType>();
            }

            var layers = Enum.GetValues(typeof(DatabaseScriptType))
                .OfType<DatabaseScriptType>().OrderBy(x => x);

            foreach (var layer in layers)
            {
                runner.DatabaseLayers.Add((int)layer, layer);
            }

            #endregion

            #region Initialize MigrationAssembly

            var usedAttrAssemblies = AppDomain.CurrentDomain.GetAssemblies()
                .Where(assy => assy != typeof(ExtMigrationRunner).Assembly)
                .FirstOrDefault(assy => assy.GetTypes()
                    .Select(type => Attribute.IsDefined(type, typeof(BaseExtMgrAttribute)))
                    .Any(x => x));

            if (usedAttrAssemblies != null)
            {
                runner.MigrationAssembly = usedAttrAssemblies;
            }

            #endregion

            return runner;
        }
    }
}

{'fraction_non_alphanumeric': 0.0935610103166133, 'fraction_numerical': 0.0003557452863749555, 'mean_word_length': 1.7389186556259133, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 35, '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': '6261242', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1311, 'n_words': 289}