Beispiel #1
0
        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);
            }
        }