public EvaluatorEngine() : base(null) { vars = new Dictionary <string, object>(); this.typeReflector = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(this.GetType())); engine = new Microsoft.JScript.Vsa.VsaEngine(); engine.doFast = false; output = new StringBuilder(); StringWriter sw = new StringWriter(output); engine.InitVsaEngine("executerjscript.net", new VsaSite(sw)); imports = new List <string>(); List <string> asses = new List <string>(); foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies()) { try { VsaReference reference = new VsaReference(engine, Path.GetFileNameWithoutExtension(assem.Location)); engine.Items.CreateItem(reference.AssemblyName, Microsoft.Vsa.VsaItemType.Reference, Microsoft.Vsa.VsaItemFlag.None); if (Path.GetExtension(assem.EscapedCodeBase).Equals(".dll", StringComparison.InvariantCultureIgnoreCase)) { string tmp = Path.GetFileNameWithoutExtension(assem.EscapedCodeBase); if (!imports.Contains(tmp)) { Import.JScriptImport(tmp, engine); } } Import.JScriptImport("System.Net", engine); Import.JScriptImport("System.IO", engine); //using System; //using System.IO; //using System.Net; //using System.Text; } catch { } } }
public static xblock GetCodeBlock(string code) { xblock ret = null; Microsoft.JScript.Vsa.VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine(); StringWriter sw = new StringWriter(); engine.InitVsaEngine("test", new VsaSite(sw)); DocumentContext docContext = new DocumentContext("", engine); Context context = new Context(docContext, code); JSParser parser = new JSParser(context); Block block = parser.ParseEvalBody(); ret = new xjscript.xblock(block); engine.Close(); // MessageBox.Show(((Completion)block.Evaluate()).value.ToString()); return(ret); }