ScriptStack 1.0.5
Loading...
Searching...
No Matches
ScriptStack.Manager Class Reference

API entry point. More...

Public Member Functions

 Manager ()
 A Manager object is responsible for memory management, type evaluation and loading of plugins.
void LoadComponents (string relativeDirectoryPath)
void LoadComponent (string relativeDirectoryPath)
bool IsRegistered (string routine)
void Register (Model model)
void UnRegister (Model model)
void Register (Routine routine, Host host)
void UnRegister (string routine)
void Register (Routine routine)
 Register a new Routine.
void ClearActiveLocks ()
void UnloadPlugins ()
 Unload all plugins that were loaded via LoadComponents (subdirectory mode). This will deregister their routines and unload their ALCs (collectible).

Properties

Func< List< string >, LexerLexerFactory = lines => new Lexer(lines) [get, set]
String Name [get, set]
Scanner Scanner [get, set]
 A Scanner reference.
Memory SharedMemory [get]
ReadOnlyDictionary< String, RoutineRoutines [get]
bool Debug [get, set]
bool Optimize [get, set]
ReadOnlyDictionary< object, InterpreterActiveLocks [get]

Private Attributes

string name
Scanner scanner
Memory sharedMemory
Dictionary< string, Routineroutines
Dictionary< object, Interpreterlocks
bool debug
bool optimize
List< PluginloadedPlugins = new List<Plugin>()

Detailed Description

API entry point.

Definition at line 20 of file Manager.cs.

Constructor & Destructor Documentation

◆ Manager()

ScriptStack.Manager.Manager ( )

A Manager object is responsible for memory management, type evaluation and loading of plugins.

Definition at line 52 of file Manager.cs.

53 {
54
55 scanner = new ScannerPrototype();
56
57 sharedMemory = Memory.AllocateSharedMemory();
58
59 routines = new Dictionary<string, Routine>();
60
61 locks = new Dictionary<object, Interpreter>();
62
63 debug = false;
64
65 optimize = true;
66
67 loadedPlugins = new List<Plugin>();
68
69 }

References ScriptStack.Runtime.Memory.AllocateSharedMemory(), debug, loadedPlugins, locks, optimize, routines, scanner, and sharedMemory.

Member Function Documentation

◆ ClearActiveLocks()

void ScriptStack.Manager.ClearActiveLocks ( )

Definition at line 234 of file Manager.cs.

235 {
236 locks.Clear();
237 }

References locks.

◆ IsRegistered()

bool ScriptStack.Manager.IsRegistered ( string routine)

Definition at line 180 of file Manager.cs.

181 {
182 return routines.ContainsKey(routine);
183 }

References routines.

◆ LoadComponent()

void ScriptStack.Manager.LoadComponent ( string relativeDirectoryPath)

Definition at line 138 of file Manager.cs.

139 {
140
141 Assembly assembly = null;
142 try
143 {
144 assembly = Assembly.LoadFile(relativeDirectoryPath);
145 }
146 catch (Exception e) { }
147
148 Type[] arrayTypes = assembly.GetExportedTypes();
149
150 foreach (Type type in arrayTypes)
151 {
152
153 if (!typeof(Model).IsAssignableFrom(type))
154 continue;
155
156 ConstructorInfo constructorInfo = null;
157 try
158 {
159 constructorInfo = type.GetConstructor(new Type[0]);
160 }
161 catch (Exception e) { continue; }
162
163 object objectHostModule = constructorInfo.Invoke(new object[0]);
164 Model hostModule = (Model)objectHostModule;
165
166 Register(hostModule);
167
168 }
169
170 }

References Register().

◆ LoadComponents()

void ScriptStack.Manager.LoadComponents ( string relativeDirectoryPath)

Definition at line 73 of file Manager.cs.

74 {
75
76 string path = relativeDirectoryPath; // System.AppDomain.CurrentDomain.BaseDirectory;
77
78 if (!Directory.Exists(path))
79 return;
80
81 var subdirs = Directory.GetDirectories(path);
82 if (subdirs.Length > 0)
83 {
84 var shared = new[] { Assembly.GetExecutingAssembly().GetName().Name! };
85 var loaded = ScriptStack.Plugins.PluginLoader.LoadPlugins(path, this, shared);
86 this.loadedPlugins = loaded;
87 return;
88 }
89
90
91 foreach (string dll in System.IO.Directory.GetFiles(path, "*.dll"))
92 {
93
94 if (dll == path + "ScriptStack.dll")
95 continue;
96
97 Assembly assembly = null;
98
99 try
100 {
101 assembly = Assembly.LoadFile(dll);
102 }
103 catch (Exception e) {
104 Console.WriteLine($"[LoadComponents] Fehler beim Laden '{dll}': {e.Message}");
105
106 if (e is TargetInvocationException tie && tie.InnerException != null)
107 Console.WriteLine("INNER: " + tie.InnerException);
108
109 continue;
110 }
111
112 Type[] arrayTypes = assembly.GetExportedTypes();
113
114 foreach (Type type in arrayTypes)
115 {
116
117 if (!typeof(Model).IsAssignableFrom(type))
118 continue;
119
120 ConstructorInfo constructorInfo = null;
121 try
122 {
123 constructorInfo = type.GetConstructor(new Type[0]);
124 }
125 catch (Exception e) { continue; }
126
127 object objectHostModule = constructorInfo.Invoke(new object[0]);
128 Model hostModule = (Model)objectHostModule;
129
130 Register(hostModule);
131
132 }
133
134 }
135
136 }

References ScriptStack.Plugins.PluginLoader.LoadPlugins(), and Register().

◆ Register() [1/3]

void ScriptStack.Manager.Register ( Model model)

Definition at line 185 of file Manager.cs.

186 {
187
188 foreach (Routine routine in model.Routines)
189 Register(routine, model);
190
191 }
ReadOnlyCollection< Routine > Routines
Returns all Routine's a Model implements.
Definition Model.cs:96

References Register().

Referenced by LoadComponent(), LoadComponents(), Register(), and Register().

◆ Register() [2/3]

void ScriptStack.Manager.Register ( Routine routine)

Register a new Routine.

Parameters
routine

Definition at line 229 of file Manager.cs.

230 {
231 Register(routine, null);
232 }

References Register().

◆ Register() [3/3]

void ScriptStack.Manager.Register ( Routine routine,
Host host )

Definition at line 201 of file Manager.cs.

202 {
203
204 string name = routine.Name;
205
206 if (routines.ContainsKey(name))
207 throw new ScriptStackException("Die Routine '" + name + "' ist bereits registriert.");
208
209 routine.Handler = host;
210
211 routines[name] = routine;
212
213 }

References ScriptStack.Runtime.Routine.Name, name, and routines.

◆ UnloadPlugins()

void ScriptStack.Manager.UnloadPlugins ( )

Unload all plugins that were loaded via LoadComponents (subdirectory mode). This will deregister their routines and unload their ALCs (collectible).

Definition at line 243 of file Manager.cs.

244 {
245 if (loadedPlugins == null || loadedPlugins.Count == 0)
246 return;
247
248 // Deregister routines
249 foreach (var plugin in loadedPlugins)
250 {
251 try
252 {
253 if (plugin?.Instance is Model model)
254 {
255 foreach (var r in model.Routines)
256 {
257 if (r != null && routines.ContainsKey(r.Name))
258 routines.Remove(r.Name);
259 }
260 }
261 }
262 catch (Exception ex)
263 {
264 Console.WriteLine($"[UnloadPlugins] Fehler beim Deregistrieren: {ex.Message}");
265 }
266 }
267
268 // Unload contexts
269 foreach (var plugin in loadedPlugins)
270 {
271 try
272 {
273 plugin.LoadContext?.Unload();
274 }
275 catch (Exception ex)
276 {
277 Console.WriteLine($"[UnloadPlugins] Fehler beim Unload: {ex.Message}");
278 }
279 }
280
281 loadedPlugins.Clear();
282
283 GC.Collect();
284 GC.WaitForPendingFinalizers();
285 GC.Collect();
286
287 }

References loadedPlugins, and routines.

◆ UnRegister() [1/2]

void ScriptStack.Manager.UnRegister ( Model model)

Definition at line 193 of file Manager.cs.

194 {
195
196 foreach (Routine routine in model.Routines)
197 UnRegister(routine.Name);
198
199 }

References ScriptStack.Runtime.Routine.Name, and UnRegister().

Referenced by UnRegister().

◆ UnRegister() [2/2]

void ScriptStack.Manager.UnRegister ( string routine)

Definition at line 215 of file Manager.cs.

216 {
217
218 if (!routines.ContainsKey(routine))
219 throw new ScriptStackException("Die Routine '" + routine + "' wurde nicht gefunden.");
220
221 routines.Remove(routine);
222
223 }

References routines.

Member Data Documentation

◆ debug

bool ScriptStack.Manager.debug
private

Definition at line 30 of file Manager.cs.

Referenced by Manager().

◆ loadedPlugins

List<Plugin> ScriptStack.Manager.loadedPlugins = new List<Plugin>()
private

Definition at line 34 of file Manager.cs.

Referenced by Manager(), and UnloadPlugins().

◆ locks

Dictionary<object, Interpreter> ScriptStack.Manager.locks
private

Definition at line 29 of file Manager.cs.

Referenced by ClearActiveLocks(), and Manager().

◆ name

string ScriptStack.Manager.name
private

Definition at line 25 of file Manager.cs.

Referenced by Register().

◆ optimize

bool ScriptStack.Manager.optimize
private

Definition at line 31 of file Manager.cs.

Referenced by Manager().

◆ routines

Dictionary<string, Routine> ScriptStack.Manager.routines
private

Definition at line 28 of file Manager.cs.

Referenced by IsRegistered(), Manager(), Register(), UnloadPlugins(), and UnRegister().

◆ scanner

Scanner ScriptStack.Manager.scanner
private

Definition at line 26 of file Manager.cs.

Referenced by Manager().

◆ sharedMemory

Memory ScriptStack.Manager.sharedMemory
private

Definition at line 27 of file Manager.cs.

Referenced by Manager().

Property Documentation

◆ ActiveLocks

ReadOnlyDictionary<object, Interpreter> ScriptStack.Manager.ActiveLocks
get

Definition at line 326 of file Manager.cs.

327 {
328 get { return new ReadOnlyDictionary<object,Interpreter>(locks); }
329 }

◆ Debug

bool ScriptStack.Manager.Debug
getset

Definition at line 314 of file Manager.cs.

315 {
316 get { return debug; }
317 set { debug = value; }
318 }

Referenced by ScriptStack.Runtime.Script.Script(), and ScriptStack.Runtime.Script.Script().

◆ LexerFactory

Func<List<string>, Lexer> ScriptStack.Manager.LexerFactory = lines => new Lexer(lines)
getset

Definition at line 71 of file Manager.cs.

71{ get; set; } = lines => new Lexer(lines);

◆ Name

String ScriptStack.Manager.Name
getset

Definition at line 172 of file Manager.cs.

173 {
174 get { return name; }
175 set {
176 name = value;
177 }
178 }

◆ Optimize

bool ScriptStack.Manager.Optimize
getset

Definition at line 320 of file Manager.cs.

321 {
322 get { return optimize; }
323 set { optimize = value; }
324 }

Referenced by ScriptStack.Runtime.Script.Script(), and ScriptStack.Runtime.Script.Script().

◆ Routines

ReadOnlyDictionary<String, Routine> ScriptStack.Manager.Routines
get

Definition at line 307 of file Manager.cs.

307 {
308 get
309 {
310 return new ReadOnlyDictionary<string, Routine>(routines);
311 }
312 }

Referenced by ScriptStack.Compiler.Parser.RoutineCall().

◆ Scanner

Scanner ScriptStack.Manager.Scanner
getset

A Scanner reference.

Definition at line 296 of file Manager.cs.

297 {
298 get { return scanner; }
299 set { scanner = value; }
300 }

◆ SharedMemory

Memory ScriptStack.Manager.SharedMemory
get

Definition at line 302 of file Manager.cs.

303 {
304 get { return sharedMemory; }
305 }

The documentation for this class was generated from the following file: