Lean  $LEAN_TAG$
QuantConnect.AlgorithmFactory.Loader Class Reference

Loader creates and manages the memory and exception space of the algorithm, ensuring if it explodes the Lean Engine is intact. More...

Inheritance diagram for QuantConnect.AlgorithmFactory.Loader:
[legend]

Public Member Functions

 Loader ()
 Creates a new loader with a 10 second maximum load time that forces exactly one derived type to be found More...
 
 Loader (bool debugging, Language language, TimeSpan loaderTimeLimit, Func< List< string >, string > multipleTypeNameResolverFunction, WorkerThread workerThread=null)
 Creates a new loader with the specified configuration More...
 
bool TryCreateAlgorithmInstance (string assemblyPath, out IAlgorithm algorithmInstance, out string errorMessage)
 Creates a new instance of the specified class in the library, safely. More...
 
bool TryCreateAlgorithmInstanceWithIsolator (string assemblyPath, int ramLimit, out IAlgorithm algorithmInstance, out string errorMessage)
 Creates a new instance of the class in the library, safely. More...
 
void Unload ()
 Unload this factory's appDomain. More...
 

Static Public Member Functions

static List< string > GetExtendedTypeNames (Assembly assembly)
 Get a list of all the matching type names in this DLL assembly: More...
 

Properties

AppDomain appDomain [get, set]
 Memory space of the user algorithm More...
 

Detailed Description

Loader creates and manages the memory and exception space of the algorithm, ensuring if it explodes the Lean Engine is intact.

Definition at line 37 of file Loader.cs.

Constructor & Destructor Documentation

◆ Loader() [1/2]

QuantConnect.AlgorithmFactory.Loader.Loader ( )

Creates a new loader with a 10 second maximum load time that forces exactly one derived type to be found

Definition at line 77 of file Loader.cs.

◆ Loader() [2/2]

QuantConnect.AlgorithmFactory.Loader.Loader ( bool  debugging,
Language  language,
TimeSpan  loaderTimeLimit,
Func< List< string >, string >  multipleTypeNameResolverFunction,
WorkerThread  workerThread = null 
)

Creates a new loader with the specified configuration

Parameters
debuggingTrue if we are debugging
languageWhich language are we trying to load
loaderTimeLimitUsed to limit how long it takes to create a new instance
multipleTypeNameResolverFunctionUsed to resolve multiple type names found in assembly to a single type name, if null, defaults to names => names.SingleOrDefault()

When we search an assembly for derived types of IAlgorithm, sometimes the assembly will contain multiple matching types. This is the case for the QuantConnect.Algorithm assembly in this solution. In order to pick the correct type, consumers must specify how to pick the type, that's what this function does, it picks the correct type from the list of types found within the assembly.

Parameters
workerThreadThe worker thread instance the loader should use

Definition at line 98 of file Loader.cs.

Member Function Documentation

◆ TryCreateAlgorithmInstance()

bool QuantConnect.AlgorithmFactory.Loader.TryCreateAlgorithmInstance ( string  assemblyPath,
out IAlgorithm  algorithmInstance,
out string  errorMessage 
)

Creates a new instance of the specified class in the library, safely.

Parameters
assemblyPathLocation of the DLL
algorithmInstanceOutput algorithm instance
errorMessageOutput error message on failure
Returns
Bool true on successfully loading the class.

Definition at line 120 of file Loader.cs.

Here is the caller graph for this function:

◆ GetExtendedTypeNames()

static List<string> QuantConnect.AlgorithmFactory.Loader.GetExtendedTypeNames ( Assembly  assembly)
static

Get a list of all the matching type names in this DLL assembly:

Parameters
assemblyAssembly dll we're loading.
Returns
String list of types available.

Definition at line 303 of file Loader.cs.

Here is the call graph for this function:

◆ TryCreateAlgorithmInstanceWithIsolator()

bool QuantConnect.AlgorithmFactory.Loader.TryCreateAlgorithmInstanceWithIsolator ( string  assemblyPath,
int  ramLimit,
out IAlgorithm  algorithmInstance,
out string  errorMessage 
)

Creates a new instance of the class in the library, safely.

Parameters
assemblyPathLocation of the DLL
ramLimitLimit of the RAM for this process
algorithmInstanceOutput algorithm instance
errorMessageOutput error message on failure
Returns
bool success

Definition at line 361 of file Loader.cs.

Here is the call graph for this function:

◆ Unload()

void QuantConnect.AlgorithmFactory.Loader.Unload ( )

Unload this factory's appDomain.

Not used in lean engine. Running the library in an app domain is 10x slower.

See also
AppDomain.CreateDomain(string, Evidence, string, string, bool, AppDomainInitializer, string[])

Definition at line 392 of file Loader.cs.

Property Documentation

◆ appDomain

AppDomain QuantConnect.AlgorithmFactory.Loader.appDomain
getset

Memory space of the user algorithm

Definition at line 57 of file Loader.cs.


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