Exemplo n.º 1
0
        private async Task RMarkdownRenderAsync(IRSession session, IFileSystem fs, string inputFilePath, string outputFilePath, string format, int codePage, IApplicationShell appShell)
        {
            using (var fts = new DataTransferSession(session, fs)) {
                string       currentStatusText = string.Empty;
                uint         cookie            = 0;
                IVsStatusbar statusBar         = null;
                appShell.DispatchOnUIThread(() => {
                    statusBar = appShell.GetGlobalService <IVsStatusbar>(typeof(SVsStatusbar));
                    statusBar.GetText(out currentStatusText);
                    statusBar.Progress(ref cookie, 1, "", 0, 0);
                });

                try {
                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); });
                    var rmd = await fts.SendFileAsync(inputFilePath);

                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1, 3); });
                    var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2, 3); });
                    await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath);

                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3, 3); });
                } finally {
                    appShell.DispatchOnUIThread(() => {
                        statusBar?.Progress(ref cookie, 0, "", 0, 0);
                        statusBar?.SetText(currentStatusText);
                    });
                }
            }
        }
Exemplo n.º 2
0
        private async Task RMarkdownRenderAsync(IRSession session, string inputFilePath, string outputFilePath, string format, int codePage, IServiceContainer services)
        {
            using (var fts = new DataTransferSession(session, services.FileSystem())) {
                string       currentStatusText = string.Empty;
                uint         cookie            = 0;
                IVsStatusbar statusBar         = null;
                services.MainThread().Post(() => {
                    statusBar = services.GetService <IVsStatusbar>(typeof(SVsStatusbar));
                    statusBar.GetText(out currentStatusText);
                    statusBar.Progress(ref cookie, 1, "", 0, 0);
                });

                try {
                    // TODO: progress and cancellation handling
                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); });
                    var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None);

                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1, 3); });
                    var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2, 3); });
                    await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath, true, null, CancellationToken.None);

                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3, 3); });
                } finally {
                    services.MainThread().Post(() => {
                        statusBar?.Progress(ref cookie, 0, "", 0, 0);
                        statusBar?.SetText(currentStatusText);
                    });
                }
            }
        }
Exemplo n.º 3
0
        private async Task RMarkdownRenderAsync(IRSession session, IFileSystem fs, string inputFilePath, string outputFilePath, string format, int codePage)
        {
            using (var fts = new DataTransferSession(session, fs)) {
                var rmd = await fts.SendFileAsync(inputFilePath);

                var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath);
            }
        }
Exemplo n.º 4
0
        private async Task ExportToImageAsync(IRSession session, string format, string filePath, int widthInPixels, int heightInPixels, int resolution)
        {
            string script = String.Format(@"
device_id <- rtvs:::graphics.ide.getactivedeviceid()
rtvs:::export_to_image(device_id, rtvs:::graphics.ide.getactiveplotid(device_id), {0}, {1}, {2}, {3})
", format, widthInPixels, heightInPixels, resolution);
            var    blobid = await session.EvaluateAsync <ulong>(script, REvaluationKind.Normal);

            using (DataTransferSession dts = new DataTransferSession(session, new FileSystem())) {
                await dts.FetchFileAsync(new RBlobInfo(blobid), filePath, true, null, CancellationToken.None);
            }
        }
Exemplo n.º 5
0
 private async Task ExportAsync(string outputFilePath, Task <ulong> exportTask)
 {
     try {
         var result = await exportTask;
         using (DataTransferSession dts = new DataTransferSession(InteractiveWorkflow.RSession, _fileSystem)) {
             await dts.FetchFileAsync(new RBlobInfo(result), outputFilePath);
         }
     } catch (IOException ex) {
         throw new RPlotManagerException(ex.Message, ex);
     } catch (RException ex) {
         throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex);
     }
 }
Exemplo n.º 6
0
        private async Task <IEnumerable <string> > ExportToPdfAsync(string[] inputs, string filePath, int width, int height)
        {
            var app = new RHostClientTestApp {
                PlotHandler = OnPlot, PlotDeviceCreateHandler = OnDeviceCreate, PlotDeviceDestroyHandler = OnDeviceDestroy
            };

            using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) {
                await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest));

                var session = sessionProvider.GetOrCreate(Guid.NewGuid());
                await session.StartHostAsync(new RHostStartupInfo {
                    Name = _testMethod.Name
                }, app, 50000);

                foreach (var input in inputs)
                {
                    using (var interaction = await session.BeginInteractionAsync()) {
                        await interaction.RespondAsync(input.EnsureLineBreak());
                    }
                }

                string script = String.Format(@"
device_id <- rtvs:::graphics.ide.getactivedeviceid()
rtvs:::export_to_pdf(device_id, rtvs:::graphics.ide.getactiveplotid(device_id), {0}, {1})
", width, height);
                var    blobid = await session.EvaluateAsync <ulong>(script, REvaluationKind.Normal);

                using (DataTransferSession dts = new DataTransferSession(session, new FileSystem())) {
                    await dts.FetchFileAsync(new RBlobInfo(blobid), filePath);
                }

                await session.StopHostAsync();
            }
            // Ensure that all plot files created by the graphics device have been deleted
            foreach (var plot in OriginalPlotMessages)
            {
                File.Exists(plot.FilePath).Should().BeFalse();
            }

            return(PlotFilePaths.AsReadOnly());
        }
Exemplo n.º 7
0
        private async Task RMarkdownRenderAsync(IRSession session, string inputFilePath, string outputFilePath, string format, int codePage, IServiceContainer services)
        {
            using (var fts = new DataTransferSession(session, services.FileSystem())) {
                var statusBar = services.GetService <IStatusBar>();
                using (var progress = await statusBar.ShowProgressAsync(3)) {
                    // TODO: cancellation handling
                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0));

                    var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None);

                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1));

                    var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2));
                    await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath, true, null, CancellationToken.None);

                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3));
                }
            }
        }
Exemplo n.º 8
0
        private static async Task CreateCsvAndStartProcess(IREvaluationResultInfo result, IRSession session, string fileName, IFileSystem fileSystem, IProgress <ProgressDialogData> progress)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
            var dec = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            using (var e = await session.BeginEvaluationAsync()) {
                var csvDataBlobId = await e.EvaluateAsync <ulong>($"rtvs:::export_to_csv({result.Expression}, sep={sep.ToRStringLiteral()}, dec={dec.ToRStringLiteral()})", REvaluationKind.Normal);

                using (DataTransferSession dts = new DataTransferSession(session, fileSystem)) {
                    var total = await session.GetBlobSizeAsync(csvDataBlobId, CancellationToken.None);

                    progress.Report(new ProgressDialogData(0, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV));
                    await dts.FetchFileAsync(new RBlobInfo(csvDataBlobId), fileName, true, new Progress <long>(b => {
                        var step = (int)(b * 100 / total);
                        progress.Report(new ProgressDialogData(step, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV));
                    }));

                    progress.Report(new ProgressDialogData(100, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV));
                }
            }
        }
Exemplo n.º 9
0
        private async Task<IEnumerable<string>> ExportToPdfAsync(string[] inputs, string filePath, int width, int height) {
            var app = new RHostClientTestApp { PlotHandler = OnPlot, PlotDeviceCreateHandler = OnDeviceCreate, PlotDeviceDestroyHandler = OnDeviceDestroy };
            using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) {
                await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest));
                var session = sessionProvider.GetOrCreate(Guid.NewGuid());
                await session.StartHostAsync(new RHostStartupInfo {
                    Name = _testMethod.Name
                }, app, 50000);

                foreach (var input in inputs) {
                    using (var interaction = await session.BeginInteractionAsync()) {
                        await interaction.RespondAsync(input.EnsureLineBreak());
                    }
                }

                string script = String.Format(@"
device_id <- rtvs:::graphics.ide.getactivedeviceid()
rtvs:::export_to_pdf(device_id, rtvs:::graphics.ide.getactiveplotid(device_id), {0}, {1})
", width, height);
                var blobid = await session.EvaluateAsync<ulong>(script, REvaluationKind.Normal);
                using (DataTransferSession dts = new DataTransferSession(session, new FileSystem())) {
                    await dts.FetchFileAsync(new RBlobInfo(blobid), filePath, true, null, CancellationToken.None);
                }

                await session.StopHostAsync();
            }
            // Ensure that all plot files created by the graphics device have been deleted
            foreach (var plot in OriginalPlotMessages) {
                File.Exists(plot.FilePath).Should().BeFalse();
            }

            return PlotFilePaths.AsReadOnly();
        }
Exemplo n.º 10
0
        private async Task ExportToImageAsync(IRSession session, string format, string filePath, int widthInPixels,int heightInPixels, int resolution) {
            string script = String.Format(@"
device_id <- rtvs:::graphics.ide.getactivedeviceid()
rtvs:::export_to_image(device_id, rtvs:::graphics.ide.getactiveplotid(device_id), {0}, {1}, {2}, {3})
", format, widthInPixels, heightInPixels, resolution);
            var blobid = await session.EvaluateAsync<ulong>(script, REvaluationKind.Normal);

            using(DataTransferSession dts = new DataTransferSession(session, new FileSystem())) {
                await dts.FetchFileAsync(new RBlobInfo(blobid), filePath, true, null, CancellationToken.None);
            }
        }