public virtual async Task ExportAsync(IEnumerable <string> groupIds, ITemplateSheetDataStore datastore, Dictionary <string, string> columnMappings) { var objects = await CollectPermittedObjectsAsync(groupIds); var dataAdapter = GetDataAdapter(datastore, columnMappings); dataAdapter.WriteObjects(objects); }
public ColumnMappedTemplateDataAdapter(ITemplateSheetDataStore store, Dictionary <string, string> columnMappings, bool includesNestedRows) : base(store, includesNestedRows) { _store = store; //columnMappings is a dictionary with { internalName => friendlyName } mappings. _friendlyColumnNames = columnMappings.ToDictionary(m => m.Key.ToLower(), m => m.Value); _internalColumnNames = columnMappings.ToDictionary(m => m.Value.ToLower(), m => m.Key); }
public async Task <ImportResult> ImportAsync(IEnumerable <string> includedGroupIds, ITemplateSheetDataStore datastore, Dictionary <string, string> columnMappings) { var dataAdapter = GetDataAdapter(datastore, columnMappings); var totalRowCount = 0; var mappedObjects = dataAdapter.ReadObjects(out totalRowCount, fields => //Field validation function { if (!_validateGroupTag) { return(true); } //Check whether this object belongs to a group that is inside the scope of included groups. var groupTag = (string)fields["grouptag"]; var isValid = _groupTagService.TagExists(groupTag); return(isValid); }); //Perform any further validations for mappedObjects. foreach (var obj in mappedObjects) { ValidateMappedObject(obj); } //Check whether there are any errors before begining actual import to database. var errorRows = GetErrorRows(mappedObjects); if (errorRows.Any()) { return new ImportResult { ErrorRows = errorRows, TotalProcessedRowCount = totalRowCount } } ; var importedObjectsCount = 0; //Perform import of all objects and record any errors. foreach (var mappedObject in mappedObjects) { try { BeforeImport(mappedObject.Object); //Allows custom code execution before import. await ImportObjectToDatabaseAsync(mappedObject.Object); AfterImport(mappedObject.Object); //Allows custom code execution after import. importedObjectsCount++; } catch (YawnMassageException ex) { var dataRow = mappedObject.DataRowGroup.First(); dataRow.MarkAsError(ex.Message); } } errorRows = GetErrorRows(mappedObjects); return(new ImportResult { TotalProcessedRowCount = totalRowCount, ErrorRows = errorRows, SuccessObjectsCount = importedObjectsCount, }); }
protected abstract ITemplateDataAdapter <T> GetDataAdapter(ITemplateSheetDataStore datastore, Dictionary <string, string> columnMappings);
public TemplateDataAdapter(ITemplateSheetDataStore store, bool includesNestedRows) { _store = store; _includesNestedRows = includesNestedRows; }