public IHttpActionResult ProcessExport(PlatformImportExportRequest exportRequest) { var notification = new PlatformExportPushNotification(_userNameResolver.GetCurrentUserName()) { Title = "Platform export task", Description = "starting export...." }; _pushNotifier.Upsert(notification); BackgroundJob.Enqueue(() => PlatformExportBackground(exportRequest, notification)); return(Ok(notification)); }
public ActionResult <PlatformExportPushNotification> ProcessExport([FromBody] PlatformImportExportRequest exportRequest) { var notification = new PlatformExportPushNotification(_userNameResolver.GetCurrentUserName()) { Title = "Platform export task", Description = "starting export...." }; _pushNotifier.Send(notification); var jobId = BackgroundJob.Enqueue(() => PlatformExportBackgroundAsync(exportRequest, notification, JobCancellationToken.Null, null)); notification.JobId = jobId; return(Ok(notification)); }
public void PlatformExportBackground(PlatformImportExportRequest exportRequest, PlatformExportPushNotification pushNotification) { Action <ExportImportProgressInfo> progressCallback = x => { pushNotification.InjectFrom(x); pushNotification.Errors = x.Errors; _pushNotifier.Upsert(pushNotification); }; try { const string relativeUrl = "tmp/exported_data.zip"; var localTmpFolder = HostingEnvironment.MapPath("~/App_Data/Uploads/tmp"); var localTmpPath = Path.Combine(localTmpFolder, "exported_data.zip"); if (!Directory.Exists(localTmpFolder)) { Directory.CreateDirectory(localTmpFolder); } //Import first to local tmp folder because Azure blob storage doesn't support some special file access mode using (var stream = File.Open(localTmpPath, FileMode.OpenOrCreate)) { var manifest = exportRequest.ToManifest(); _platformExportManager.Export(stream, manifest, progressCallback); } //Copy export data to blob provider for get public download url using (var localStream = File.Open(localTmpPath, FileMode.Open)) using (var blobStream = _blobStorageProvider.OpenWrite(relativeUrl)) { localStream.CopyTo(blobStream); //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 async Task PlatformExportBackgroundAsync(PlatformImportExportRequest exportRequest, PlatformExportPushNotification pushNotification, IJobCancellationToken cancellationToken, PerformContext context) { void progressCallback(ExportImportProgressInfo x) { pushNotification.Path(x); pushNotification.JobId = context.BackgroundJob.Id; _pushNotifier.Send(pushNotification); } try { var localTmpFolder = Path.GetFullPath(Path.Combine(_platformOptions.DefaultExportFolder)); var localTmpPath = Path.Combine(localTmpFolder, Path.GetFileName(_platformOptions.DefaultExportFileName)); if (!Directory.Exists(localTmpFolder)) { Directory.CreateDirectory(localTmpFolder); } if (System.IO.File.Exists(localTmpPath)) { System.IO.File.Delete(localTmpPath); } //Import first to local tmp folder because Azure blob storage doesn't support some special file access mode using (var stream = System.IO.File.OpenWrite(localTmpPath)) { var manifest = exportRequest.ToManifest(); await _platformExportManager.ExportAsync(stream, manifest, progressCallback, new JobCancellationTokenWrapper(cancellationToken)); pushNotification.DownloadUrl = $"api/platform/export/download/{_platformOptions.DefaultExportFileName}"; } } catch (JobAbortedException) { //do nothing } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Export finished"; pushNotification.Finished = DateTime.UtcNow; await _pushNotifier.SendAsync(pushNotification); } }
public async Task PlatformExportBackgroundAsync(PlatformImportExportRequest exportRequest, PlatformExportPushNotification pushNotification, IJobCancellationToken cancellationToken, PerformContext context) { Action <ExportImportProgressInfo> progressCallback = x => { pushNotification.Path(x); pushNotification.JobId = context.BackgroundJob.Id; _pushNotifier.SendAsync(pushNotification); }; try { const string relativeUrl = "tmp/exported_data.zip"; var localTmpFolder = _hostEnv.MapPath(Path.Combine(_platformOptions.LocalUploadFolderPath, "tmp")); var localTmpPath = Path.Combine(localTmpFolder, "exported_data.zip"); if (!Directory.Exists(localTmpFolder)) { Directory.CreateDirectory(localTmpFolder); } //Import first to local tmp folder because Azure blob storage doesn't support some special file access mode using (var stream = System.IO.File.Open(localTmpPath, FileMode.OpenOrCreate)) { var manifest = exportRequest.ToManifest(); await _platformExportManager.ExportAsync(stream, manifest, progressCallback, new JobCancellationTokenWrapper(cancellationToken)); } //Copy export data to blob provider for get public download url using (var localStream = System.IO.File.Open(localTmpPath, FileMode.Open)) using (var blobStream = _blobStorageProvider.OpenWrite(relativeUrl)) { localStream.CopyTo(blobStream); //Get a download url pushNotification.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(relativeUrl); } } catch (JobAbortedException) { //do nothing } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Export finished"; pushNotification.Finished = DateTime.UtcNow; await _pushNotifier.SendAsync(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 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 { var localTmpFolder = HostingEnvironment.MapPath(_defaultExportFolder); var localTmpPath = Path.Combine(localTmpFolder, _defaultExportFileName); if (!Directory.Exists(localTmpFolder)) { Directory.CreateDirectory(localTmpFolder); } //Import first to local tmp folder because Azure blob storage doesn't support some special file access mode using (var stream = File.Open(localTmpPath, FileMode.OpenOrCreate)) { var manifest = exportRequest.ToManifest(); _platformExportManager.Export(stream, manifest, progressCallback); pushNotification.DownloadUrl = $"api/platform/export/download/{_defaultExportFileName}"; } } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Export finished"; pushNotification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(pushNotification); } }