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(_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()); } } string script = String.Format(@" device_id <- rtvs:::graphics.ide.getactivedeviceid() rtvs:::export_to_pdf(device_id, rtvs:::graphics.ide.getactiveplotid(device_id), {0}, {1}, {2}, {3}) ", "pdf", width, height, ("special").ToRStringLiteral()); var blobid = await session.EvaluateAsync <ulong>(script, REvaluationKind.Normal); using (DataTransferSession dts = new DataTransferSession(session, new WindowsFileSystem())) { 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()); }
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()); }