Exemplo n.º 1
0
        private async Task <IReadOnlyList <RPackage> > GetPackagesAsync(Func <IRExpressionEvaluator, Task <JArray> > queryFunc)
        {
            // Fetching of installed and available packages is done in a
            // separate package query session to avoid freezing the REPL.
            try {
                var startupInfo = new RHostStartupInfo {
                    CranMirrorName = _settings.CranMirror,
                    CodePage       = _settings.RCodePage
                };

                using (var eval = await _sessionProvider.BeginEvaluationAsync(startupInfo)) {
                    // 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(eval.ExecuteAsync($"options(repos=eval(parse(text={repositories.ToRStringLiteral()})))"));
                    }
                    var libraries = (await DeparseLibrariesAsync());
                    if (libraries != null)
                    {
                        await WrapRException(eval.ExecuteAsync($".libPaths(eval(parse(text={libraries.ToRStringLiteral()})))"));
                    }

                    var result = await WrapRException(queryFunc(eval));

                    return(result.Select(p => p.ToObject <RPackage>()).ToList().AsReadOnly());
                }
            } catch (RHostDisconnectedException ex) {
                throw new RPackageManagerException(Resources.PackageManager_TransportError, ex);
            }
        }