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 { 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 void PlatformExportBackground(PlatformImportExportRequest exportRequest, PlatformExportPushNotification pushNotification) { Action<ExportImportProgressInfo> progressCallback = x => { pushNotification.InjectFrom(x); pushNotification.Errors = x.Errors; _pushNotifier.Upsert(pushNotification); }; try { using (var stream = new MemoryStream()) { var manifest = exportRequest.ToManifest(); _platformExportManager.Export(stream, manifest, progressCallback); stream.Seek(0, SeekOrigin.Begin); var relativeUrl = "tmp/exported_data.zip"; using (var targetStream = _blobStorageProvider.OpenWrite(relativeUrl)) { stream.CopyTo(targetStream); } //Get a download url pushNotification.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(relativeUrl); } } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Export finished"; pushNotification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(pushNotification); } }
public void PlatformExportBackground(PlatformImportExportRequest exportRequest, PlatformExportPushNotification pushNotification) { Action<ExportImportProgressInfo> progressCallback = (x) => { pushNotification.InjectFrom(x); pushNotification.Errors = x.Errors; _pushNotifier.Upsert(pushNotification); }; try { using (var stream = new MemoryStream()) { var manifest = exportRequest.ToManifest(); _platformExportManager.Export(stream, manifest, progressCallback); stream.Seek(0, SeekOrigin.Begin); //Upload result to blob storage var uploadInfo = new UploadStreamInfo { FileName = string.Format("exported_data.zip"), FileByteStream = stream, FolderName = "tmp" }; var blobKey = _blobStorageProvider.Upload(uploadInfo); //Get a download url pushNotification.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(blobKey); } } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Export finished"; pushNotification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(pushNotification); } }
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); } }
public IHttpActionResult ProcessExport(PlatformImportExportRequest exportRequest) { var notification = new PlatformExportPushNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Platform export task", Description = "starting export...." }; _pushNotifier.Upsert(notification); var now = DateTime.UtcNow; BackgroundJob.Enqueue(() => PlatformExportBackground(exportRequest, notification)); return Ok(notification); }