<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Hadouken.Framework;
using Hadouken.Framework.Plugins;

namespace Hadouken.Sandbox
{
    public sealed class SandboxedEnvironment : MarshalByRefObject
    {
        private Plugin _plugin;

        public SandboxedEnvironment()
        {
            AppDomain.CurrentDomain.DomainUnload += (s, e) => Unload();
        }

        public override object InitializeLifetimeService()
        {
            // We do not want this to be garbage collected.
            return null;
        }

        public AppDomain GetAppDomain()
        {
            return AppDomain.CurrentDomain;
        }

        public void Load()
        {
            var assemblies = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
                                      .Select(File.ReadAllBytes)
                                      .Select(Assembly.Load).ToList();

            // Find the bootstrapper class in this AppDomain. Get the plugin and load it.
            var bootstrapperType = (from asm in assemblies
                                    from type in asm.GetTypes()
                                    where typeof(Bootstrapper).IsAssignableFrom(type)
                                    where type.IsClass && !type.IsAbstract
                                    select type).Single();

            var bootstrapper = (Bootstrapper)Activator.CreateInstance(bootstrapperType);

            _plugin = bootstrapper.Load(new BootConfig());
            _plugin.Load();
        }

        public void Unload()
        {
            _plugin.Unload();
        }
    }
}<commit_msg>Made Unload private since we do not call it directly.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Hadouken.Framework;
using Hadouken.Framework.Plugins;

namespace Hadouken.Sandbox
{
    public sealed class SandboxedEnvironment : MarshalByRefObject
    {
        private Plugin _plugin;

        public SandboxedEnvironment()
        {
            AppDomain.CurrentDomain.DomainUnload += (s, e) => Unload();
        }

        public override object InitializeLifetimeService()
        {
            // We do not want this to be garbage collected.
            return null;
        }

        public AppDomain GetAppDomain()
        {
            return AppDomain.CurrentDomain;
        }

        public void Load()
        {
            var assemblies = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
                                      .Select(File.ReadAllBytes)
                                      .Select(Assembly.Load).ToList();

            // Find the bootstrapper class in this AppDomain. Get the plugin and load it.
            var bootstrapperType = (from asm in assemblies
                                    from type in asm.GetTypes()
                                    where typeof(Bootstrapper).IsAssignableFrom(type)
                                    where type.IsClass && !type.IsAbstract
                                    select type).Single();

            var bootstrapper = (Bootstrapper)Activator.CreateInstance(bootstrapperType);

            _plugin = bootstrapper.Load(new BootConfig());
            _plugin.Load();
        }

        private void Unload()
        {
            _plugin.Unload();
        }
    }
}
{'fraction_non_alphanumeric': 0.07710077967080566, 'fraction_numerical': 0.0, 'mean_word_length': 1.598649662415604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5707022', 'n_tokens_mistral': 858, 'n_tokens_neox': 815, 'n_words': 209}