Class CSVImporter
A class designed to import data from a given csv format with the use of IDataMappingBase for mappings of the file format/etc
Implements
Inherited Members
Namespace: LemonEdge.API.Core.Processors.Importing
Assembly: LemonEdge.API.dll
Syntax
public class CSVImporter : IImporter
Constructors
CSVImporter(IDataMappingBase, IEnumerable<IDataMappingPropertyBase>, UserInfo, IReadOnlyCache, IProgressReporter, Func<Task<IEntityUpdater>>, IServiceContext)
Creates a new csv file importer with the specified mapping
Declaration
public CSVImporter(IDataMappingBase mapping, IEnumerable<IDataMappingPropertyBase> mappingProperties, UserInfo user, IReadOnlyCache cache, IProgressReporter reporter, Func<Task<IEntityUpdater>> getUpdater, IServiceContext services)
Parameters
Type | Name | Description |
---|---|---|
IDataMappingBase | mapping | The specified mapping for the file to use. If blank Default is used instead |
IEnumerable<IDataMappingPropertyBase> | mappingProperties | The specified property mapping for the import file. If null, then no mappings are used and the headers must match the expected template import headers for the entity type |
UserInfo | user | The current logged in user |
IReadOnlyCache | cache | A local cache |
IProgressReporter | reporter | A class for reporting the progress/status of the import to the client, or a log |
Func<Task<IEntityUpdater>> | getUpdater | A function that returns a new updater context for retrieving and updating items |
IServiceContext | services |
Properties
AlgorithmStepID
If this is executing within an algorithm step this holds the id of the executing step so all created/deleted/updated items can be linked to it
Declaration
public Guid? AlgorithmStepID { get; set; }
Property Value
Type | Description |
---|---|
Guid? |
AutoIncrementReferences
The list of auto increment references that have been created by this import and can be referenced by other imports
Declaration
public Dictionary<string, Guid> AutoIncrementReferences { get; }
Property Value
Type | Description |
---|---|
Dictionary<string, Guid> |
CachedIDsFromKeyLookup
Declaration
public Dictionary<CSVImporter.CacheType, CSVImporter.CachedIDKeys> CachedIDsFromKeyLookup { get; }
Property Value
Type | Description |
---|---|
Dictionary<CSVImporter.CacheType, CSVImporter.CachedIDKeys> |
MarkImportedItems
An action that is called on all imported/updated items to allow the callee a chance to add custom modifications
Declaration
public Action<IBaseEntity> MarkImportedItems { get; set; }
Property Value
Type | Description |
---|---|
Action<IBaseEntity> |
ProgressReporter
An interface for reporting the progress, or status, of the import back to the client or a log
Declaration
public IProgressReporter ProgressReporter { get; }
Property Value
Type | Description |
---|---|
IProgressReporter |
Step
If this is executing within an IImportDefinition then this holds the step this import represents for error/progress reporting
Declaration
public string Step { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
AddImportDefinitionArg(object)
Adds an object to a list of parameters to be used when retrieving the IEntityDescriptorImportExtender
Declaration
public void AddImportDefinitionArg(object arg)
Parameters
Type | Name | Description |
---|---|---|
object | arg | the object to add to the params |
ImportData(IEntityUpdater, bool, bool, bool, CancellationToken)
Imports the data specified using InitDataForImport(byte[]) according to the specified parameters
Leaves progress as 95% complete for saving if in batch/extra work/etc
Declaration
public Task<IEnumerable<ImportLineResultInfo>> ImportData(IEntityUpdater updater, bool saveSequentially, bool validate, bool bypassProcessors, CancellationToken cancel = default)
Parameters
Type | Name | Description |
---|---|---|
IEntityUpdater | updater | The current context of updater to use for importing/updating and committing the data |
bool | saveSequentially | Indicates the data should be saved and committed to the database. Creates a new context for each item to import.
If this is false, the data is just all imported into the |
bool | validate | |
bool | bypassProcessors | |
CancellationToken | cancel | A cancellation token to stop importing the data |
Returns
Type | Description |
---|---|
Task<IEnumerable<ImportLineResultInfo>> | A task representing the completion of the operation with a list of information for each item imported |
InitDataForImport(IAsyncEnumerable<DataRow>, int)
Adds an enumeration of datarows to be imported - used when enumerating sql data a row at a time instead of having to load whole data set into memory upfront
Declaration
public void InitDataForImport(IAsyncEnumerable<DataRow> asyncData, int count)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<DataRow> | asyncData | An enumeration of data rows to import. The table holds the schema |
int | count |
InitDataForImport(IEnumerable<(EntityDescriptor ImportType, byte[] ImportData)>)
Adds the set of entities and their associated file to import
Declaration
public void InitDataForImport(IEnumerable<(EntityDescriptor ImportType, byte[] ImportData)> importData)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<(EntityDescriptor ImportType, byte[] ImportData)> | importData | An enumeration of a tuple holding an entity type to import and its associated binary file csv data |
ProcessSaveResults(IEnumerable<IHasSaveProcessingTask>, IEnumerable<Guid>, IProgressReporter, IEntityUpdater)
Declaration
public static Task ProcessSaveResults(IEnumerable<IHasSaveProcessingTask> createdTasks, IEnumerable<Guid> newTaskIDs, IProgressReporter reporter, IEntityUpdater updater)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IHasSaveProcessingTask> | createdTasks | |
IEnumerable<Guid> | newTaskIDs | |
IProgressReporter | reporter | |
IEntityUpdater | updater |
Returns
Type | Description |
---|---|
Task |