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 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 async Task ExecuteAsync( BulkActionContext bulkActionContext, BulkActionPushNotification notification, IJobCancellationToken cancellationToken, PerformContext performContext) { Validate(bulkActionContext); Validate(performContext); try { var tokenWrapper = new JobCancellationTokenWrapper(cancellationToken); await _bulkActionExecutor.ExecuteAsync( bulkActionContext, context => { notification.Patch(context); notification.JobId = performContext.BackgroundJob.Id; _pushNotificationManager.Send(notification); }, tokenWrapper); } catch (JobAbortedException) { // idle } catch (Exception exception) { notification.Errors.Add(exception.ExpandExceptionMessage()); } finally { notification.Description = "Job finished"; notification.Finished = DateTime.UtcNow; _pushNotificationManager.Send(notification); } }