Example #1
0
        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);
            }
        }