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.ICommandLineApplicationInterpreter Interface Reference

Interface for simple command-line applicatino interpreters. More...

+ Inheritance diagram for IG.Lib.ICommandLineApplicationInterpreter:

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...
 

Detailed Description

Interface for simple command-line applicatino interpreters.

$A Igor xx Aug08 Dec09;

Member Function Documentation

CommandThreadBase IG.Lib.ICommandLineApplicationInterpreter.GetCommmandThread ( int  whichCommandThread)

Returns the specified command thread for the current interpreter.

Parameters
whichCommandThreadIndex 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.

Parameters
commandThreadCommand thread that is being executed.
varNameName 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.

Parameters
commandThreadCommand thread that is being executed.
varNameName of the variable to be set.
valueValue that is assigned to the variable.
Returns
New value of the variable (before the method was called).

Implemented in IG.Lib.CommandLineApplicationInterpreter.

string IG.Lib.ICommandLineApplicationInterpreter.ClearVariable ( CommandThread  commandThread,
string  varName 
)

Clears (removes) the specified variable.

Parameters
commandThreadCommand thread that is being executed.
varNameName of the variable to be cleared.
Returns
null.

Implemented in IG.Lib.CommandLineApplicationInterpreter.

string IG.Lib.ICommandLineApplicationInterpreter.PrintVariable ( CommandThread  commandThread,
string  varName 
)

Prints the specified variable.

Parameters
commandThreadCommand thread that is being executed.
varNameName of the variable to be cleared.
Returns
null.

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.

Parameters
commandLineCommand line that is split to individual arguments. Command line can also contain a command, which is treated equally.
Returns
An array of arguments.

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.

Parameters
commandThreadCommand thread that is being executed.
filePathPath to the file containing commands.
Returns
Return value of the last command.

Implemented in IG.Lib.CommandLineApplicationInterpreter.

string IG.Lib.ICommandLineApplicationInterpreter.RunInteractive ( CommandThread  commandThread)

Reads commands one by one from the standard input and executes them.

Parameters
commandThreadCommand 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.

Parameters
commandNameName of the command that is checked.
Returns
True if the specified command is installed on the current interpreter, false if not.

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.

Parameters
commandThreadCommandline interpreter thread in which command is executed.
commandNameCommand name.
commandArgumentsCommand 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.

Parameters
commandThreadCommandline interpreter thread in which command is executed.
commandNameCommand name.
argsCommand 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.

Parameters
commandThreadCommandline interpreter thread in which command is executed.
argsCommand 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.

Parameters
commandThreadCommandline interpreter thread in which command is executed.
argsCommand 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.

Parameters
commandThreadCommandline interpreter thread in which command is executed.
commandNameCommand name.
commandArgumentsCommand arguments.
Returns
ID of asynchronous run used to query results and whether command has completed, or -1 if a call was not launched (actually, an exception would be thrown in this case).

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.

Parameters
idID of the asynchronous command execution that is querried.
Returns

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.

Parameters
callIdID of the asynchronous command execution.
Returns
Results of the command if the command has not completed before, null otherwise.

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.

Parameters
appNameName of the commant.
appMainDelegate 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.

Parameters
commandNameName of the commant.
commandDelegateDelegate 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.

Parameters
appNameName of the commant.
appMainDelegate 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.

Parameters
appNameName 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.

Parameters
moduleNameName of the module. When used, module names are case sensitive if commands are case sensitive.
moduleDelegateMethod that performs module initialization.

Implemented in IG.Lib.CommandLineApplicationInterpreter.

void IG.Lib.ICommandLineApplicationInterpreter.LoadModule ( string  moduleName)

Loads and initializes the specified module.

Parameters
moduleNameName 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.

Parameters
moduleNameName 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.

Parameters
scriptFilePathPath to the file containing loadable script must be the first argument to the method.
initAndRunArgsInitialization arguments for the object that will be instantiated in order to execute the script.
Returns
Result of execution returned by the executable method of the dynamically loaded script object.

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.

Parameters
newCommandNameName of the newly installed command.
scriptFilePathName of the file containing the script code that defines a loadable script class.
initArgsArguments 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.

Parameters
commandNameName under which the command is installed on the current intepreter and on interpreder based on dynamically loaded scripts (LoadableScriptInterpreter).
argumentsArguments to the command.
Returns
Results of command execution.

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.

Returns

Implemented in IG.Lib.CommandLineApplicationInterpreter.

Property Documentation

string IG.Lib.ICommandLineApplicationInterpreter.Name
getset

Name of the current interpreter.

string IG.Lib.ICommandLineApplicationInterpreter.Description
getset

Description of hte current interpreter.

CommandStackFrame IG.Lib.ICommandLineApplicationInterpreter.GlobalFrame
get

Global frame where global variables are stored.

Referenced by IG.Lib.CommandStackFrameBase.ToString().

CommandThread IG.Lib.ICommandLineApplicationInterpreter.MainThread
get

Main command thread of the interpreter (usually run in the same thread where interpreter was created).

Referenced by IG.Lib.CommandLineJobContainer.RunCommand().

int IG.Lib.ICommandLineApplicationInterpreter.NumCommandThreads
get

Returns the number of command threads that are currently contained on the interpreter.

Referenced by IG.Lib.CommandThreadBase.ToString().

bool IG.Lib.ICommandLineApplicationInterpreter.Exit
get

Whether the exit flag is set, usually causing interpreter to stop.

int IG.Lib.ICommandLineApplicationInterpreter.OutputLevel
getset

Level of output for some of the interpreter's functionality (e.g. asynchronous command execution).

bool IG.Lib.ICommandLineApplicationInterpreter.WarnCommandReplacement
getset

Specifies whether a wrning should be launched whenever an installed command is being replaced.

LoadableScriptInterpreterBase IG.Lib.ICommandLineApplicationInterpreter.LoadableScriptInterpreter
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.

Exceptions
ArgumentNullExceptionWhen set to null reference.

$A Igor Aug11;


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