Beispiel #1
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(_services)) {
                await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest));

                var session = sessionProvider.GetOrCreate(_testMethod.FileSystemSafeName);
                await session.StartHostAsync(new RHostStartupInfo(), 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());
        }
Beispiel #2
0
        private async Task <IEnumerable <string> > ExportToPdfAsync(string[] inputs, string filePath, int width, int height)
        {
            var app = new RHostClientTestApp {
                PlotHandler = OnPlot
            };

            using (var sessionProvider = new RSessionProvider()) {
                var session = sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector);
                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 + "\n");
                    }
                }

                string script = String.Format("rtvs:::export_to_pdf({0}, {1})", width, height);
                var    data   = await session.EvaluateAsync <byte[]>(script, REvaluationKind.Normal);

                File.WriteAllBytes(filePath, data);

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

            using (var sessionProvider = new RSessionProvider()) {
                var session = sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector);
                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 + "\n");
                    }
                }

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