IGLib
1.7.2
The IGLib base library for development of numerical, technical and business applications.
|
Interface for simple command-line applicatino interpreters. More...
Public Member Functions | |
CommandThreadBase | GetCommmandThread (int whichCommandThread) |
Returns the specified command thread for the current interpreter. More... | |
string | GetVariableValue (CommandThread commandThread, string varName) |
Returns the value of the specified variable of the current command line interpreter. null is returned if the specified variable does not exist. More... | |
string | SetVariableValue (CommandThread commandThread, string varName, string value) |
Sets the specified variable to the specified value. More... | |
string | ClearVariable (CommandThread commandThread, string varName) |
Clears (removes) the specified variable. More... | |
string | PrintVariable (CommandThread commandThread, string varName) |
Prints the specified variable. More... | |
string[] | GetArguments (string commandLine) |
Parses a command line and extracts arguments from it. Arguments can be separated according to usual rules for command-line arguments: spaces are separators, there can be arbitraty number of spaces, and if we want an argument to contain spaces, we must enclose it in double quotes. Command line can also contain the command name followed by arguments. In this case it is treated in the same way, and command can be obtained simply as the first string in the returned array. More... | |
string | RunFile (CommandThread commandThread, string filePath) |
Runs all commands that are written in a file. Each line of a file is interpreted as a single command, consisting of command name followed by arguments. More... | |
string | RunInteractive (CommandThread commandThread) |
Reads commands one by one from the standard input and executes them. More... | |
bool | ContainsCommand (string commandName) |
Returns true if the specified command is installed on the interpreter, false if not. More... | |
string | RunWithoutModifications (CommandThread commandThread, string commandName, params string[] commandArguments) |
Runs the specified command with specified name, installed on the current application object, without any modifications of the command arguments. More... | |
string | Run (CommandThread commandThread, string commandName, string[] args) |
Runs the command with specified name, installed on the current application object. More... | |
string | Run (CommandThread commandThread, string[] args) |
Runs command where the first argument is command name. Extracts application name and runs the corresponding application delegate.Before running it, arguments for the application delegate are extracted and then passed to the delegate. More... | |
string | RunAsync (CommandThread commandThread, string[] args) |
Runs a command asynchronously where the first argument is command name. Extracts command name and runs the corresponding application delegate. Before running it, arguments for the application delegate are extracted and then passed to the delegate. More... | |
string | RunAsync (CommandThread commandThread, string commandName, params string[] commandArguments) |
Runs the command with specified name (installed on the current interpreter object) asynchronously. More... | |
bool | AsyncIsCompleted (int id) |
Returns true if the asynchronous command execution identified by id has completed, and false otherwise. More... | |
void | AsyncWaitAll () |
Waits until all asynchronously commands that have been eventually executed by the current interpreter, complete. More... | |
string | AsyncWait (int callId) |
Waits for the specified asynchronous command (specified by command ID) to complete. More... | |
void | AddCommand (string appName, ApplicationCommandDelegate appMain) |
Adds command with the specified name. More... | |
void | AddCommand (string commandName, ApplicationCommandDelegateMt commandDelegate) |
Adds command with the specified name. More... | |
void | AddCommandMt (string appName, ApplicationCommandDelegateMt appMain) |
Adds command with the specified name. More... | |
void | RemoveCommand (string appName) |
Removes the command with the specified name. More... | |
void | RemoveAllCommands () |
Removes all commands from the current interpreter. More... | |
void | AddModule (string moduleName, ModuleDelegate moduleDelegate) |
Adds a new module to the interpreter. This adds an initialization function (via a delegate) which is executed when module module initialization is performed. More... | |
void | LoadModule (string moduleName) |
Loads and initializes the specified module. More... | |
bool | IsModuleLoaded (string moduleName) |
Returns true if the specified module has been loaded on the interpreter, false if not. More... | |
string | RunScriptFile (string scriptFilePath, string[] initAndRunArgs) |
Dynamically loads (temporarily, just for execution of the current commad) a class form the script contained in the specified file and executes its executable method. The file must contain the script that is dynamically loaded and executed, in form of definition of the appropriate class of type ILoadableScript. The dynamically loadable script class is loaded from the file and instantiated by the LoadableScriptInterpreter interpreter that is based on loadable scripts. More... | |
void | LoadScript (string newCommandName, string scriptFilePath, string[] initArgs) |
Dynamically loads (compiles and instantiates) a loadable script class contained in the specified file, and installs a new command on LoadableScriptInterpreter and on the current interpreter, based on the dynamically created instance of the loaded (dynamically compiled) class. More... | |
string | RunLoadedScript (string commandName, string[] arguments) |
Executes the specified command that has been dynamically loaded form a script. More... | |
string[] | GetLoadableScriptReferencedAssemblies () |
Returns an array of assemblies that are currently referenced by the script loader that takes care of loading the dynamic scripts. More... | |
Properties | |
string | Name [get, set] |
Name of the current interpreter. More... | |
string | Description [get, set] |
Description of hte current interpreter. More... | |
CommandStackFrame | GlobalFrame [get] |
Global frame where global variables are stored. More... | |
CommandThread | MainThread [get] |
Main command thread of the interpreter (usually run in the same thread where interpreter was created). More... | |
int | NumCommandThreads [get] |
Returns the number of command threads that are currently contained on the interpreter. More... | |
bool | Exit [get] |
Whether the exit flag is set, usually causing interpreter to stop. More... | |
int | OutputLevel [get, set] |
Level of output for some of the interpreter's functionality (e.g. asynchronous command execution). More... | |
bool | WarnCommandReplacement [get, set] |
Specifies whether a wrning should be launched whenever an installed command is being replaced. More... | |
LoadableScriptInterpreterBase | LoadableScriptInterpreter [get, set] |
Interprater based on dynamically loadable scripts. This enables installation and running of commands that are based on C# code that is dynamically compiled. Ihe object is created on first get access if it has not been assigned before. This property can be overridden in derived classes such that getter creates a dynamically loadable script - based interpreter of another kind. This is important because different script loaders (in particuar with different dynamic libraries referenced) will be used in different contexts. Another possibility is that a custom object is assigned to this property, usually in the initialization stage of the current interpreter. More... | |
Interface for simple command-line applicatino interpreters.
$A Igor xx Aug08 Dec09;
CommandThreadBase IG.Lib.ICommandLineApplicationInterpreter.GetCommmandThread | ( | int | whichCommandThread | ) |
Returns the specified command thread for the current interpreter.
whichCommandThread | Index of the thread on the list of interpreter's threads. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
Referenced by IG.Lib.CommandThreadBase.ToString().
string IG.Lib.ICommandLineApplicationInterpreter.GetVariableValue | ( | CommandThread | commandThread, |
string | varName | ||
) |
Returns the value of the specified variable of the current command line interpreter. null is returned if the specified variable does not exist.
commandThread | Command thread that is being executed. |
varName | Name of the variable. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.SetVariableValue | ( | CommandThread | commandThread, |
string | varName, | ||
string | value | ||
) |
Sets the specified variable to the specified value.
commandThread | Command thread that is being executed. |
varName | Name of the variable to be set. |
value | Value that is assigned to the variable. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.ClearVariable | ( | CommandThread | commandThread, |
string | varName | ||
) |
Clears (removes) the specified variable.
commandThread | Command thread that is being executed. |
varName | Name of the variable to be cleared. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.PrintVariable | ( | CommandThread | commandThread, |
string | varName | ||
) |
Prints the specified variable.
commandThread | Command thread that is being executed. |
varName | Name of the variable to be cleared. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string [] IG.Lib.ICommandLineApplicationInterpreter.GetArguments | ( | string | commandLine | ) |
Parses a command line and extracts arguments from it. Arguments can be separated according to usual rules for command-line arguments: spaces are separators, there can be arbitraty number of spaces, and if we want an argument to contain spaces, we must enclose it in double quotes. Command line can also contain the command name followed by arguments. In this case it is treated in the same way, and command can be obtained simply as the first string in the returned array.
commandLine | Command line that is split to individual arguments. Command line can also contain a command, which is treated equally. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.RunFile | ( | CommandThread | commandThread, |
string | filePath | ||
) |
Runs all commands that are written in a file. Each line of a file is interpreted as a single command, consisting of command name followed by arguments.
commandThread | Command thread that is being executed. |
filePath | Path to the file containing commands. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.RunInteractive | ( | CommandThread | commandThread | ) |
Reads commands one by one from the standard input and executes them.
commandThread | Command thread that is being executed. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
bool IG.Lib.ICommandLineApplicationInterpreter.ContainsCommand | ( | string | commandName | ) |
Returns true if the specified command is installed on the interpreter, false if not.
Case sensitivity of the interpreter is treated appropriately.
commandName | Name of the command that is checked. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
Referenced by IG.Lib.LoadableScriptBase.Script_AddCommand().
string IG.Lib.ICommandLineApplicationInterpreter.RunWithoutModifications | ( | CommandThread | commandThread, |
string | commandName, | ||
params string[] | commandArguments | ||
) |
Runs the specified command with specified name, installed on the current application object, without any modifications of the command arguments.
commandThread | Commandline interpreter thread in which command is executed. |
commandName | Command name. |
commandArguments | Command arguments. |
This method should not be overriden, but the Run(CommandThread, string, string[]) method can be, e.g. in order to perform some argument or command name transformations.
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.Run | ( | CommandThread | commandThread, |
string | commandName, | ||
string[] | args | ||
) |
Runs the command with specified name, installed on the current application object.
commandThread | Commandline interpreter thread in which command is executed. |
commandName | Command name. |
args | Command arguments. |
Referenced by IG.Lib.CommandLineJobContainer.RunCommand().
string IG.Lib.ICommandLineApplicationInterpreter.Run | ( | CommandThread | commandThread, |
string[] | args | ||
) |
Runs command where the first argument is command name. Extracts application name and runs the corresponding application delegate.Before running it, arguments for the application delegate are extracted and then passed to the delegate.
commandThread | Commandline interpreter thread in which command is executed. |
args | Command arguments where the first argument is command name. The rest of the arguments are collected and passed to the command delegate. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.RunAsync | ( | CommandThread | commandThread, |
string[] | args | ||
) |
Runs a command asynchronously where the first argument is command name. Extracts command name and runs the corresponding application delegate. Before running it, arguments for the application delegate are extracted and then passed to the delegate.
commandThread | Commandline interpreter thread in which command is executed. |
args | Command arguments where the first argument is command name. The rest of the arguments are collected and passed to the command delegate. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.RunAsync | ( | CommandThread | commandThread, |
string | commandName, | ||
params string[] | commandArguments | ||
) |
Runs the command with specified name (installed on the current interpreter object) asynchronously.
commandThread | Commandline interpreter thread in which command is executed. |
commandName | Command name. |
commandArguments | Command arguments. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
bool IG.Lib.ICommandLineApplicationInterpreter.AsyncIsCompleted | ( | int | id | ) |
Returns true if the asynchronous command execution identified by id has completed, and false otherwise.
id | ID of the asynchronous command execution that is querried. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
void IG.Lib.ICommandLineApplicationInterpreter.AsyncWaitAll | ( | ) |
Waits until all asynchronously commands that have been eventually executed by the current interpreter, complete.
It is sometimes necessary to call this method if any asynchronous command invocations were made because such commands are executed in background threads, which are automatically broken when all foreground threads complete.
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.AsyncWait | ( | int | callId | ) |
Waits for the specified asynchronous command (specified by command ID) to complete.
callId | ID of the asynchronous command execution. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
void IG.Lib.ICommandLineApplicationInterpreter.AddCommand | ( | string | appName, |
ApplicationCommandDelegate | appMain | ||
) |
Adds command with the specified name.
Commands added in this way are suitable for single threaded invocation, unless they don't interact with interpreter.
appName | Name of the commant. |
appMain | Delegate that will be used to execute the command. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
Referenced by IG.Neural.NeuralAllpicationCommands.InstallCommands(), IG.Neural.NeuralApplicationCommandsTadej.InstallCommands(), and IG.Lib.LoadableScriptBase.Script_AddCommand().
void IG.Lib.ICommandLineApplicationInterpreter.AddCommand | ( | string | commandName, |
ApplicationCommandDelegateMt | commandDelegate | ||
) |
Adds command with the specified name.
commandName | Name of the commant. |
commandDelegate | Delegate that will be used to execute the command. |
WARNING: This should be removed later. It is only here such that when the signature of the old command functions is changed, the AddCommand can act on them, so no new errors need to be corrected. In the future, this shoud be removed, and AddCommandMt should be renamed to AddCommand, and the old obsolete AddCommand should be also removed.
[Obsolete "Converge both methods with the same signature to only one method - AddCommandMt should be used and renamed."]
Implemented in IG.Lib.CommandLineApplicationInterpreter.
void IG.Lib.ICommandLineApplicationInterpreter.AddCommandMt | ( | string | appName, |
ApplicationCommandDelegateMt | appMain | ||
) |
Adds command with the specified name.
appName | Name of the commant. |
appMain | Delegate that will be used to execute the command. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
Referenced by IG.Lib.CommandLineApplicationInterpreter.ModuleTest1(), and IG.Lib.CommandLineApplicationInterpreter.ModuleTest2().
void IG.Lib.ICommandLineApplicationInterpreter.RemoveCommand | ( | string | appName | ) |
Removes the command with the specified name.
appName | Name of the commad. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
Referenced by IG.Lib.LoadableScriptBase.Script_AddCommand(), and IG.Script.ScriptAppBase.Script_RemoveRunFileByScriptCommand().
void IG.Lib.ICommandLineApplicationInterpreter.RemoveAllCommands | ( | ) |
Removes all commands from the current interpreter.
Implemented in IG.Lib.CommandLineApplicationInterpreter.
Referenced by IG.Lib.LoadableScriptBase.Script_RemoveAllCommands().
void IG.Lib.ICommandLineApplicationInterpreter.AddModule | ( | string | moduleName, |
ModuleDelegate | moduleDelegate | ||
) |
Adds a new module to the interpreter. This adds an initialization function (via a delegate) which is executed when module module initialization is performed.
moduleName | Name of the module. When used, module names are case sensitive if commands are case sensitive. |
moduleDelegate | Method that performs module initialization. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
void IG.Lib.ICommandLineApplicationInterpreter.LoadModule | ( | string | moduleName | ) |
Loads and initializes the specified module.
moduleName | Name of the module. It is case sensitive if commands are case sensitive. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
bool IG.Lib.ICommandLineApplicationInterpreter.IsModuleLoaded | ( | string | moduleName | ) |
Returns true if the specified module has been loaded on the interpreter, false if not.
moduleName | Name of the module. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.RunScriptFile | ( | string | scriptFilePath, |
string[] | initAndRunArgs | ||
) |
Dynamically loads (temporarily, just for execution of the current commad) a class form the script contained in the specified file and executes its executable method. The file must contain the script that is dynamically loaded and executed, in form of definition of the appropriate class of type ILoadableScript. The dynamically loadable script class is loaded from the file and instantiated by the LoadableScriptInterpreter interpreter that is based on loadable scripts.
scriptFilePath | Path to the file containing loadable script must be the first argument to the method. |
initAndRunArgs | Initialization arguments for the object that will be instantiated in order to execute the script. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
void IG.Lib.ICommandLineApplicationInterpreter.LoadScript | ( | string | newCommandName, |
string | scriptFilePath, | ||
string[] | initArgs | ||
) |
Dynamically loads (compiles and instantiates) a loadable script class contained in the specified file, and installs a new command on LoadableScriptInterpreter and on the current interpreter, based on the dynamically created instance of the loaded (dynamically compiled) class.
newCommandName | Name of the newly installed command. |
scriptFilePath | Name of the file containing the script code that defines a loadable script class. |
initArgs | Arguments to the initialization method of the loaded object. The initialization method will be called before the first call to the executable method of the class, which takes care of execution of the newly installed command. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string IG.Lib.ICommandLineApplicationInterpreter.RunLoadedScript | ( | string | commandName, |
string[] | arguments | ||
) |
Executes the specified command that has been dynamically loaded form a script.
commandName | Name under which the command is installed on the current intepreter and on interpreder based on dynamically loaded scripts (LoadableScriptInterpreter). |
arguments | Arguments to the command. |
Implemented in IG.Lib.CommandLineApplicationInterpreter.
string [] IG.Lib.ICommandLineApplicationInterpreter.GetLoadableScriptReferencedAssemblies | ( | ) |
Returns an array of assemblies that are currently referenced by the script loader that takes care of loading the dynamic scripts.
Implemented in IG.Lib.CommandLineApplicationInterpreter.
|
getset |
Name of the current interpreter.
|
getset |
Description of hte current interpreter.
|
get |
Global frame where global variables are stored.
Referenced by IG.Lib.CommandStackFrameBase.ToString().
|
get |
Main command thread of the interpreter (usually run in the same thread where interpreter was created).
Referenced by IG.Lib.CommandLineJobContainer.RunCommand().
|
get |
Returns the number of command threads that are currently contained on the interpreter.
Referenced by IG.Lib.CommandThreadBase.ToString().
|
get |
Whether the exit flag is set, usually causing interpreter to stop.
|
getset |
Level of output for some of the interpreter's functionality (e.g. asynchronous command execution).
|
getset |
Specifies whether a wrning should be launched whenever an installed command is being replaced.
|
getset |
Interprater based on dynamically loadable scripts. This enables installation and running of commands that are based on C# code that is dynamically compiled. Ihe object is created on first get access if it has not been assigned before. This property can be overridden in derived classes such that getter creates a dynamically loadable script - based interpreter of another kind. This is important because different script loaders (in particuar with different dynamic libraries referenced) will be used in different contexts. Another possibility is that a custom object is assigned to this property, usually in the initialization stage of the current interpreter.
ArgumentNullException | When set to null reference. |
$A Igor Aug11;