public static Assembly compile_H2Script(this string h2Script) { try { var sourceCode = ""; if (h2Script.extension(".h2")) { PublicDI.CurrentScript = h2Script; if (h2Script.fileExists().isFalse()) { h2Script = h2Script.local(); } sourceCode = H2.load(h2Script).SourceCode; } if (sourceCode.valid()) { return(sourceCode.compile_CodeSnippet()); } } catch (Exception ex) { ex.log("in string compile_H2Script"); } return(null); }
public void loadH2Script(string scriptToLoad) { O2Thread.mtaThread(() => { if (scriptToLoad.fileName().starts(this.typeName())) { PublicDI.log.error("We can execute the current type of we will get a recursive load :)"); return; } currentScript = scriptToLoad; statusLabel.set_Text("loading script: {0}".format(scriptToLoad.fileName())); csharpCompiler = new CSharp_FastCompiler(); csharpCompiler.set_OnAstFail(() => { showError("Ast creation failed", csharpCompiler.astErrors()); csharpCompiler_OnAstFail.invoke(); }); csharpCompiler.set_OnAstOK(() => { showInfo("Ast creation Ok"); csharpCompiler_OnAstOk.invoke(); }); csharpCompiler.set_OnCompileFail(() => { showError("Compilation failed", csharpCompiler.compilationErrors()); csharpCompiler_OnCompileFail.invoke(); }); csharpCompiler.set_OnCompileOK(() => { showInfo("Compilation Ok: Executing 1st method"); csharpCompiler_OnCompileOk.invoke(); executeCompiledCode(); }); var sourceCode = ""; PublicDI.CurrentScript = scriptToLoad; csharpCompiler.CompilerOptions.SourceCodeFile = scriptToLoad; if (scriptToLoad.extension(".h2")) { sourceCode = H2.load(scriptToLoad).SourceCode; } if (scriptToLoad.extension(".o2") || scriptToLoad.extension(".cs")) { sourceCode = scriptToLoad.contents(); } if (sourceCode.valid()) { csharpCompiler.compileSnippet(sourceCode); } else { statusLabel.set_Text("Non supported file").textColor(this, Color.Red); } }); }
public void LoadAndSaveH2File() { var codeSnippet = "return 42;"; var h2 = new H2(codeSnippet); var h2Saved = h2.save(); "h2Saved: {0}".info(h2Saved); var h2Loaded = H2.load(h2Saved); Assert.IsNotNull(h2); Assert.IsTrue(h2Saved.fileExists()); Assert.IsNotNull(h2Loaded); Assert.AreEqual(h2Loaded.SourceCode, codeSnippet); var tempH2 = "test.h2".tempFile(); h2.save(tempH2); var tempH2Loaded = H2.load(tempH2); var h2SourceCode = tempH2.h2_SourceCode(); Assert.IsTrue(tempH2.fileExists()); Assert.IsNotNull(tempH2Loaded); Assert.AreEqual(tempH2Loaded.SourceCode, codeSnippet); Assert.IsNotNull(h2SourceCode); Assert.AreEqual(h2SourceCode, codeSnippet); }
public static string h2_SourceCode(this string file) { if (file.extension(".h2")) { "return source code of H2 file".info(); return(H2.load(file).SourceCode); } return(null); }
public static string h2_SourceCode(this string file) { if (file.extension(".h2")) { //"return source code of H2 file".info(); if (file.fileExists()) { return(H2.load(file).SourceCode.fix_CRLF()); } } return(null); }
public static RibbonGroup add_RibbonButton_H2Script(this RibbonGroup ribbonGroup, WinForms.Control winFormsControl, string label, string h2Script) { if (h2Script.extension(".h2")) { if (h2Script.fileExists().isFalse()) { h2Script = h2Script.local(); } var h2 = H2.load(h2Script); var scriptText = h2.notNull() ? h2.SourceCode : ""; return(ribbonGroup.add_RibbonButton_Script_GUI(winFormsControl, label, scriptText)); } return(ribbonGroup.add_RibbonButton_Script(winFormsControl, label, h2Script)); }
public static object executeH2Script(this string h2ScriptFile) { try { if (h2ScriptFile.extension(".h2").isFalse()) { "[in executeH2Script]: file to execute must be a *.h2 file, it was:{0}".error(h2ScriptFile); } else { PublicDI.CurrentScript = h2ScriptFile; var h2Script = H2.load(h2ScriptFile); return(h2Script.execute()); } } catch (Exception ex) { ex.log("in CSharp_FastCompiler.executeH2Script"); } return(null); }