Beispiel #1
0
 public async Task ImportAsync(ImportingJobDescriptor descriptor)
 {
     ShellScope.AddDeferredTask(async defferedTaskContext => {
         using (var tx = _transactionManager.BeginTransaction()) {
             var importTask = await this.CreateTaskAsync(descriptor);
             var context    = new ImportingTaskContext(defferedTaskContext.ServiceProvider, _environment.ContentRootFileProvider);
             await this.DoImportAsync(importTask, context);
             await tx.CommitAsync();
         }
     });
     await Task.CompletedTask;
 }
Beispiel #2
0
        async Task ImportSingleRecordAsync(
            ImportingJob importingTask, ImportingTaskContext context, IRecordFinder recordFinder, IRecordImporter recordImporter, IDataSourceReader reader)
        {
            var propValues = new Dictionary <string, object>(importingTask.Descriptor.ImportEntity.Fields.Count);

            foreach (var fieldMapping in importingTask.Descriptor.ImportEntity.Fields)
            {
                var propertyValueExpression = reader.GetField(fieldMapping.Selector).ToString();
                var metaProperty            = importingTask.Entity.Fields[fieldMapping.Field];
                if (metaProperty.Type.TryParse(metaProperty, propertyValueExpression, out var propertyValue, fieldMapping.Format))
                {
                    propValues.Add(metaProperty.Name, propertyValue);
                }
Beispiel #3
0
        async Task DoImportAsync(ImportingJob importingTask, ImportingTaskContext context)
        {
            var dataSource = _dataSources.Single(x => x.Format == importingTask.Descriptor.DataSource.Format);

            var recordFinderType = typeof(GenericRecordFinder <>).MakeGenericType(importingTask.Entity.ClrType);
            var recordFinder     = context.ServiceProvider.GetRequiredService(recordFinderType) as IRecordFinder;

            var recordImporterType = typeof(GenericRecordImporter <>).MakeGenericType(importingTask.Entity.ClrType);
            var recordImporter     = context.ServiceProvider.GetRequiredService(recordImporterType) as IRecordImporter;

            using (var stream = importingTask.ImportFileInfo.CreateReadStream())
                using (var reader = dataSource.Open(stream, importingTask.Descriptor.ImportEntity.Selector)) {
                    await reader.Initialize();

                    while (await reader.ReadAsync())
                    {
                        await ImportSingleRecordAsync(importingTask, context, recordFinder, recordImporter, reader);
                    }
                }
        }