public Task <ImportBatchResult> RunAsync(ImportBatch batch, CancellationToken cancellationToken) { if (batch == null) { throw new ArgumentNullException(nameof(batch)); } var profile = _importProfileStorage.GetImportProfile(batch.ImportProfileName); if (profile == null) { throw new Exception($"Import profile '{batch.ImportProfileName}' does not exist."); } var importType = _importTypeStorage.GetImportType(profile.ImportTypeName); var worker = _importWorkerFactory.Create(importType.WorkerType); var context = new ImportWorkerContext { Batch = batch, ImportType = importType, Profile = profile }; return(worker.RunAsync(context, cancellationToken)); }
public void Start() { var batch = new ImportBatch { ImportProfileName = "TestProfile", FileName = "some/file.csv" }; // run worker var importTask = _batchExecutor.RunAsync(batch, CancellationToken.None); importTask.ContinueWith((task) => { if (task.IsFaulted) { // handler error // task.Exception return; } var result = task.Result; }); }