public class Module
{
public string? Name { get; set; }
public string? File { get; set; }
public Dictionary<string, object>? Options;
}
public class HostedModule
{
public dynamic? runtime;
public Module? module;
}
public enum AuxFuncType
{
None,
RequestsMenu
}
public class AuxFunc
{
// todo: options dictionary
public string? Name { get; set; }
public AuxFuncType Type { get; set; }
public Action<Dictionary<string, object>>? Action { get; set; }
}
public static class ModuleManager
{
static List<AuxFunc> auxFuncs = new List<AuxFunc>();
static Dictionary<string, HostedModule> modules = new Dictionary<string, HostedModule>();
public static void AddAuxFunc(AuxFunc auxFunc)
{
auxFuncs.Add(auxFunc);
}
public static void LoadModules()
{
foreach (var file in Directory.GetFiles("Scripts"))
{
var newModule = new HostedModule
{
runtime = CSScript.Evaluator
.ReferenceAssembly(Assembly.GetAssembly(typeof(Message)))
.LoadFile(file)
};
newModule.module = newModule.runtime!.module;
newModule.module.File = file;
newModule.runtime.OnModuleLoad();
modules.Add(newModule.module.Name!, newModule);
}
}
}
}