public Extension(String path) { _extensionPath = path; _engine = new ScriptEngine(); _watcher = new FileSystemWatcher(path) { EnableRaisingEvents = true }; _watcher.Changed += _watcher_Changed; String entryPoint = Path.Combine(path, "extension.js"); if (!File.Exists(entryPoint)) { throw new Exception("Extension must contain an extension.js file."); } var files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).ToList(); foreach (var filePath in files) { var file = new FileInfo(filePath); _watchedFiles.Add(filePath, file.LastWriteTimeUtc); } _engine.SetNamedItem("lumen", new LumenScript(this)); try { LoadScript(Path.Combine(path, @"..\common.js")); _parsed = LoadScript(entryPoint); __extension = new ParsedScript(_engine, _engine.Eval(_extensionIdent)); ExtensionManager.Current.Add(this); } catch (ScriptException ex) { var s = _scripts.FromLineNumber(ex.Line); ex.Line = s.TranslateLineNumber(ex.Line); System.Windows.MessageBox.Show(ex.ErrorType + ": " + ex.Description + "\t\t\t" + s.Name + ":" + ex.Line); } }
private object Parse(string text, bool expression) { const string varName = "x___"; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; object result; IntPtr dispatch; ScriptText flags = ScriptText.None; _engine.SetScriptState(ScriptState.Connected); if (expression) { flags |= ScriptText.IsExpression; } try { // immediate expression computation seems to work only for 64-bit so hack something for 32-bit... if (_parse32 != null) { if (expression) { text = varName + "=" + text; // should work for jscript & vbscript at least... } _parse32.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } else { _parse64.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } } catch { if (_site._lastException != null) { throw _site._lastException; } throw; } if (expression) { // continue 32-bit hack... if (_parse32 != null) { _engine.GetScriptDispatch(null, out dispatch); object dp = Marshal.GetObjectForIUnknown(dispatch); try { var res = dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null); return res; } catch { if (_site._lastException != null) throw _site._lastException; throw; } } return result; } _engine.GetScriptDispatch(null, out dispatch); ParsedScript parsed = new ParsedScript(this, dispatch); return parsed; }
private object Parse(string text, bool expression) { const string varName = "x___"; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; object result; IntPtr dispatch; ScriptText flags = ScriptText.None; _engine.SetScriptState(ScriptState.Connected); if (expression) { flags |= ScriptText.IsExpression; } try { // immediate expression computation seems to work only for 64-bit so hack something for 32-bit... if (_parse32 != null) { if (expression) { text = varName + "=" + text; // should work for jscript & vbscript at least... } _parse32.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } else { _parse64.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo); } } catch { if (_site._lastException != null) { throw _site._lastException; } throw; } if (expression) // continue 32-bit hack... { if (_parse32 != null) { _engine.GetScriptDispatch(null, out dispatch); object dp = Marshal.GetObjectForIUnknown(dispatch); try { var res = dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null); return(res); } catch { if (_site._lastException != null) { throw _site._lastException; } throw; } } return(result); } _engine.GetScriptDispatch(null, out dispatch); ParsedScript parsed = new ParsedScript(this, dispatch); return(parsed); }