WinForms

Code Examples Upgrade Guide User Guide Demos Support Forums Download
  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class ScriptingManager

    Show / Hide Table of Contents

    Class ScriptingManager

    Encapsulates a script, script site, and script engine as a single component.

    Inheritance
    System.Object
    ScriptingManager
    ScriptManagerEx
    Namespace: Syncfusion.Scripting
    Assembly: Syncfusion.Scripting.Base.dll
    Syntax
    public class ScriptingManager : Component
    Remarks

    This class provides a convenient wrapper around a script, script site, and script engine. It can be added to a form using the toolbox and configured using the property editor.

    The ScriptingManager creates the ScriptSite and Script objects by calling the virtual CreateScriptSite() and CreateScript() methods, respectively. These methods can be overriden in derived ScriptingManager classes in order to create custom Script and ScriptSite objects. After creating the ScriptSite and Script, the ScriptingManager attaches these objects to the ScriptSite and Script properties, respectively. Another way to attach a custom ScriptSite or Script to the ScriptingManager is to pass them to one of the overloaded constructors.

    The ScriptEngine is created by the ScriptEngineFactory based on the value of the property.

    The LoadScript(String) method is used to load the script source code. Once the script is loaded, the

    CompileScript() method can be called to compile the script.

    CompileScript() method can be called to compile the script.

    Constructors

    ScriptingManager()

    Default constructor

    Declaration
    public ScriptingManager()

    ScriptingManager(Script)

    Construct a ScriptingManager given a script.

    Declaration
    public ScriptingManager(Script script)
    Parameters
    Type Name Description
    Script script

    Script to attach

    ScriptingManager(ScriptSite)

    Construct a ScriptingManager given a script site.

    Declaration
    public ScriptingManager(ScriptSite scriptSite)
    Parameters
    Type Name Description
    ScriptSite scriptSite

    Script site to attach

    ScriptingManager(ScriptSite, Script)

    Construct a ScriptingManager given a script site and a script.

    Declaration
    public ScriptingManager(ScriptSite scriptSite, Script script)
    Parameters
    Type Name Description
    ScriptSite scriptSite

    Script site to attach

    Script script

    Script to attach

    Properties

    ApplicationBase

    Sets the root folder where non-system assemblies are located.

    Declaration
    public string ApplicationBase { get; set; }
    Property Value
    Type Description
    System.String

    IsScriptCompiled

    Indicates if the script has been loaded and compiled in the script engine.

    Declaration
    public bool IsScriptCompiled { get; }
    Property Value
    Type Description
    System.Boolean

    IsScriptRunning

    Indicates if the script engine is currently running the script.

    Declaration
    public bool IsScriptRunning { get; }
    Property Value
    Type Description
    System.Boolean

    NeedToCompile

    Indicates if the script needs to be compiled.

    Declaration
    public bool NeedToCompile { get; }
    Property Value
    Type Description
    System.Boolean

    Script

    Script to load into the. ScriptEngine.

    Declaration
    public Script Script { get; set; }
    Property Value
    Type Description
    Script

    ScriptEngine

    The ScriptEngine compiles and executes the script.

    Declaration
    public IVsaEngine ScriptEngine { get; }
    Property Value
    Type Description
    Microsoft.Vsa.IVsaEngine
    Remarks

    Each language uses a different ScriptEngine. The ScriptEngineFactory creates the appropriate ScriptEngine for a given language. New or alternate ScriptEngines can be registered with the ScriptEngineFactory.

    ScriptSite

    The ScriptSite provides for host-implemented callbacks, describes interaction between the engine and the host's object model, and allows the reporting of compilation errors.

    Declaration
    public ScriptSite ScriptSite { get; }
    Property Value
    Type Description
    ScriptSite

    Methods

    ClearScriptSite()

    Removes all event sources, global instances, and compiled code from the site.

    Declaration
    public void ClearScriptSite()

    CloseScriptEngine()

    Closes the script engine and releases all resources. If the script engine is currently running, the IVsaEngine.Reset method is called first.

    Declaration
    public void CloseScriptEngine()

    CompileScript()

    Compiles the script loaded in the ScriptEngine.

    Declaration
    public bool CompileScript()
    Returns
    Type Description
    System.Boolean

    true if successful; otherwise false

    Remarks

    The OnCompileError(VsaErrorEventArgs) method is called if an error occurs during compilation.

    CreateScript()

    Creates the Script to attach to the ScriptingManager.

    Declaration
    protected virtual Script CreateScript()
    Returns
    Type Description
    Script

    Script object

    CreateScriptEngine()

    Creates a new instance of the ScriptEngine and loads the script into it.

    Declaration
    protected virtual bool CreateScriptEngine()
    Returns
    Type Description
    System.Boolean

    true if successful; otherwise false

    CreateScriptSite()

    Creates the ScriptSite to attach to the ScriptingManager.

    Declaration
    protected virtual ScriptSite CreateScriptSite()
    Returns
    Type Description
    ScriptSite

    ScriptSite object

    Init()

    Initializes the ScriptingManager

    Declaration
    protected virtual void Init()
    Remarks

    This method calls the CreateScriptSite() and CreateScript() methods and attaches the ScriptSite and Script to the ScriptingManager. If the ScriptingManager already has a ScriptSite attached, then a new one is not created. The same is true of the Script.

    InvokeScriptMethod(String)

    Invokes the specified method in the script.

    Declaration
    public object InvokeScriptMethod(string methodName)
    Parameters
    Type Name Description
    System.String methodName

    Name of method to invoke

    Returns
    Type Description
    System.Object

    Return value of the method

    Remarks

    This method throws an InvalidOperationException if the ScriptEngine or Script is null. The ScriptEngine must be running to call this method.

    LoadScript(Stream)

    Loads the given stream into the script.

    Declaration
    public void LoadScript(Stream strm)
    Parameters
    Type Name Description
    System.IO.Stream strm

    Stream containing the script source

    LoadScript(String)

    Loads the contents of the specified file into the script.

    Declaration
    public void LoadScript(string fileName)
    Parameters
    Type Name Description
    System.String fileName

    Name of file containing the script source

    OnCompileError(VsaErrorEventArgs)

    Called when an error occurs during compilation.

    Declaration
    protected virtual void OnCompileError(VsaErrorEventArgs evtArgs)
    Parameters
    Type Name Description
    VsaErrorEventArgs evtArgs

    Event arguments

    OnScriptChanged(ScriptEventArgs)

    Called when the script changes.

    Declaration
    protected virtual void OnScriptChanged(ScriptEventArgs evtArgs)
    Parameters
    Type Name Description
    ScriptEventArgs evtArgs

    Event arguments

    RegisterEventSource(String, Object)

    Registers and event source with the site.

    Declaration
    public void RegisterEventSource(string name, object obj)
    Parameters
    Type Name Description
    System.String name

    Name of the event source

    System.Object obj

    Event source object

    RegisterGlobalInstance(String, Object)

    Registers a global instance with the site.

    Declaration
    public void RegisterGlobalInstance(string name, object obj)
    Parameters
    Type Name Description
    System.String name

    Name of the global instance

    System.Object obj

    Global instance object

    ResetScriptEngine()

    Removes the script engine from the running state and disconnects automatically bound event handlers.

    Declaration
    public void ResetScriptEngine()

    RunScript()

    Runs the script that is compiled in the ScriptEngine.

    Declaration
    public void RunScript()
    Remarks

    The script must be loaded and compiled before this method is called. An error occurs if the ScriptEngine is already running.

    Events

    CompileError

    Fired when an error occurs during compilation.

    Declaration
    public event VsaErrorEventHandler CompileError
    Event Type
    Type Description
    VsaErrorEventHandler

    ScriptChanged

    Fired when the script changes

    Declaration
    public event ScriptEventHandler ScriptChanged
    Event Type
    Type Description
    ScriptEventHandler
    Back to top Generated by DocFX
    Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved