Beispiel #1
0
        private void OnPlot(PlotMessage plot)
        {
            // We also store the original plot messages, so we can
            // validate that the files have been deleted when the host goes away
            OriginalPlotMessages.Add(plot);

            if (plot.FilePath.Length <= 0)
            {
                return;
            }

            // Make a copy of the plot file, and store the path to the copy
            // When the R code finishes executing, the graphics device is destructed,
            // which destructs all the plots which deletes the original plot files
            int index = PlotFilePaths.Count;

            PlotFilePaths.Add(SavePlotFile(plot.FilePath, index));
        }
Beispiel #2
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());
        }
Beispiel #3
0
        private async Task <IEnumerable <string> > ExportToImageAsync(string[] inputs, string[] format, string[] paths, int widthInPixels, int heightInPixels, int resolution)
        {
            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());
                    }
                }

                for (int i = 0; i < format.Length; ++i)
                {
                    await ExportToImageAsync(session, format[i], paths[i], widthInPixels, heightInPixels, resolution);
                }

                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());
        }