2using System.Collections.Generic;
4using System.Linq.Expressions;
5using System.Reflection;
23 #region Private Variables
29 private Dictionary<object, Interpreter>
locks;
38 #region Internal Properties
40 internal Dictionary<object, Interpreter> Locks
47 #region Public Methods
55 scanner =
new ScannerPrototype();
59 routines =
new Dictionary<string, Routine>();
61 locks =
new Dictionary<object, Interpreter>();
76 string path = relativeDirectoryPath;
78 if (!Directory.Exists(path))
81 var subdirs = Directory.GetDirectories(path);
82 if (subdirs.Length > 0)
84 var shared =
new[] { Assembly.GetExecutingAssembly().GetName().Name! };
86 this.loadedPlugins = loaded;
91 foreach (
string dll
in System.IO.Directory.GetFiles(path,
"*.dll"))
94 if (dll == path +
"ScriptStack.dll")
97 Assembly assembly =
null;
101 assembly = Assembly.LoadFile(dll);
103 catch (Exception e) {
104 Console.WriteLine($
"[LoadComponents] Fehler beim Laden '{dll}': {e.Message}");
106 if (e is TargetInvocationException tie && tie.InnerException !=
null)
107 Console.WriteLine(
"INNER: " + tie.InnerException);
112 Type[] arrayTypes = assembly.GetExportedTypes();
114 foreach (Type type
in arrayTypes)
117 if (!typeof(
Model).IsAssignableFrom(type))
120 ConstructorInfo constructorInfo =
null;
123 constructorInfo = type.GetConstructor(
new Type[0]);
125 catch (Exception e) {
continue; }
127 object objectHostModule = constructorInfo.Invoke(
new object[0]);
141 Assembly assembly =
null;
144 assembly = Assembly.LoadFile(relativeDirectoryPath);
146 catch (Exception e) { }
148 Type[] arrayTypes = assembly.GetExportedTypes();
150 foreach (Type type
in arrayTypes)
153 if (!typeof(
Model).IsAssignableFrom(type))
156 ConstructorInfo constructorInfo =
null;
159 constructorInfo = type.GetConstructor(
new Type[0]);
161 catch (Exception e) {
continue; }
163 object objectHostModule = constructorInfo.Invoke(
new object[0]);
182 return routines.ContainsKey(routine);
188 foreach (
Routine routine
in model.Routines)
196 foreach (
Routine routine
in model.Routines)
209 routine.Handler = host;
253 if (plugin?.Instance is
Model model)
255 foreach (var r
in model.Routines)
257 if (r !=
null &&
routines.ContainsKey(r.Name))
264 Console.WriteLine($
"[UnloadPlugins] Fehler beim Deregistrieren: {ex.Message}");
273 plugin.LoadContext?.Unload();
277 Console.WriteLine($
"[UnloadPlugins] Fehler beim Unload: {ex.Message}");
284 GC.WaitForPendingFinalizers();
291 #region Public Properties
307 public ReadOnlyDictionary<String, Routine>
Routines {
310 return new ReadOnlyDictionary<string, Routine>(
routines);
316 get {
return debug; }
317 set {
debug = value; }
328 get {
return new ReadOnlyDictionary<object,Interpreter>(
locks); }
The lexical analyzer (Lexer) breaks code (written in sentences) into a series of known Token and pass...
void LoadComponent(string relativeDirectoryPath)
Manager()
A Manager object is responsible for memory management, type evaluation and loading of plugins.
Func< List< string >, Lexer > LexerFactory
List< Plugin > loadedPlugins
void Register(Model model)
ReadOnlyDictionary< object, Interpreter > ActiveLocks
void UnloadPlugins()
Unload all plugins that were loaded via LoadComponents (subdirectory mode). This will deregister thei...
bool IsRegistered(string routine)
Scanner Scanner
A Scanner reference.
void UnRegister(string routine)
Dictionary< string, Routine > routines
void LoadComponents(string relativeDirectoryPath)
Dictionary< object, Interpreter > locks
void Register(Routine routine)
Register a new Routine.
void UnRegister(Model model)
ReadOnlyDictionary< String, Routine > Routines
void Register(Routine routine, Host host)
static List< Plugin > LoadPlugins(string pluginsRoot, ScriptStack.Manager manager, string[]? sharedAssemblyNames=null)
static Memory AllocateSharedMemory()
A Routine is an abstract representation of a method.
The main interface to create a Host. A Host can implement Routine's to extend its functionality.