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 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 { var relativeUrl = "tmp/exported_data.zip"; using (var stream = _blobStorageProvider.OpenWrite(relativeUrl)) { var manifest = exportRequest.ToManifest(); _platformExportManager.Export(stream, manifest, progressCallback); //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 fileName = string.Format(_platformOptions.DefaultExportFileName, DateTime.UtcNow); var localTmpFolder = Path.GetFullPath(Path.Combine(_platformOptions.DefaultExportFolder)); var localTmpPath = Path.Combine(localTmpFolder, Path.GetFileName(fileName)); 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/{fileName}"; } } 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 async Task PlatformImportBackgroundAsync(PlatformImportExportRequest importRequest, PlatformImportPushNotification pushNotification, IJobCancellationToken cancellationToken, PerformContext context) { void progressCallback(ExportImportProgressInfo x) { pushNotification.Path(x); pushNotification.JobId = context.BackgroundJob.Id; _pushNotifier.Send(pushNotification); } var now = DateTime.UtcNow; try { var cancellationTokenWrapper = new JobCancellationTokenWrapper(cancellationToken); var uploadFolderFullPath = Path.GetFullPath(_platformOptions.LocalUploadFolderPath); // VP-5353: Checking that the file is inside LocalUploadFolderPath var localPath = Path.Combine(uploadFolderFullPath, importRequest.FileUrl); if (!localPath.StartsWith(uploadFolderFullPath)) { throw new PlatformException($"Invalid path {localPath}"); } //Load source data only from local file system using (var stream = new FileStream(localPath, FileMode.Open)) { var manifest = importRequest.ToManifest(); manifest.Created = now; await _platformExportManager.ImportAsync(stream, manifest, progressCallback, cancellationTokenWrapper); } } catch (JobAbortedException) { //do nothing } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Import 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 { 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 void PlatformImportBackground(PlatformImportExportRequest importRequest, PlatformImportPushNotification pushNotification, IJobCancellationToken cancellationToken, PerformContext context) { Action <ExportImportProgressInfo> progressCallback = x => { pushNotification.Path(x); pushNotification.JobId = context.BackgroundJob.Id; _pushNotifier.SendAsync(pushNotification); }; var now = DateTime.UtcNow; try { var cancellationTokenWrapper = new JobCancellationTokenWrapper(cancellationToken); var localPath = _hostEnv.MapPath(importRequest.FileUrl); //Load source data only from local file system using (var stream = new FileStream(localPath, FileMode.Open)) { var manifest = importRequest.ToManifest(); manifest.Created = now; _platformExportManager.ImportAsync(stream, manifest, progressCallback, cancellationTokenWrapper); } } catch (JobAbortedException) { //do nothing } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Import finished"; pushNotification.Finished = DateTime.UtcNow; _pushNotifier.Send(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 { 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); } }