コード例 #1
0
        public static ImportRun CsvImport(ImportConfig config, string csvData)
        {
            ImportSettings settings = new ImportSettings
            {
                FileToken      = "whatever",
                ImportConfigId = config.Id
            };


            IFileRepository fileRepository = MockFileRepository.FromText(csvData);

            using (var scope = Factory.Current
                               .BeginLifetimeScope(builder => builder.RegisterInstance(fileRepository).Named <IFileRepository>(FileRepositoryModule.TemporaryFileRepositoryName)))
            {
                Assert.That(scope.ResolveKeyed <IFileRepository>(FileRepositoryModule.TemporaryFileRepositoryName), Is.InstanceOf <MockFileRepository>( ));

                // Create import run
                var       si          = ( SpreadsheetImporter )scope.Resolve <ISpreadsheetImporter>( );
                ImportRun importRun   = si.CreateImportRunEntity(config, settings);
                long      importRunId = importRun.Id;

                IImportRunWorker worker = scope.Resolve <IImportRunWorker>( );

                worker.StartImport(importRunId);
                return(importRun);
            }
        }
コード例 #2
0
        public static ImportRun RunTest(EntityType entityType, string fileName, ImportFormat importFormat, string sheetName = null)
        {
            string fileToken;

            using (Stream stream = SheetTestHelper.GetStream(fileName))
            {
                fileToken = FileRepositoryHelper.AddTemporaryFile(stream);
            }


            EntityType   type         = entityType;
            ImportConfig importConfig = CreateImportConfig(type, importFormat, sheetName);

            ImportRun importRun = CreateImportRun(importConfig, fileToken);

            ISpreadsheetInspector inspector = Factory.Current.Resolve <ISpreadsheetInspector>( );
            SpreadsheetInfo       info      = inspector.GetSpreadsheetInfo(fileToken, importFormat);
            SampleTable           sample    = inspector.GetSampleTable(fileToken, importFormat, sheetName, 1, 2, null);

            AddAllFields(importConfig, sample);

            // Run import
            IImportRunWorker worker = Factory.Current.Resolve <IImportRunWorker>( );

            worker.StartImport(importRun.Id);

            return(importRun);
        }
コード例 #3
0
        public void IImportRunWorker_Instance( )
        {
            IImportRunWorker importRunWorker = Factory.Current.Resolve <IImportRunWorker>( );

            Assert.That(importRunWorker, Is.InstanceOf <ImportRunWorker>());

            ImportRunWorker worker = ( ImportRunWorker )importRunWorker;

            Assert.That(worker.FileRepository, Is.InstanceOf <FileRepository>());
            FileRepository fileRepo = ( FileRepository )worker.FileRepository;

            Assert.That(fileRepo.Name, Is.EqualTo("Temporary"));
        }
コード例 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="entityRepository">Injected service</param>
        /// <param name="asyncRunner">Injected service</param>
        /// <param name="importRunWorker">Injected service</param>
        public SpreadsheetImporter(IEntityRepository entityRepository, IAsyncRunner asyncRunner, IImportRunWorker importRunWorker)
        {
            if (entityRepository == null)
            {
                throw new ArgumentNullException(nameof(entityRepository));
            }
            if (importRunWorker == null)
            {
                throw new ArgumentNullException(nameof(importRunWorker));
            }
            if (asyncRunner == null)
            {
                throw new ArgumentNullException(nameof(asyncRunner));
            }

            _entityRepository = entityRepository;
            _asyncRunner      = asyncRunner;
            _importRunWorker  = importRunWorker;
        }