public void BackgroundImport(ImportRequest request, ImportNotification notification) { Action <ExportImportProgressInfo> progressCallback = c => { notification.InjectFrom(c); _notifier.Upsert(notification); }; using (var stream = _blobStorageProvider.OpenRead(request.FileUrl)) { try { _csvCouponImporter.DoImport(stream, request.Delimiter, request.PromotionId, request.ExpirationDate, progressCallback); } catch (Exception exception) { notification.Description = "Import error"; notification.ErrorCount++; notification.Errors.Add(exception.ToString()); } finally { notification.Finished = DateTime.UtcNow; notification.Description = "Import finished" + (notification.Errors.Any() ? " with errors" : " successfully"); _notifier.Upsert(notification); } } }
// Only public methods can be invoked in the background. (Hangfire) public void BackgroundImport(CsvImportInfo importInfo, ImportNotification notifyEvent) { Action <ExportImportProgressInfo> progressCallback = x => { notifyEvent.InjectFrom(x); _notifier.Upsert(notifyEvent); }; using (var stream = _blobStorageProvider.OpenRead(importInfo.FileUrl)) { try { _csvImporter.DoImport(stream, importInfo, progressCallback); } catch (Exception ex) { notifyEvent.Description = "Export error"; notifyEvent.ErrorCount++; notifyEvent.Errors.Add(ex.ToString()); } finally { notifyEvent.Finished = DateTime.UtcNow; notifyEvent.Description = "Import finished" + (notifyEvent.Errors.Any() ? " with errors" : " successfully"); _notifier.Upsert(notifyEvent); } } }