Table of Contents

Class ScriptRun

Namespace
Alternet.Scripter.IronPython
Assembly
Alternet.Scripter.IronPython.v9.dll

Represents runner for script engine.

[ToolboxBitmap(typeof(ScriptRun), "Images.ScriptRun.Python.Icon.bmp")]
public class ScriptRun : Component, IComponent, IDisposable, IScriptRun, IScriptRunBase
Inheritance
ScriptRun
Implements

Examples

Here is how to run IronPython 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.IronPython.ScriptRun();
        scriptRun.ScriptSource.FromScriptFile(@"c:\myscript.py");
        scriptRun.Run();
    }
}

Here is how to run IronPython 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.IronPython.ScriptRun()
        scriptRun.ScriptSource.FromScriptFile("c:\myscript.py")
        scriptRun.Run()
    End Sub
End Class

Remarks

ScriptRun is a non-visual component that allows executing IronPython 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.

The ScriptSource property contains the source of the script to execute.

The GlobalItems property contains a collection of application objects accessible to the scripts.

The Run() method executes the script.

The RunFunction method executes the specified script function.

Constructors

ScriptRun()

Initializes a new instance of the ScriptRun class with default settings.

ScriptRun(IContainer)

Initializes a new instance of the ScriptRun class with specified parameters.

Properties

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.

CodeEnvironment
Compiled

Gets boolean value indicating that script has been compiled and ready to be executed.

Executed

Gets boolean value indicating that script has been compiled and ready to be executed.

GlobalItems

Gets or sets a script items collection attached to this runner.

LoadUserTypeDefinitions

Gets or sets whether users type definitions should be loaded.

ProjectDirectory

Gets or sets root project directory.

ScriptHost

Returns object that implements IScriptHost interface for this runner.

ScriptSource

Gets source of the script to execute.

TypeDefinitionsSearchPaths

Gets or sets a list of search directories to look for type definitions.

Methods

Compile()

Initializes script engine and compiles the script.

CreateScriptHost()

Creates a new IScriptHost object with appropriate characteristics.

CreateScriptSource()
Dispose(bool)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

EvaluateExpression(string)

Evaluates specified expression.

EvaluateExpressionAsync(string, CancellationToken)

Evaluates specified expression asynchronously.

LoadScript(string)

Load script from specified file.

OnFileLoad(string)

Invokes FileLoad event handler.

OnResolveReference(string, out string)

Invokes ReferenceResolve event handler.

OnScriptCompiled()

Invokes ScriptCompiled event handler.

OnScriptError(ScriptErrorEventArgs)

Invokes ScriptError event handler.

OnScriptExecuted()

Invokes ScriptRunning event handler.

OnScriptReset()

Invokes ScriptReset event handler.

OnScriptRunning()

Invokes ScriptRunning event handler.

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.

RunProcess(string[], bool)

Executes script starting from the main entry point in stand-alone process

Events

FileLoad

Occurs when script code is loaded from file.

ReferenceResolve

Occurs when assembly reference needs to be resolved.

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.