public void Test_CompletedWorks( )
        {
            ImportRun            importRun = new ImportRun( );
            ICancellationWatcher watcher   = new ImportRunCancellationWatcher(importRun);

            Assert.That(watcher.IsCancellationRequested, Is.False);
            importRun.ImportRunStatus_Enum = WorkflowRunState_Enumeration.WorkflowRunStarted;
            Assert.That(watcher.IsCancellationRequested, Is.False);
            importRun.ImportRunStatus_Enum = WorkflowRunState_Enumeration.WorkflowRunCompleted;
            Assert.That(watcher.IsCancellationRequested, Is.False);
        }
Пример #2
0
        /// <summary>
        /// Start processing an import run, after checking has been performed.
        /// </summary>
        /// <param name="importRun">A writable import run entity. Caller will save.</param>
        internal void StartImportSafe(ImportRun importRun)
        {
            ImportConfig importConfig = importRun.ImportConfigUsed;

            if (importConfig == null)
            {
                throw new ConnectorConfigException("Import configuration could not be loaded.");
            }
            if (importConfig.ImportConfigMapping == null)
            {
                throw new ConnectorConfigException("Import configuration has no mapping.");
            }

            IObjectsReader         recordsReader = null;
            IReaderToEntityAdapter entityAdapter;
            IImportReporter        importRunReporter;
            IRecordImporter        recordImporter;
            ICancellationWatcher   cancellationWatcher;
            BatchRunner            batchRunner;

            try
            {
                // Reads records out of the file to count
                recordsReader = GetRecordsReader(importRun, importConfig);
                importRun.ImportRecordsTotal = recordsReader.GetObjects( ).Count( );
                importRun.Save( );

                // Re-reads records out of the file for importing
                recordsReader = GetRecordsReader(importRun, importConfig);

                // Writes records into entities
                entityAdapter = GetEntityAdapter(importConfig);

                // Create a reporter to process progress notifications
                importRunReporter = new ImportRunReporter(importRun);

                // Create a reporter to process progress notifications
                cancellationWatcher = new ImportRunCancellationWatcher(importRun);

                // Activate record impoter
                bool testRun = importRun.ImportTestRun == true;
                recordImporter = _recordImporterActivator(entityAdapter, importRunReporter, importConfig.ImportConfigMapping, testRun);
                if (recordImporter == null)
                {
                    throw new Exception("recordImporter failed to activate.");
                }

                // Connects the reader to the writer
                batchRunner = new BatchRunner
                {
                    ObjectsReader       = recordsReader,
                    RecordImporter      = recordImporter,
                    CancellationWatcher = cancellationWatcher
                };

                // Go! Run as user
                using (new SecurityBypassContext(false))
                {
                    batchRunner.ProcessAll( );
                }
            }
            finally
            {
                recordsReader?.Dispose( );
            }
        }