Пример #1
0
        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);
            }
        }
Пример #2
0
        /// <summary>
        /// Evaluates an expression using the specified language, with an optional array of named items.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="expression">The expression. May not be null.</param>
        /// <param name="namedItems">The named items array.</param>
        /// <returns>The result of the evaluation.</returns>
        public static object Eval(string language, string expression, params KeyValuePair<string, object>[] namedItems)
        {
            if (language == null) {
                throw new ArgumentNullException("language");
            }

            if (expression == null) {
                throw new ArgumentNullException("expression");
            }

            using (ScriptEngine engine = new ScriptEngine()) {
                if (namedItems != null) {
                    foreach (KeyValuePair<string, object> kvp in namedItems) {
                        engine.SetNamedItem(kvp.Key, kvp.Value);
                    }
                }
                return engine.Eval(expression);
            }
        }
Пример #3
0
 internal ParsedScript(ScriptEngine engine, IntPtr dispatch)
 {
     this._engine = engine;
     this._dispatch = Marshal.GetObjectForIUnknown(dispatch);
 }
Пример #4
0
 public ParsedScript(ScriptEngine engine, object dispatch)
 {
     this._engine = engine;
     this._dispatch = dispatch;
 }