public void PlatformImportBackground(PlatformImportExportRequest importRequest, PlatformImportPushNotification pushNotification) { Action<ExportImportProgressInfo> progressCallback = x => { pushNotification.InjectFrom(x); pushNotification.Errors = x.Errors; _pushNotifier.Upsert(pushNotification); }; var now = DateTime.UtcNow; try { var localPath = HostingEnvironment.MapPath(importRequest.FileUrl); //Load source data only from local file system using (var stream = File.Open(localPath, FileMode.Open)) { var manifest = importRequest.ToManifest(); manifest.Created = now; _platformExportManager.Import(stream, manifest, progressCallback); } } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Import finished"; pushNotification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(pushNotification); } }
public IHttpActionResult ProcessImport(PlatformImportExportRequest importRequest) { var notification = new PlatformImportPushNotification(_userNameResolver.GetCurrentUserName()) { Title = "Platform import task", Description = "starting import...." }; _pushNotifier.Upsert(notification); BackgroundJob.Enqueue(() => PlatformImportBackground(importRequest, notification)); return Ok(notification); }
public void PlatformImportBackground(PlatformImportExportRequest importRequest, PlatformImportPushNotification pushNotification) { Action<ExportImportProgressInfo> progressCallback = (x) => { pushNotification.InjectFrom(x); pushNotification.Errors = x.Errors; _pushNotifier.Upsert(pushNotification); }; var now = DateTime.UtcNow; try { using (var stream = _blobStorageProvider.OpenReadOnly(importRequest.FileUrl)) { var manifest = importRequest.ToManifest(); manifest.Created = now; _platformExportManager.Import(stream, manifest, progressCallback); } } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Import finished"; pushNotification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(pushNotification); } }