IGLib  1.7.2
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Lib.ScriptLoaderBase Class Reference

Dynamically compiles, loads and instantiates classes of type ILoadableScript from files or from strings. More...

+ Inheritance diagram for IG.Lib.ScriptLoaderBase:
+ Collaboration diagram for IG.Lib.ScriptLoaderBase:

Public Member Functions

 ScriptLoaderBase ()
 
virtual void InitializeScriptLoader ()
 Initializes the current script loader. More...
 
virtual void ClearLogger ()
 Clears the logger. More...
 
virtual string GetExampleCode ()
 Gets example code base (a template code for compiling) where names of classes, methods etc. are properly set. More...
 
virtual string GetExampleCode (string pureScript)
 Returns a complete example code that can be loaded and run. More...
 
void CheckAndCorrectNames ()
 Corrects the ClassName (if the current class name has already been used) and namespace and class name in the loaded scritp code (if they don't correspond to ClassNamespace and ClassName, respectively). More...
 
virtual string GetExecutableDirectory ()
 Returns the directory containing the executable that started the current application. More...
 
virtual void AddReferencedAssembly (string assemblyFile)
 Adds an additional referenced assembly by name of the assembly file. Assmebly is only added if it is not yet contained in the list of referenced assemblies and if the specified assembly file name is not null or empty string. More...
 
virtual void AddReferencedAssemblies (params string[] assemblyFiles)
 Adds the specified assemblies to the list of referenced assemblies. Assemblise are added only if not yet on the list and if their names are not null or empty strings. More...
 
virtual void SetReferencedAssemblies (params string[] assemblyFiles)
 Sets the list of referenced assemblies in such a way that it contains only the specified assemblies. More...
 
virtual void RemoveReferencedAssembly (string assemblyFile)
 Removes the specified assembly from the list of referenced assemblies. If the specified assembly does not exist on the list or it is a null or empty string then nothing happens. More...
 
virtual void RemoveReferencedAssemblies (params string[] assemblyFiles)
 Removes the specified assemblies from the list of referenced assemblies. More...
 
virtual void RemoveAllReferencedAssemblies ()
 Removes all assemblies from tehe list of referenced assemblies. More...
 
virtual string[] GetReferencedAssemblies ()
 Returns an array of assemblies (paths, sometimes only file names) that are currently referenced by the compiler on the current script loader. More...
 
virtual string Compile ()
 Compiles the code that is currently loaded by the current loader, and returns full name of the compiled script class. More...
 
virtual void UnloadApplicationDomain ()
 Unloads the application domain used by the current script loader. More...
 
virtual ILoadableScript CreateObject (string[] initializationArguments)
 Creates and returns an object of the class that has been last compiled. The created object is also stored such that it can later be accessed through the CreatedObject property. More...
 
virtual ILoadableScript CreateLoadableObject (string[] initializationArguments, bool storeObject)
 Creates and returns an object of the class that has been last compiled. More...
 
virtual ILoadableScript CreateLoadableObject (string[] initializationArguments, string classFullName)
 Creates and returns an object of the specified loadable class. More...
 
virtual void Run (string[] initializationAndRunArguments)
 Runs the object of the compiled loadable class (calls its Run() method) that is currently loaded by the current loader. Compiles the code and creates the object if necessary. More...
 
virtual void Run (string[] initializationArguments, string[] runArguments)
 Runs the object of the compiled loadable class (calls its Run() method) that is currently loaded by the current loader. Compiles the code and creates the object if necessary. More...
 
void LoadCode (string code, string classFullName)
 Loads code form a string. More...
 
void LoadCode (string code)
 Loads code form a string. Class name is extracted from the code. More...
 
ILoadableScript CreateObjectFromCode (string code, string className, string[] initializationArguments)
 Creates and returns a loadable script object form code. More...
 
ILoadableScript CreateObjectFromCode (string code, string[] initializationArguments)
 Creates and returns a loadable script object form code. Class name is extracted from code. More...
 
string RunCode (string code, string className, string[] initializationArguments, string[] runArguments)
 Creates and runs a loadable script object form code. More...
 
string RunCode (string code, string[] initializationArguments, string[] runArguments)
 Creates and returns a loadable script object form code. Class name is extracted from code. More...
 
string RunCode (string code, string className, string[] initializationAndRunArguments)
 Runs a loadable script object form code. More...
 
string RunCode (string code, string[] initializationAndRunArguments)
 Creates and returns a loadable script object form code. Class name is extracted from code. More...
 
void LoadFile (string filePath, string className)
 Loads loadable script code form the specified file. More...
 
void LoadFile (string filePath)
 Loads loadable script code form a file. Name of the class is extracted from the file contents. More...
 
ILoadableScript CreateObjectFromFile (string filePath, string className, string[] initializationArguments)
 Creates and returns a loadable script object form a file containing its code. More...
 
ILoadableScript CreateObjectFromFile (string filePath, string[] initializationArguments)
 Creates and returns a loadable script object form code. Class name is extracted from code. More...
 
string RunFile (string filePath, string className, string[] initializationArguments, string[] runArguments)
 Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. More...
 
string RunFile (string filePath, string[] initializationArguments, string[] runArguments)
 Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. Class name is extracted from code. More...
 
string RunFile (string filePath, string className, string[] initializationAndRunArguments)
 Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. The same arguments are taken for initialization of the loadable script object and for execution of the script. More...
 
string RunFile (string filePath, string[] initializationAndRunArguments)
 Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. The same arguments are taken for initialization of the loadable script object and for execution of the script. Class name is extracted from code. More...
 

Static Public Member Functions

static void InitializeScripting ()
 Initializes the scripting system. More...
 
static ILoadableScript GetLoadableScriptC (ILoadableScript scriptObject)
 Returns the loadable script object if the script object is actually loadable, or null if it is not meant as loadable. More...
 
static byte[] LoadFileBytes (string filePath)
 Copies the specified file to byte array and returns it. More...
 
static ILoadableScript CreateScriptObject (string scriptClassFullName)
 Creates and returns a new script obect of the specified type. More...
 
static ILoadableScript CreateScriptObject (string scriptClassFullName, int outputLevel)
 Creates and returns a new script obect of the specified type. More...
 
static void AddDefaultAssemblies (params string[] assemblies)
 Add the specified assemblies (just their names) to the list of assemblies that are referenced by newly created script loaders by default. More...
 
static void RemoveDefaultAssemblies (params string[] assemblies)
 Removes the specified assemblies from the list of default assemblies that are referenced by newly created script loaders. More...
 
static void ClearDefaultAssemblies ()
 Clears the list of assemblies that are referenced by default by newly created script loaders. More...
 
static bool IsClassFullNameUsed (string classFillName)
 Returns a flag indicating whether the specified class full name has already been used or not. More...
 
static string FindNameAfterKeyword (string code, string keyword, string allowedCharacters)
 In the specified string, finds a name that follows the specified keyword, and returns it. Name must directly follow the keyword with only blank characters between them, and it end at the first character that is not alphanumeric and is also not contained in the specified string of allowed characters. More...
 
static string FindNamespace (string code)
 Finds and returns the name of the first namespace that is defined in the specified C# code block. A null string is returned if the name can not be found. More...
 
static string FindClassName (string code)
 Finds and returns the name of the first class that is defined in the specified C# code block. A null string is returned if the name can not be found. More...
 
static string GetFileContents (string filePath)
 Returns contents of the specified file. More...
 

Protected Member Functions

void AddDefaultReferencedAssemblies ()
 Add assemblies that are referenced by default to the list of assemblies that are referenced by the current script loader. More...
 
void CreateNonexistentLibraryPath ()
 Modifies library path in such a way that it points to an non-existent file. More...
 
virtual void AddReferencedAssemblies (System.CodeDom.Compiler.CompilerParameters compilerParameters)
 Adds referenced assemblies to the specified compiler parameters, according to current settings. More...
 

Static Protected Member Functions

static string CreateNonexistentFilePath (string originalPath)
 Returns a file path that does not exist and is derived form the specified file path by adding a suffix composed of underscore and a number. More...
 

Protected Attributes

string _code = null
 
string _libraryFilename = null
 
string _originalLibraryPath = null
 
List< string > _referencedAssimblies = new List<string>()
 
bool _referenceAllLoadedAssemblies = true
 

Properties

bool IsScriptLoaderInitialized [get, protected set]
 Whether the current script loader is initialized or not. More...
 
static bool IsScriptingInitialized [get, protected set]
 Whether scripting system is initialized or not. More...
 
object Lock [get]
 This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock. More...
 
static List< string > DefaultAssemblies [get]
 Gets the list of assemblies that are added to all newly created script loaders by default. More...
 
static SortedList< string, string > UsedClassFullNames [get]
 Stores used class names, i.e. class names that have already been used for dynamiically loaded classes. More...
 
static ScriptLoaderBase Global [get, set]
 Global script loader. Getter always returns a non-null object. More...
 
int OutputLevel [get, set]
 Definbes level of output on console that is generated by some operations. 0 means that no output will be written to the console. More...
 
virtual Logger Logger [get]
 Gets the logger that is used to log errors and warnings. More...
 
virtual string Code [get, set]
 Gets or sets code to be compiled. Get: If not assigned explicitly then CodeBase is taken. More...
 
bool PerformNamesCorrection [get, set]
 Specifies whether automatic checking and correction of the class and namespace name in the loaded code is performed. If correction is switched on, it is performed before every compilation. Correction first checks if the class name has already been used, and if this is the case, it changes the name to the one that has not yet been used. It is then checked whether the namespace and class names used in the code are the same as those set on the current script loader. If not then names are replaced. At this stage, the assumed namespace class names are the first namespace and the first class found in the code block. More...
 
virtual string LanguageName [get, protected set]
 Language used by compiler. More...
 
virtual string ClassNamespace [get, protected set]
 Namespace in which the compiled class is defined. More...
 
virtual string ClassInterface [get]
 Interface that is implemented by the compiled class. More...
 
virtual string ClassName [get, set]
 
virtual string ClassFullName [get]
 Name of the compiled class that contains loadable script. More...
 
virtual string AppDomainName [get, set]
 Name of the application domain in which the class is loaded. More...
 
virtual string RunFunctionName [get, protected set]
 Name of the method of dynamically loadable classes that contains the runnable script. More...
 
virtual string InitFunctionName [get, protected set]
 Name of the initialization method of dynamically loadable classes. More...
 
virtual string ArgumentsName [get, set]
 Agreed formal name of the arguments parameter. Agreement upon this name makes possible to execute scripts in which run arguments are referenced. More...
 
virtual string LibraryFilename [get, set]
 
virtual string LibraryDirectory [get, protected set]
 Returns directory where library will be compiled, which will be the directory of the executable that started the application. More...
 
virtual string LibraryPath [get, protected set]
 Path to the dll where code is compiled. We take the directory where executable is located. More...
 
virtual bool IsCodeLoaded [get, protected set]
 Whether scripting code to be compiled is loaded. More...
 
virtual bool IsCompiled [get, protected set]
 Whether the code is compiled. More...
 
virtual bool IsClassLoaded [get, protected set]
 Whether the compiled class corresponding to the script is prepared. More...
 
virtual bool IsObjectPrepared [get, protected set]
 Whether an instance of the object is prepared to be used. More...
 
virtual CompilerResults CompilerResults [get, protected set]
 Results of compilation. More...
 
virtual List< String > ReferencedAssemblies [get]
 List of assemblies that are referenced when compiling the code. Contains names of files containing referenced assemblies. More...
 
virtual bool ReferenceAllLoadedAssemblies [get, set]
 If true then all assemblies that are currently loaded by the application are also added to the referenced assemblies when script code is compiled. This makes sure that all that is necessary is actually referenced. More...
 
virtual AppDomain ApplicationDomain [get, set]
 Application domain used by the current script loader for loading assemblies. More...
 
virtual Assembly Assembly [get, protected set]
 Gets or sets the assembly that has been compiled and loaded into the current application domain from the source code. More...
 
virtual ILoadableScript CreatedObject [get, protected set]
 Object of the compiled class that has beeen created. More...
 
- Properties inherited from IG.Lib.ILockable
object Lock [get]
 

Private Attributes

bool _isScriptLoaderInitialized = false
 
object _mainLock = new object()
 
int _outputLevel = Util.OutputLevel
 
Logger _logger = new Logger()
 
bool _nameCorrection = true
 
string _languageName = "CSharp"
 
string _namespace = "IG.Script"
 
string _interface = "IG.Lib.ILoadableScript"
 
string _className = "TestClass"
 
string _appDomainName = "NewDomain"
 
string _runFunctionName = "RunThis"
 
string _initFunctionName = "InitializeThis"
 
string _argumentsName = "arguments"
 
string _libraryPath = null
 
string _libraryDirectory = null
 
bool _isCodeLoaded = false
 
bool _isCompiled = false
 
bool _isClassLoaded = false
 
bool _isObjectPrepared = false
 
CompilerResults _compilerResults
 
AppDomain _applicationDomain
 
Assembly _assembly
 
ILoadableScript _runnableObject
 

Static Private Attributes

static bool _isScriptingInitialized = false
 
static List< string > _defaultAssemblies
 
static SortedList< string, string > _usedClassFullNames
 
static ScriptLoaderBase _global
 

Detailed Description

Dynamically compiles, loads and instantiates classes of type ILoadableScript from files or from strings.

$A Igor Jul09 Feb10;

Constructor & Destructor Documentation

IG.Lib.ScriptLoaderBase.ScriptLoaderBase ( )
inline

Member Function Documentation

virtual void IG.Lib.ScriptLoaderBase.InitializeScriptLoader ( )
inlinevirtual

Initializes the current script loader.

static void IG.Lib.ScriptLoaderBase.InitializeScripting ( )
inlinestatic

Initializes the scripting system.

static ILoadableScript IG.Lib.ScriptLoaderBase.GetLoadableScriptC ( ILoadableScript  scriptObject)
inlinestatic

Returns the loadable script object if the script object is actually loadable, or null if it is not meant as loadable.

Parameters
scriptObjectScript object to be returned if the object itself is loadable.

This method filters out the controllable loadable scripts (i.e. the scripts that implement the ILoadableScriptC interface) that are not loadable by property ILoadableScriptC.IsLoadable.

References IG.Lib.ILoadableScriptC.IsLoadable.

static byte [] IG.Lib.ScriptLoaderBase.LoadFileBytes ( string  filePath)
inlinestatic

Copies the specified file to byte array and returns it.

TODO: move this to utils or something like that!

static ILoadableScript IG.Lib.ScriptLoaderBase.CreateScriptObject ( string  scriptClassFullName)
inlinestatic

Creates and returns a new script obect of the specified type.

null is returned if the oject can not be created (but no exception is thrown).

Parameters
scriptClassFullNameFull name of the script class whose object is created.

Referenced by IG.Lib.CommandLineApplicationInterpreter.CmdRunInternalScriptClass().

static ILoadableScript IG.Lib.ScriptLoaderBase.CreateScriptObject ( string  scriptClassFullName,
int  outputLevel 
)
inlinestatic

Creates and returns a new script obect of the specified type.

null is returned if the oject can not be created (but no exception is thrown).

Parameters
scriptClassFullNameFull name of the script class whose object is created.
outputLevelLevel of output to console.
static void IG.Lib.ScriptLoaderBase.AddDefaultAssemblies ( params string[]  assemblies)
inlinestatic

Add the specified assemblies (just their names) to the list of assemblies that are referenced by newly created script loaders by default.

Parameters
assembliesNames of assemblies that are added to the list.

References IG.Lib.Util.LockGlobal.

Referenced by IG.Lib.ApplicationCommandlineBase.AddDefaultAssemblies(), IG.Lib.ShellApplication< InterpreterType >.AddDefaultAssemblies(), IG.Lib.ModuleBase.AddDefaultAssembliesExtShellApp(), and IG.Lib.ModuleBase.AnnAdd().

static void IG.Lib.ScriptLoaderBase.RemoveDefaultAssemblies ( params string[]  assemblies)
inlinestatic

Removes the specified assemblies from the list of default assemblies that are referenced by newly created script loaders.

Parameters
assembliesnames of assemblies that are removed from the list.

References IG.Lib.Util.LockGlobal.

static void IG.Lib.ScriptLoaderBase.ClearDefaultAssemblies ( )
inlinestatic

Clears the list of assemblies that are referenced by default by newly created script loaders.

References IG.Lib.Util.LockGlobal.

void IG.Lib.ScriptLoaderBase.AddDefaultReferencedAssemblies ( )
inlineprotected

Add assemblies that are referenced by default to the list of assemblies that are referenced by the current script loader.

Assemblies that are referenced by default can be set by the ScriptLoaderBase.AddDefaultAssemblies method.

static bool IG.Lib.ScriptLoaderBase.IsClassFullNameUsed ( string  classFillName)
inlinestatic

Returns a flag indicating whether the specified class full name has already been used or not.

Parameters
classFillNameFully qualified class name (namespace and class).
virtual void IG.Lib.ScriptLoaderBase.ClearLogger ( )
inlinevirtual

Clears the logger.

References IG.Lib.Logger.Clear().

virtual string IG.Lib.ScriptLoaderBase.GetExampleCode ( )
inlinevirtual

Gets example code base (a template code for compiling) where names of classes, methods etc. are properly set.

virtual string IG.Lib.ScriptLoaderBase.GetExampleCode ( string  pureScript)
inlinevirtual

Returns a complete example code that can be loaded and run.

<pparam name="pureScript">Code that is inserted in the LoadableScriptBase.RunThis method.</pparam>

static string IG.Lib.ScriptLoaderBase.FindNameAfterKeyword ( string  code,
string  keyword,
string  allowedCharacters 
)
inlinestatic

In the specified string, finds a name that follows the specified keyword, and returns it. Name must directly follow the keyword with only blank characters between them, and it end at the first character that is not alphanumeric and is also not contained in the specified string of allowed characters.

Parameters
codeString in which the specified name is searched for.
keywordKeyword.
allowedCharactersEventual string arguments that contains characters that are allowed beside the alphanumeric characters.
Returns
Name that follows the specified keyword.

This functions can be used e.g. for searching for class names or namespace names in code blocks. The method is currently not implemented very efficiently because it uses access to characters of a string through their within the string.

static string IG.Lib.ScriptLoaderBase.FindNamespace ( string  code)
inlinestatic

Finds and returns the name of the first namespace that is defined in the specified C# code block. A null string is returned if the name can not be found.

Parameters
codeCode block where namespace name is searched for.
static string IG.Lib.ScriptLoaderBase.FindClassName ( string  code)
inlinestatic

Finds and returns the name of the first class that is defined in the specified C# code block. A null string is returned if the name can not be found.

Parameters
codeCode block where class name is searched for.
void IG.Lib.ScriptLoaderBase.CheckAndCorrectNames ( )
inline

Corrects the ClassName (if the current class name has already been used) and namespace and class name in the loaded scritp code (if they don't correspond to ClassNamespace and ClassName, respectively).

References IG.Lib.Logger.LogWarning().

virtual string IG.Lib.ScriptLoaderBase.GetExecutableDirectory ( )
inlinevirtual

Returns the directory containing the executable that started the current application.

References IG.Lib.UtilSystem.GetExecutableDirectory().

virtual void IG.Lib.ScriptLoaderBase.AddReferencedAssembly ( string  assemblyFile)
inlinevirtual

Adds an additional referenced assembly by name of the assembly file. Assmebly is only added if it is not yet contained in the list of referenced assemblies and if the specified assembly file name is not null or empty string.

Parameters
assemblyFileFile name of the assembly that is added to referenced assemblies.
virtual void IG.Lib.ScriptLoaderBase.AddReferencedAssemblies ( params string[]  assemblyFiles)
inlinevirtual

Adds the specified assemblies to the list of referenced assemblies. Assemblise are added only if not yet on the list and if their names are not null or empty strings.

Parameters
assemblyFilesA table of file names of the assemblies to be added.
virtual void IG.Lib.ScriptLoaderBase.SetReferencedAssemblies ( params string[]  assemblyFiles)
inlinevirtual

Sets the list of referenced assemblies in such a way that it contains only the specified assemblies.

Parameters
assemblyFilesArray of file names of the assemblies to be contained in the list.
virtual void IG.Lib.ScriptLoaderBase.RemoveReferencedAssembly ( string  assemblyFile)
inlinevirtual

Removes the specified assembly from the list of referenced assemblies. If the specified assembly does not exist on the list or it is a null or empty string then nothing happens.

Parameters
assemblyFileFile name of the assembly to be removed.
virtual void IG.Lib.ScriptLoaderBase.RemoveReferencedAssemblies ( params string[]  assemblyFiles)
inlinevirtual

Removes the specified assemblies from the list of referenced assemblies.

Parameters
assemblyFilesArray of file names of the assemblies to be removed from the list.
virtual void IG.Lib.ScriptLoaderBase.RemoveAllReferencedAssemblies ( )
inlinevirtual

Removes all assemblies from tehe list of referenced assemblies.

static string IG.Lib.ScriptLoaderBase.CreateNonexistentFilePath ( string  originalPath)
inlinestaticprotected

Returns a file path that does not exist and is derived form the specified file path by adding a suffix composed of underscore and a number.

Parameters
originalPathOriginal file path.

Even if the file with original path does not exist, the method finds and returns a new path.

void IG.Lib.ScriptLoaderBase.CreateNonexistentLibraryPath ( )
inlineprotected

Modifies library path in such a way that it points to an non-existent file.

virtual void IG.Lib.ScriptLoaderBase.AddReferencedAssemblies ( System.CodeDom.Compiler.CompilerParameters  compilerParameters)
inlineprotectedvirtual

Adds referenced assemblies to the specified compiler parameters, according to current settings.

Parameters
compilerParametersCompiler parameters on which referenced assemblies ar added.

References IG.Lib.Logger.LogWarning().

virtual string [] IG.Lib.ScriptLoaderBase.GetReferencedAssemblies ( )
inlinevirtual

Returns an array of assemblies (paths, sometimes only file names) that are currently referenced by the compiler on the current script loader.

virtual string IG.Lib.ScriptLoaderBase.Compile ( )
inlinevirtual

Compiles the code that is currently loaded by the current loader, and returns full name of the compiled script class.

Returns
Full name of the class implementing teh ILoadableScript interface that has been compiled.

References IG.Lib.Logger.GetErrorsReport(), IG.Lib.Logger.LogError(), IG.Lib.Logger.LogInfo(), and IG.Lib.Logger.LogWarning().

virtual void IG.Lib.ScriptLoaderBase.UnloadApplicationDomain ( )
inlinevirtual

Unloads the application domain used by the current script loader.

virtual ILoadableScript IG.Lib.ScriptLoaderBase.CreateObject ( string[]  initializationArguments)
inlinevirtual

Creates and returns an object of the class that has been last compiled. The created object is also stored such that it can later be accessed through the CreatedObject property.

Parameters
initializationArgumentsInitialization arguments.
virtual ILoadableScript IG.Lib.ScriptLoaderBase.CreateLoadableObject ( string[]  initializationArguments,
bool  storeObject 
)
inlinevirtual

Creates and returns an object of the class that has been last compiled.

Parameters
initializationArgumentsInitialization arguments.
storeObjectIf true then the created object is stored such that it can be accessed via CreatedObject property.
virtual ILoadableScript IG.Lib.ScriptLoaderBase.CreateLoadableObject ( string[]  initializationArguments,
string  classFullName 
)
inlinevirtual

Creates and returns an object of the specified loadable class.

Parameters
initializationArgumentsInitialization arguments.
classFullNameFull name of the class that is instantiated.

References IG.Lib.ILoadableScript.InitializationArguments.

virtual void IG.Lib.ScriptLoaderBase.Run ( string[]  initializationAndRunArguments)
inlinevirtual

Runs the object of the compiled loadable class (calls its Run() method) that is currently loaded by the current loader. Compiles the code and creates the object if necessary.

Parameters
initializationAndRunArgumentsArguments used both for initialization and running of the object.
virtual void IG.Lib.ScriptLoaderBase.Run ( string[]  initializationArguments,
string[]  runArguments 
)
inlinevirtual

Runs the object of the compiled loadable class (calls its Run() method) that is currently loaded by the current loader. Compiles the code and creates the object if necessary.

Parameters
initializationArgumentsArgumets used for initialization of the object.
runArgumentsArguments used to run the object.
void IG.Lib.ScriptLoaderBase.LoadCode ( string  code,
string  classFullName 
)
inline

Loads code form a string.

Parameters
codeString containing script code that is loaded.
classFullNameName of the class that is contained in the code and contains loadable script that can be executed.
void IG.Lib.ScriptLoaderBase.LoadCode ( string  code)
inline

Loads code form a string. Class name is extracted from the code.

Parameters
codeString containing script code that is loaded.
ILoadableScript IG.Lib.ScriptLoaderBase.CreateObjectFromCode ( string  code,
string  className,
string[]  initializationArguments 
)
inline

Creates and returns a loadable script object form code.

Parameters
codeCode that contains class definition and is dynamically compiled.
classNameName of the class containing loadable script code.
initializationArgumentsInitialization arguments for the created object.
ILoadableScript IG.Lib.ScriptLoaderBase.CreateObjectFromCode ( string  code,
string[]  initializationArguments 
)
inline

Creates and returns a loadable script object form code. Class name is extracted from code.

Parameters
codeCode that contains class definition and is dynamically compiled.
initializationArgumentsInitialization arguments for the created object.
string IG.Lib.ScriptLoaderBase.RunCode ( string  code,
string  className,
string[]  initializationArguments,
string[]  runArguments 
)
inline

Creates and runs a loadable script object form code.

Parameters
codeCode that contains class definition and is dynamically compiled.
classNameName of the class containing loadable script code.
initializationArgumentsInitialization arguments for the created object.
runArgumentsArguments passed to the execution method of the loadable script.
string IG.Lib.ScriptLoaderBase.RunCode ( string  code,
string[]  initializationArguments,
string[]  runArguments 
)
inline

Creates and returns a loadable script object form code. Class name is extracted from code.

Parameters
codeCode that contains class definition and is dynamically compiled.
initializationArgumentsInitialization arguments for the created object.
runArgumentsArguments passed to the execution mathod of the loadable script.
string IG.Lib.ScriptLoaderBase.RunCode ( string  code,
string  className,
string[]  initializationAndRunArguments 
)
inline

Runs a loadable script object form code.

Parameters
codeCode that contains class definition and is dynamically compiled.
classNameName of the class containing loadable script code.
initializationAndRunArgumentsArguments used both for initialization of the loadable script object and as parameters of the executable method..
string IG.Lib.ScriptLoaderBase.RunCode ( string  code,
string[]  initializationAndRunArguments 
)
inline

Creates and returns a loadable script object form code. Class name is extracted from code.

Parameters
codeCode that contains class definition and is dynamically compiled.
initializationAndRunArgumentsArguments used both for initialization of the loadable script object and as parameters of the executable method..
static string IG.Lib.ScriptLoaderBase.GetFileContents ( string  filePath)
inlinestatic

Returns contents of the specified file.

Parameters
filePathPath to the file.
Returns
Full contents of the file as string.
void IG.Lib.ScriptLoaderBase.LoadFile ( string  filePath,
string  className 
)
inline

Loads loadable script code form the specified file.

Parameters
filePathPath to the file that contains script code.
classNameName of the class that is contained in the code and embeds loadable script that can be executed.
void IG.Lib.ScriptLoaderBase.LoadFile ( string  filePath)
inline

Loads loadable script code form a file. Name of the class is extracted from the file contents.

Parameters
filePathPath to the file that contains script code.
ILoadableScript IG.Lib.ScriptLoaderBase.CreateObjectFromFile ( string  filePath,
string  className,
string[]  initializationArguments 
)
inline

Creates and returns a loadable script object form a file containing its code.

Parameters
filePathPath to the file that contains script code.
classNameName of the class containing class definition for loadable script objects.
initializationArgumentsInitialization arguments for the created object.
ILoadableScript IG.Lib.ScriptLoaderBase.CreateObjectFromFile ( string  filePath,
string[]  initializationArguments 
)
inline

Creates and returns a loadable script object form code. Class name is extracted from code.

Parameters
filePathPath to the file that contains script code.
initializationArgumentsInitialization arguments for the created object.
string IG.Lib.ScriptLoaderBase.RunFile ( string  filePath,
string  className,
string[]  initializationArguments,
string[]  runArguments 
)
inline

Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it.

Parameters
filePathPath to the file that contains script code.
classNameName of the class containing loadable script code.
initializationArgumentsInitialization arguments for the created object.
runArgumentsArguments passed to the execution mathod of the loadable script.
string IG.Lib.ScriptLoaderBase.RunFile ( string  filePath,
string[]  initializationArguments,
string[]  runArguments 
)
inline

Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. Class name is extracted from code.

Parameters
filePathPath to the file that contains script code.
initializationArgumentsInitialization arguments for the created object.
runArgumentsArguments passed to the execution mathod of the loadable script.
string IG.Lib.ScriptLoaderBase.RunFile ( string  filePath,
string  className,
string[]  initializationAndRunArguments 
)
inline

Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. The same arguments are taken for initialization of the loadable script object and for execution of the script.

Parameters
filePathPath to the file that contains script code.
classNameName of the class containing loadable script code.
initializationAndRunArgumentsArguments used both for initialization of the loadable script object and as parameters of the executable method.
string IG.Lib.ScriptLoaderBase.RunFile ( string  filePath,
string[]  initializationAndRunArguments 
)
inline

Executes a loadable script form a file. The file must contain definition of the loadable script class that is used to instantiate an object and execute it. The same arguments are taken for initialization of the loadable script object and for execution of the script. Class name is extracted from code.

Parameters
filePathPath to the file that contains script code.
initializationAndRunArgumentsArguments used both for initialization of the loadable script object and as parameters of the executable method.

Member Data Documentation

bool IG.Lib.ScriptLoaderBase._isScriptLoaderInitialized = false
private
bool IG.Lib.ScriptLoaderBase._isScriptingInitialized = false
staticprivate
object IG.Lib.ScriptLoaderBase._mainLock = new object()
private
List<string> IG.Lib.ScriptLoaderBase._defaultAssemblies
staticprivate
SortedList<string, string> IG.Lib.ScriptLoaderBase._usedClassFullNames
staticprivate
ScriptLoaderBase IG.Lib.ScriptLoaderBase._global
staticprivate
int IG.Lib.ScriptLoaderBase._outputLevel = Util.OutputLevel
private
Logger IG.Lib.ScriptLoaderBase._logger = new Logger()
private
string IG.Lib.ScriptLoaderBase._code = null
protected
bool IG.Lib.ScriptLoaderBase._nameCorrection = true
private
string IG.Lib.ScriptLoaderBase._languageName = "CSharp"
private
string IG.Lib.ScriptLoaderBase._namespace = "IG.Script"
private
string IG.Lib.ScriptLoaderBase._interface = "IG.Lib.ILoadableScript"
private
string IG.Lib.ScriptLoaderBase._className = "TestClass"
private
string IG.Lib.ScriptLoaderBase._appDomainName = "NewDomain"
private
string IG.Lib.ScriptLoaderBase._runFunctionName = "RunThis"
private
string IG.Lib.ScriptLoaderBase._initFunctionName = "InitializeThis"
private
string IG.Lib.ScriptLoaderBase._argumentsName = "arguments"
private
string IG.Lib.ScriptLoaderBase._libraryFilename = null
protected
string IG.Lib.ScriptLoaderBase._libraryPath = null
private
string IG.Lib.ScriptLoaderBase._originalLibraryPath = null
protected
string IG.Lib.ScriptLoaderBase._libraryDirectory = null
private
bool IG.Lib.ScriptLoaderBase._isCodeLoaded = false
private
bool IG.Lib.ScriptLoaderBase._isCompiled = false
private
bool IG.Lib.ScriptLoaderBase._isClassLoaded = false
private
bool IG.Lib.ScriptLoaderBase._isObjectPrepared = false
private
CompilerResults IG.Lib.ScriptLoaderBase._compilerResults
private
List<string> IG.Lib.ScriptLoaderBase._referencedAssimblies = new List<string>()
protected
bool IG.Lib.ScriptLoaderBase._referenceAllLoadedAssemblies = true
protected
AppDomain IG.Lib.ScriptLoaderBase._applicationDomain
private
Assembly IG.Lib.ScriptLoaderBase._assembly
private
ILoadableScript IG.Lib.ScriptLoaderBase._runnableObject
private

Property Documentation

bool IG.Lib.ScriptLoaderBase.IsScriptLoaderInitialized
getprotected set

Whether the current script loader is initialized or not.

bool IG.Lib.ScriptLoaderBase.IsScriptingInitialized
staticgetprotected set

Whether scripting system is initialized or not.

object IG.Lib.ScriptLoaderBase.Lock
get

This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock.

List<string> IG.Lib.ScriptLoaderBase.DefaultAssemblies
staticgetprotected

Gets the list of assemblies that are added to all newly created script loaders by default.

SortedList<string, string> IG.Lib.ScriptLoaderBase.UsedClassFullNames
staticgetprotected

Stores used class names, i.e. class names that have already been used for dynamiically loaded classes.

Every time a new class is dynamically loaded, its full name is added to this list.

ScriptLoaderBase IG.Lib.ScriptLoaderBase.Global
staticgetset

Global script loader. Getter always returns a non-null object.

int IG.Lib.ScriptLoaderBase.OutputLevel
getset

Definbes level of output on console that is generated by some operations. 0 means that no output will be written to the console.

virtual Logger IG.Lib.ScriptLoaderBase.Logger
get

Gets the logger that is used to log errors and warnings.

virtual string IG.Lib.ScriptLoaderBase.Code
getset

Gets or sets code to be compiled. Get: If not assigned explicitly then CodeBase is taken.

bool IG.Lib.ScriptLoaderBase.PerformNamesCorrection
getset

Specifies whether automatic checking and correction of the class and namespace name in the loaded code is performed. If correction is switched on, it is performed before every compilation. Correction first checks if the class name has already been used, and if this is the case, it changes the name to the one that has not yet been used. It is then checked whether the namespace and class names used in the code are the same as those set on the current script loader. If not then names are replaced. At this stage, the assumed namespace class names are the first namespace and the first class found in the code block.

virtual string IG.Lib.ScriptLoaderBase.LanguageName
getprotected set

Language used by compiler.

virtual string IG.Lib.ScriptLoaderBase.ClassNamespace
getprotected set

Namespace in which the compiled class is defined.

virtual string IG.Lib.ScriptLoaderBase.ClassInterface
get

Interface that is implemented by the compiled class.

virtual string IG.Lib.ScriptLoaderBase.ClassName
getset
virtual string IG.Lib.ScriptLoaderBase.ClassFullName
get

Name of the compiled class that contains loadable script.

virtual string IG.Lib.ScriptLoaderBase.AppDomainName
getset

Name of the application domain in which the class is loaded.

virtual string IG.Lib.ScriptLoaderBase.RunFunctionName
getprotected set

Name of the method of dynamically loadable classes that contains the runnable script.

virtual string IG.Lib.ScriptLoaderBase.InitFunctionName
getprotected set

Name of the initialization method of dynamically loadable classes.

virtual string IG.Lib.ScriptLoaderBase.ArgumentsName
getset

Agreed formal name of the arguments parameter. Agreement upon this name makes possible to execute scripts in which run arguments are referenced.

virtual string IG.Lib.ScriptLoaderBase.LibraryFilename
getset
virtual string IG.Lib.ScriptLoaderBase.LibraryDirectory
getprotected set

Returns directory where library will be compiled, which will be the directory of the executable that started the application.

virtual string IG.Lib.ScriptLoaderBase.LibraryPath
getprotected set

Path to the dll where code is compiled. We take the directory where executable is located.

virtual bool IG.Lib.ScriptLoaderBase.IsCodeLoaded
getprotected set

Whether scripting code to be compiled is loaded.

virtual bool IG.Lib.ScriptLoaderBase.IsCompiled
getprotected set

Whether the code is compiled.

virtual bool IG.Lib.ScriptLoaderBase.IsClassLoaded
getprotected set

Whether the compiled class corresponding to the script is prepared.

virtual bool IG.Lib.ScriptLoaderBase.IsObjectPrepared
getprotected set

Whether an instance of the object is prepared to be used.

virtual CompilerResults IG.Lib.ScriptLoaderBase.CompilerResults
getprotected set

Results of compilation.

virtual List<String> IG.Lib.ScriptLoaderBase.ReferencedAssemblies
get

List of assemblies that are referenced when compiling the code. Contains names of files containing referenced assemblies.

virtual bool IG.Lib.ScriptLoaderBase.ReferenceAllLoadedAssemblies
getset

If true then all assemblies that are currently loaded by the application are also added to the referenced assemblies when script code is compiled. This makes sure that all that is necessary is actually referenced.

virtual AppDomain IG.Lib.ScriptLoaderBase.ApplicationDomain
getsetprotected

Application domain used by the current script loader for loading assemblies.

virtual Assembly IG.Lib.ScriptLoaderBase.Assembly
getprotected set

Gets or sets the assembly that has been compiled and loaded into the current application domain from the source code.

Setter is protected.

virtual ILoadableScript IG.Lib.ScriptLoaderBase.CreatedObject
getprotected set

Object of the compiled class that has beeen created.


The documentation for this class was generated from the following file: