<commit_before>﻿using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using Microsoft.CSharp;
using log4net;

namespace L2dotNET.GameService.scripting
{
    /// <summary>
    /// Idea L2cemu
    /// </summary>
    public class ScriptCompiler
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(ScriptCompiler));

        private CSharpCodeProvider provider;

        private static volatile ScriptCompiler instance;
        private static object syncRoot = new object();

        public static ScriptCompiler Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new ScriptCompiler();
                        }
                    }
                }

                return instance;
            }
        }

        public ScriptCompiler()
        {
            provider = new CSharpCodeProvider();
        }

        public object[] CompileFolder(string path)
        {
            CompilerParameters cp = new CompilerParameters();
            cp.ReferencedAssemblies.Add("L2dotNET.GameService.exe");
            cp.GenerateInMemory = true;
            cp.CompilerOptions = "/t:library";

            List<object> objectList = new List<object>();
            foreach (string fname in Directory.GetFiles(path, "*.cs"))
            {
                FileInfo info = new FileInfo(fname);
                CompilerResults result = provider.CompileAssemblyFromFile(cp, fname);

                if (result.Errors.Count > 0)
                    log.Error($"ScriptCompiler: Failed to compile { fname }.");
                else
                    objectList.Add(result.CompiledAssembly.CreateInstance(info.Name.Remove(info.Name.Length - 3)));
            }
            log.Info($"Script Compiler: Compiled {objectList.Count} scripted quests.");

            return objectList.ToArray();
        }
    }
}
<commit_msg>Changed how is get the file name without extension on assembly CreateInstance. Note: Still not working the compilation from referenced assemblies. Need revision.<commit_after>﻿using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using Microsoft.CSharp;
using log4net;

namespace L2dotNET.GameService.scripting
{
    /// <summary>
    /// Idea L2cemu
    /// </summary>
    public class ScriptCompiler
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(ScriptCompiler));

        private CSharpCodeProvider provider;

        private static volatile ScriptCompiler instance;
        private static object syncRoot = new object();

        public static ScriptCompiler Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new ScriptCompiler();
                        }
                    }
                }

                return instance;
            }
        }

        public ScriptCompiler()
        {
            provider = new CSharpCodeProvider();
        }

        public object[] CompileFolder(string path)
        {
            CompilerParameters cp = new CompilerParameters();
            cp.ReferencedAssemblies.Add("L2dotNET.GameService.exe");
            cp.GenerateInMemory = true;
            cp.CompilerOptions = "/t:library";

            List<object> objectList = new List<object>();
            foreach (string fname in Directory.GetFiles(path, "*.cs"))
            {
                FileInfo info = new FileInfo(fname);
                CompilerResults result = provider.CompileAssemblyFromFile(cp, fname);

                if (result.Errors.Count > 0)
                    log.Error($"ScriptCompiler: Failed to compile { fname }.");
                else
                    objectList.Add(result.CompiledAssembly.CreateInstance(Path.GetFileNameWithoutExtension(info.Name)));
            }
            log.Info($"Script Compiler: Compiled {objectList.Count} scripted quests.");

            return objectList.ToArray();
        }
    }
}

{'fraction_non_alphanumeric': 0.08678546632723906, 'fraction_numerical': 0.0025457070122656793, 'mean_word_length': 1.5710886377156454, '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': '5927555', 'n_tokens_mistral': 1064, 'n_tokens_neox': 989, 'n_words': 245}