private async Task <IReadOnlyList <RPackage> > GetPackagesAsync(Func <Task <JArray> > queryFunc, CancellationToken cancellationToken) { // Fetching of installed and available packages is done in a // separate package query session to avoid freezing the REPL. try { await _session.EnsureHostStartedAsync(new RHostStartupInfo(), null, cancellationToken : cancellationToken); await _session.SetVsCranSelectionAsync(CranMirrorList.UrlFromName(_settings.CranMirror), cancellationToken); await _session.SetCodePageAsync(_settings.RCodePage, cancellationToken); // Get the repos and libpaths from the REPL session and set them // in the package query session var repositories = (await DeparseRepositoriesAsync()); if (repositories != null) { await WrapRException(_session.ExecuteAsync($"options(repos=eval(parse(text={repositories.ToRStringLiteral()})))", cancellationToken)); } var libraries = (await DeparseLibrariesAsync()); if (libraries != null) { await WrapRException(_session.ExecuteAsync($".libPaths(eval(parse(text={libraries.ToRStringLiteral()})))", cancellationToken)); } var result = await WrapRException(queryFunc()); return(result.Select(p => p.ToObject <RPackage>()).ToList().AsReadOnly()); } catch (RHostDisconnectedException ex) { throw new RPackageManagerException(Resources.PackageManager_TransportError, ex); } }
public async Task SerializeWithEncoding(string expr, string json, int codepage) { if (json == SameAsInput) { json = expr; } await _session.SetCodePageAsync(codepage); var res = await _session.EvaluateAsync(expr, REvaluationKind.Normal); res.Error.Should().BeNullOrEmpty(); res.Result.Should().NotBeNull(); res.RawResult.Should().BeNull(); var actualJson = JsonConvert.SerializeObject(res.Result).ToUnicodeQuotes(); actualJson.Should().Be(json); }
public async Task RepresentationWithEncoding(string expr, string deparse, string str, string toString, int codepage) { await _session.SetCodePageAsync(codepage); await Representation(expr, deparse, str, toString); }