Class ModelLibraryBase<A, T, U, V>
Represents a local model file library. It fetches simulator model files from CDF, save a local copy and process the model (extract information). This library only keeps the latest version of a given model file
public abstract class ModelLibraryBase<A, T, U, V> : IModelProvider<A, T> where A : AutomationConfig where T : ModelStateBase where U : ModelStateBasePoco where V : ModelParsingInfo, new()
Type Parameters
A
Type of the automation configuration object
T
Type of the state object used in this library
U
Type of the data object used to serialize and deserialize state
V
Type of the model parsing information object
- Inheritance
-
ModelLibraryBase<A, T, U, V>
- Implements
-
IModelProvider<A, T>
- Derived
- Inherited Members
Constructors
ModelLibraryBase(ModelLibraryConfig, IList<SimulatorConfig>, CogniteDestination, ILogger, FileStorageClient, IExtractionStateStore)
Creates a new instance of the library using the provided parameters
public ModelLibraryBase(ModelLibraryConfig config, IList<SimulatorConfig> simulators, CogniteDestination cdf, ILogger logger, FileStorageClient downloadClient, IExtractionStateStore store = null)
Parameters
config
ModelLibraryConfigLibrary configuration
simulators
IList<SimulatorConfig>Dictionary of simulators
cdf
CogniteDestinationCDF destination object
logger
ILoggerLogger
downloadClient
FileStorageClientHTTP client to download files
store
IExtractionStateStoreState store for models state
Properties
_cdfFiles
CDF files resource. Can be used to read and write files in CDF
protected FilesResource _cdfFiles { get; }
Property Value
- FilesResource
_cdfSimulatorResources
CDF simulator resource. Can be used to read and write files in CDF
protected SimulatorsResource _cdfSimulatorResources { get; }
Property Value
- SimulatorsResource
_logger
Logger object
protected ILogger _logger { get; }
Property Value
_state
Dictionary holding the file states. The keys are the ids of the
CDF simulator model revisions and the values are the state objects of type T
Should only be modified from a single thread to avoid multi-threading issues.
public ConcurrentDictionary<string, T> _state { get; }
Property Value
_temporaryState
Temporary model states that are used once and then deleted after the run. We keep them in memory to avoid saving them to the state store and hence to avoid the multi-threading issues. This state is used to store temporary model file paths, used only in case a run item is received before the model file has been downloaded.
public Dictionary<string, T> _temporaryState { get; }
Property Value
- Dictionary<string, T>
Methods
ExtractModelInformation(T, CancellationToken)
This method should open the model versions in the simulator, extract the required information and ingest it to CDF.
protected abstract Task ExtractModelInformation(T modelState, CancellationToken token)
Parameters
modelState
TModel file states
token
CancellationTokenCancellation token
Returns
GetModelRevision(string)
Returns the state object of the given version of the given model
public Task<T> GetModelRevision(string modelRevisionExternalId)
Parameters
modelRevisionExternalId
stringModel revision external id
Returns
- Task<T>
State object
GetRunTasks(CancellationToken)
Creates a list of the tasks performed by this library. These include searching and downloading files ans saving state.
public IEnumerable<Task> GetRunTasks(CancellationToken token)
Parameters
token
CancellationTokenCancellation token
Returns
- IEnumerable<Task>
List of tasks
Init(CancellationToken)
Initializes the local model library from the state store (sqlite database)
public Task Init(CancellationToken token)
Parameters
token
CancellationTokenCancellation token
Returns
StateFromModelRevision(SimulatorModelRevision)
Creates a state object of type T
from a
CDF Simulator model revision passed as parameter
protected abstract T StateFromModelRevision(SimulatorModelRevision modelRevision)
Parameters
modelRevision
SimulatorModelRevisionCDF Simulator model revision
Returns
- T
File state object
StoreLibraryState(CancellationToken)
Persists the library state from memory to the store
public Task StoreLibraryState(CancellationToken token)
Parameters
token
CancellationTokenCancellation token
Returns
WipeTemporaryModelFiles()
Wipes all temporary model files stored in memory
public void WipeTemporaryModelFiles()