ScriptRun Class
Definition
Represents runner for script engine.
Implements
Syntax
[ToolboxBitmap(typeof(ScriptRun), "Images.ScriptRun.TS.Icon.bmp")]
public class ScriptRun : Component, IComponent, IDisposable, IScriptRun, IScriptRunBase, ITypeDefinitionsLocator, IScriptFileLoader
Remarks
ScriptRun is a non-visual component that allows executing JavaScript or TypeScript scripts and script projects; it allows referencing third-party assemblies and registering application-defined objects to be accessible in the scripts.
The most important properties and methods of the ScriptRun are:
The ScriptHost property provides properties and methods of the underlying scripting engine and allows adding application-specific objects to the script.
The ScriptSource property contains the source of the script to execute.
The Run() method executes the script.
The RunFunction method executes the specified script function.
Examples
Here is how to run TypeScript script using ScriptRun from the C# code:
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
var scriptRun = new Alternet.Scripter.TypeScript.ScriptRun();
scriptRun.ScriptSource.FromScriptFile(@"c:\myscript.ts");
scriptRun.Run();
}
}
Here is how to run TypeScript script using ScriptRun from the Visual Basic code:
Partial Public Class Form1
Inherits Form
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim scriptRun = New Alternet.Scripter.TypeScript.ScriptRun()
scriptRun.ScriptSource.FromScriptFile("c:\myscript.ts")
scriptRun.Run()
End Sub
End Class
Constructors
ScriptRun() | Initializes a new instance of the |
ScriptRun(IContainer) | Initializes a new instance of the |
Properties
AutoGeneratedTypeDefinitionsPath | Gets or sets whether project should automatically generate type definitions if possible. |
AutoGenerateTypeDefinitions | Gets or sets whether project should automatically generate type definitions if possible. |
CaseSensitive | When implemented by a class, indicates whether script language is case sensitive. |
Compiled | Gets boolean value indicating that script has been compiled and ready to be executed. |
EmbeddedTypeDefitionsLocations | Gets or sets a collection of EmbeddedTypeDefitionsLocation that belong to the project. |
Executed | Gets boolean value indicating that script has been compiled and ready to be executed. |
LoadUserTypeDefinitions | Gets or sets whether users type definitions should be loaded. |
ProjectDirectory | Gets or sets root project directory. |
ScriptHost | Returns object that implements |
ScriptLanguage | Gets or sets programming language of the script. |
ScriptSource | Gets source of the script to execute. |
TypeDefinitionsSearchPaths | Gets or sets list of search directories to look for type definitions. |
WaitForDebuggerOnStart | Gets of sets a boolean value indicates whether script engine is to wait for a debugger connection and schedule a pause before executing the first line of application script code. |
Methods
Compile() | Initializes script engine and compiles the script. |
CreateScriptHost() | Creates a new |
CreateScriptSource() | |
Dispose(Boolean) | |
EvaluateExpression(String) | Evaluates specified expression. |
EvaluateExpressionAsync(String, CancellationToken) | Evaluates specified expression asynchronously. |
LoadFile(String) | Load script from specified file. |
LoadScript(String) | Load script from specified file. |
OnFileLoad(String) | Invokes |
OnScriptCompiled() | Invokes |
OnScriptError(ScriptErrorEventArgs) | Invokes |
OnScriptExecuted() | Invokes |
OnScriptReset() | Invokes |
OnScriptRunning() | Invokes |
Reset() | Resets the script engine and releases all resources. |
Run() | Executes script starting from the main entry point. |
RunAsync(CancellationToken) | Executes script asynchronously starting from the main entry point. |
RunFunction(String, Object[]) | Executes specified function. |
RunFunctionAsync(String, Object[], CancellationToken) | Executes specified function asynchronously. |
Events
FileLoad | Occurs when script code is loaded from file. |
ScriptCompiled | Occurs when the script engine running successfully. |
ScriptError | Occurs when the script engine running is failed. |
ScriptExecuted | Occurs when script engine executes the script. |
ScriptReset | Occurs when the script engine is reset. |
ScriptRunning | Occurs when script engine tries to running script. |
Explicit Interface Implementations
IScriptRunBase.ScriptSource |