public async Task <CompilerResult> CompileScript(FileInfo fileInfo, CompilerOptions compilerOptions) { var compiler = new Compiler.Compiler(this); return(await compiler.Compile(fileInfo.Name, File.ReadAllText(fileInfo.FullName), compilerOptions)); }
public async Task <int> RunAsync() { var compiler = new Compiler.Compiler(this); try { if (Debugging) { var @class = Activator.CreateInstance(_debugMainType); if (@class is IAsyncRosi asyncRosi) { var result = await asyncRosi.Run(this); await DisposeRosi(asyncRosi); return(result); } else if (@class is IRosi rosi) { var result = rosi.Run(this); await DisposeRosi(rosi); return(result); } } else { var compilerOptions = new CompilerOptions { Debugging = Debugging, ScriptPath = Config.ScriptPath, ScriptNamespace = Config.ScriptNamespace, UseCachedAssemblies = Config.UseCachedAssemblies, ScriptOutputPath = Config.ScriptOutputPath, LogScriptOnError = Config.LogScriptOnError, SetDirective = (key, value) => Config[key] = value }; var compilerResult = await CompileScript(_mainScript, compilerOptions); if (compilerResult.Result != CompilerResultType.Ok) { return(-1); } var assembly = compilerResult?.Assembly; if (assembly != null) { Type[] types = null; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types; Log.HandleException(ex); } foreach (var type in types) { if (typeof(IAsyncRosi).IsAssignableFrom(type)) { var asyncRosi = (IAsyncRosi)assembly.CreateInstance(type.FullName); if (asyncRosi != null) { var result = await asyncRosi.Run(this); await DisposeRosi(asyncRosi); return(result); } } else if (typeof(IRosi).IsAssignableFrom(type)) { var rosi = (IRosi)assembly.CreateInstance(type.FullName); if (rosi != null) { var result = rosi.Run(this); await DisposeRosi(rosi); return(result); } } } } } } catch (Exception ex) { Log.Fatal(Tr.Get("Runtime.RuntimeError", ex), this); return(-1); } Log.Fatal(Tr.Get("Runtime.NoMainFound", _mainScript.Name), this); return(-1); }