public void PlatformExportBackground(PlatformExportImportRequest exportRequest, string platformVersion, string author, ExportImportProgressNotificationEvent notifyEvent) { Action<ExportImportProgressInfo> progressCallback = (x) => { notifyEvent.InjectFrom(x); _eventNotifier.Upsert(notifyEvent); }; var now = DateTime.UtcNow; try { var exportedModules = InnerGetModulesWithInterface(typeof(ISupportExportModule)).Where(x => exportRequest.Modules.Contains(x.Id)).ToArray(); using (var stream = new MemoryStream()) { var options = new PlatformExportImportOptions { Modules = exportedModules, PlatformSecurity = exportRequest.PlatformSecurity, PlatformSettings = exportRequest.PlatformSettings, PlatformVersion = SemanticVersion.Parse(platformVersion), Author = author }; _platformExportManager.Export(stream, options, progressCallback); stream.Seek(0, SeekOrigin.Begin); //Upload result to blob storage var uploadInfo = new UploadStreamInfo { FileName = "Platform-" + now.ToString("yyMMddhh") + "-export.zip", FileByteStream = stream, FolderName = "tmp" }; var blobKey = _blobStorageProvider.Upload(uploadInfo); //Get a download url notifyEvent.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(blobKey); notifyEvent.Description = "Export finished"; } } catch(Exception ex) { notifyEvent.Errors.Add(ex.ExpandExceptionMessage()); } finally { notifyEvent.Finished = DateTime.UtcNow; _eventNotifier.Upsert(notifyEvent); } }
public IHttpActionResult ProcessExport(PlatformExportImportRequest exportRequest) { var notification = new ExportImportProgressNotificationEvent(CurrentPrincipal.GetCurrentUserName()) { Title = "Platform export task", Description = "starting export...." }; _eventNotifier.Upsert(notification); var now = DateTime.UtcNow; BackgroundJob.Enqueue(() => PlatformExportBackground(exportRequest, PlatformVersion.CurrentVersion.ToString(), CurrentPrincipal.GetCurrentUserName(), notification)); return Ok(notification); }
public void PlatformImportBackground(PlatformExportImportRequest importRequest, ExportImportProgressNotificationEvent notifyEvent) { Action<ExportImportProgressInfo> progressCallback = (x) => { notifyEvent.InjectFrom(x); _eventNotifier.Upsert(notifyEvent); }; var now = DateTime.UtcNow; try { var importedModules = InnerGetModulesWithInterface(typeof(ISupportImportModule)).Where(x => importRequest.Modules.Contains(x.Id)).ToArray(); using (var stream = _blobStorageProvider.OpenReadOnly(importRequest.FileUrl)) { var options = new PlatformExportImportOptions { Modules = importedModules, PlatformSecurity = importRequest.PlatformSecurity, PlatformSettings = importRequest.PlatformSettings, }; _platformExportManager.Import(stream, options, progressCallback); } } catch (Exception ex) { notifyEvent.Errors.Add(ex.ExpandExceptionMessage()); } finally { notifyEvent.Finished = DateTime.UtcNow; _eventNotifier.Upsert(notifyEvent); } }