/// <summary> /// Loads the script /// </summary> /// <param name="scriptPath">The script path.</param> public void LoadScript(string scriptPath) { if (!loadedScripts.ContainsKey(scriptPath)) { try { ScriptSource src = _engine.CreateScriptSourceFromFile(scriptPath); CompiledCode code = src.Compile(); ApplicationScript cpy = new ApplicationScript(scriptPath, code, _scope); loadedScripts.Add(scriptPath, cpy); ScriptEventHandler handler = this.ScriptLoaded; if (handler != null) { handler(cpy); } } catch (SyntaxErrorException ex) { ExceptionOperations eo = _engine.GetService <ExceptionOperations>(); string error = eo.FormatException(ex); string msg = "Syntax error in \"{0}\"{1}Details:{1}{2}"; msg = string.Format(msg, Path.GetFileName(scriptPath), Environment.NewLine, error); MessageService.ShowError(msg); } } }
/// <summary> /// Unloads the script. /// </summary> /// <param name="script">The script.</param> public void UnloadScript(string script) { if (loadedScripts.ContainsKey(script)) { ApplicationScript cpy = loadedScripts[script]; loadedScripts.Remove(script); } }
/// <summary> /// Recompiles the script. Call this if the referenced script has changed since it was loade /// </summary> /// <param name="scriptPath">The script path.</param> public void RecompileScript(string scriptPath) { if (loadedScripts.ContainsKey(scriptPath)) { try { ScriptSource src = _engine.CreateScriptSourceFromFile(scriptPath); CompiledCode code = src.Compile(); ApplicationScript cpy = new ApplicationScript(scriptPath, code, _scope); loadedScripts[scriptPath] = cpy; } catch (SyntaxErrorException ex) { ExceptionOperations eo = _engine.GetService<ExceptionOperations>(); string error = eo.FormatException(ex); string msg = "Syntax error in \"{0}\"{1}Details:{1}{2}"; msg = string.Format(msg, Path.GetFileName(scriptPath), Environment.NewLine, error); MessageService.ShowError(msg); } } }
public static void OnScriptLoaded(ApplicationScript script) { LoggingService.Info("Loaded: " + script.Path); }
void OnScriptUnloaded(ApplicationScript script) { treeScripts.Nodes.RemoveByKey(script.Path); UpdateButtonStates(); }
void OnScriptLoaded(ApplicationScript script) { AddScriptItem(script.Path); }