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 ActionResult <PlatformImportPushNotification> ProcessImport([FromBody] PlatformImportExportRequest importRequest) { var notification = new PlatformImportPushNotification(_userNameResolver.GetCurrentUserName()) { Title = "Platform import task", Description = "starting import...." }; _pushNotifier.Send(notification); var jobId = BackgroundJob.Enqueue(() => PlatformImportBackgroundAsync(importRequest, notification, JobCancellationToken.Null, null)); notification.JobId = jobId; 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 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 localPath = Path.GetFullPath(Path.Combine(_platformOptions.LocalUploadFolderPath, 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; 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 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); } }