Represents a piece of executable script code.
示例#1
0
        /// <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);
                }
            }
        }
示例#2
0
 /// <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);
     }
 }
示例#3
0
 /// <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);
         }
     }
 }
示例#4
0
 public static void OnScriptLoaded(ApplicationScript script)
 {
     LoggingService.Info("Loaded: " + script.Path);
 }
示例#5
0
 void OnScriptUnloaded(ApplicationScript script)
 {
     treeScripts.Nodes.RemoveByKey(script.Path);
     UpdateButtonStates();
 }
示例#6
0
 void OnScriptLoaded(ApplicationScript script)
 {
     AddScriptItem(script.Path);
 }
示例#7
0
 void OnScriptUnloaded(ApplicationScript script)
 {
     treeScripts.Nodes.RemoveByKey(script.Path);
     UpdateButtonStates();
 }
示例#8
0
 void OnScriptLoaded(ApplicationScript script)
 {
     AddScriptItem(script.Path);
 }