Example #1
0
        private Dictionary <Uri, IConnection> CreateConnectionList()
        {
            var connections  = GetConnectionsFromSettings();
            var localEngines = new RInstallation().GetCompatibleEngines();

            // Remove missing engines and add engines missing from saved connections
            // Set 'is used created' to false if path points to locally found interpreter
            foreach (var kvp in connections.Where(c => !c.Value.IsRemote).ToList())
            {
                var valid = IsValidLocalConnection(kvp.Value.Name, kvp.Value.Path);
                if (!valid)
                {
                    connections.Remove(kvp.Key);
                }
            }

            // Add newly installed engines
            foreach (var e in localEngines)
            {
                if (!connections.Values.Any(x => x.Path.PathEquals(e.InstallPath)))
                {
                    connections[new Uri(e.InstallPath, UriKind.Absolute)] = CreateConnection(e.Name, e.InstallPath, string.Empty, isUserCreated: false);
                }
            }

            // Verify that most recently used connection is still valid
            var last = _settings.LastActiveConnection;

            if (last != null && !IsRemoteConnection(last.Path) && !IsValidLocalConnection(last.Name, last.Path))
            {
                _settings.LastActiveConnection = null;
            }

            if (connections.Count == 0)
            {
                if (!localEngines.Any())
                {
                    var message = string.Format(CultureInfo.InvariantCulture, Resources.NoLocalR, Environment.NewLine + Environment.NewLine, Environment.NewLine);
                    if (_shell.ShowMessage(message, MessageButtons.YesNo) == MessageButtons.Yes)
                    {
                        var installer = _shell.ExportProvider.GetExportedValue <IMicrosoftRClientInstaller>();
                        installer.LaunchRClientSetup(_shell);
                        return(connections);
                    }
                }
                // No connections, may be first use or connections were removed.
                // Add local connections so there is at least something available.
                foreach (var e in localEngines)
                {
                    var c = CreateConnection(e.Name, e.InstallPath, string.Empty, isUserCreated: false);
                    connections[new Uri(e.InstallPath, UriKind.Absolute)] = c;
                }
            }
            return(connections);
        }
Example #2
0
        private IEnumerable <Interpreter> GetInterpreters()
        {
            if (_options.AutoDetect)
            {
                _logger.LogTrace(Resources.Trace_AutoDetectingR);

                var engines = new RInstallation().GetCompatibleEngines().AsList();
                if (engines.Any())
                {
                    var interpreterId = 0;
                    foreach (var e in engines)
                    {
                        var detected = new Interpreter(this, Invariant($"{interpreterId++}"), e.Name, e.InstallPath, e.BinPath, e.Version);
                        _logger.LogTrace(Resources.Trace_DetectedR, detected.Version, detected.Path);
                        yield return(detected);
                    }
                }
                else
                {
                    _logger.LogWarning(Resources.Error_NoRInterpreters);
                }
            }

            foreach (var kv in _options.Interpreters)
            {
                string             id      = kv.Key;
                InterpreterOptions options = kv.Value;

                if (!string.IsNullOrEmpty(options.BasePath) && _fs.DirectoryExists(options.BasePath))
                {
                    var interpInfo = new RInterpreterInfo(string.Empty, options.BasePath);
                    if (interpInfo.VerifyInstallation())
                    {
                        yield return(new Interpreter(this, id, options.Name, interpInfo.InstallPath, interpInfo.BinPath, interpInfo.Version));

                        continue;
                    }
                }

                _logger.LogError(Resources.Error_FailedRInstallationData, options.Name ?? id, options.BasePath);
            }
        }