Beispiel #1
0
        public void Duplicates()
        {
            var tr  = new RegistryMock(SimulateDuplicates());
            var svl = new SupportedRVersionRange(3, 2, 3, 4);

            string dir = @"C:\Program Files\Microsoft\R Client\R_SERVER";
            var    fs  = Substitute.For <IFileSystem>();
            var    fsi = Substitute.For <IFileSystemInfo>();

            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(@"C:\Program Files\Microsoft\R Client\R_SERVER").EnumerateFileSystemInfos().Returns(new IFileSystemInfo[] { fsi });

            var fvi = SimulateFileVersion(3, 22);

            fs.GetVersionInfo(Path.Combine(dir, @"bin\x64", "R.dll")).Returns(fvi);

            PretendRFilesAvailable(fs, dir);
            var ri = new RInstallation(tr, fs);

            var engines = ri.GetCompatibleEngines(svl);

            engines.Should().HaveCount(1);

            var e = engines.First();

            e.Name.Should().Contain("Microsoft R");
            e = new RInterpreterInfo(e.Name, e.InstallPath, fs);
        }
Beispiel #2
0
 private bool IsValidLocalConnection(string name, string path)
 {
     try {
         var info = new RInterpreterInfo(name, path);
         return(info.VerifyInstallation());
     } catch (Exception ex) when(!ex.IsCriticalException())
     {
         _shell.Services.Log.Write(LogVerbosity.Normal, MessageCategory.Error, ex.Message);
     }
     return(false);
 }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public void BrowseLocalPath(IConnectionViewModel connection)
        {
            Shell.AssertIsOnMainThread();
            if (connection == null)
            {
                return;
            }

            string latestLocalPath;
            Uri    latestLocalPathUri;

            if (connection.Path != null && Uri.TryCreate(connection.Path, UriKind.Absolute, out latestLocalPathUri) &&
                latestLocalPathUri.IsFile && !latestLocalPathUri.IsUnc)
            {
                latestLocalPath = latestLocalPathUri.LocalPath;
            }
            else
            {
                latestLocalPath = Environment.SystemDirectory;

                try {
                    latestLocalPath = new RInstallation().GetCompatibleEngines().FirstOrDefault()?.InstallPath;
                    if (string.IsNullOrEmpty(latestLocalPath) || !Directory.Exists(latestLocalPath))
                    {
                        // Force 64-bit PF
                        latestLocalPath = Environment.GetEnvironmentVariable("ProgramW6432");
                    }
                } catch (ArgumentException) { } catch (IOException) { }
            }

            var path = Shell.FileDialog.ShowBrowseDirectoryDialog(latestLocalPath);

            if (path != null)
            {
                // Verify path
                var ri = new RInterpreterInfo(string.Empty, path);
                if (ri.VerifyInstallation(null, null, Shell))
                {
                    connection.Path = path;
                }
            }
        }
Beispiel #5
0
        public void MissingBinaries()
        {
            var tr  = new RegistryMock(SimulateRegistry02());
            var svl = new SupportedRVersionRange(3, 1, 3, 4);

            string dir = @"C:\Program Files\R\R-3.1.3";
            var    fs  = Substitute.For <IFileSystem>();
            var    fsi = Substitute.For <IFileSystemInfo>();

            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(@"C:\Program Files\R").EnumerateFileSystemInfos().Returns(new IFileSystemInfo[] { fsi });

            var fvi = new Version(3, 13);

            fs.GetFileVersion(Path.Combine(dir, @"bin\x64", "R.dll")).Returns(fvi);

            PretendRFilesAvailable(fs, dir);
            var ri = new RInstallation(tr, fs);

            var e = ri.GetCompatibleEngines(svl).FirstOrDefault();

            e.Should().NotBeNull();

            var ui = Substitute.For <IUIService>();

            fs = Substitute.For <IFileSystem>();
            var coreShell = Substitute.For <ICoreShell>();

            coreShell.UI().Returns(ui);

            e = new RInterpreterInfo(e.Name, e.InstallPath, fs);
            e.VerifyInstallation(svl, fs, ui).Should().BeFalse();

            ui.When(x => x.ShowMessage(Arg.Any <string>(), MessageButtons.OK)).Do(x => {
                var s = x.Args()[0] as string;
                s.Should().Contain("Cannot find");
            });
            ui.Received().ShowMessage(Arg.Any <string>(), MessageButtons.OK);
        }
Beispiel #6
0
        public void Duplicates() {
            var tr = new RegistryMock(SimulateDuplicates());
            var svl = new SupportedRVersionRange(3, 2, 3, 4);

            string dir = @"C:\Program Files\Microsoft\R Client\R_SERVER";
            var fs = Substitute.For<IFileSystem>();
            var fsi = Substitute.For<IFileSystemInfo>();
            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(@"C:\Program Files\Microsoft\R Client\R_SERVER").EnumerateFileSystemInfos().Returns(new IFileSystemInfo[] { fsi });

            var fvi = SimulateFileVersion(3, 22);
            fs.GetVersionInfo(Path.Combine(dir, @"bin\x64", "R.dll")).Returns(fvi);

            PretendRFilesAvailable(fs, dir);
            var ri = new RInstallation(tr, fs);

            var engines = ri.GetCompatibleEngines(svl);
            engines.Should().HaveCount(1);

            var e = engines.First();
            e.Name.Should().Contain("Microsoft R");
            e = new RInterpreterInfo(e.Name, e.InstallPath, fs);
        }
Beispiel #7
0
        public void MissingBinaries() {
            var tr = new RegistryMock(SimulateRegistry02());
            var svl = new SupportedRVersionRange(3, 1, 3, 4);

            string dir = @"C:\Program Files\R\R-3.1.3";
            var fs = Substitute.For<IFileSystem>();
            var fsi = Substitute.For<IFileSystemInfo>();
            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(@"C:\Program Files\R").EnumerateFileSystemInfos().Returns(new IFileSystemInfo[] { fsi });

            var fvi = SimulateFileVersion(3, 13);
            fs.GetVersionInfo(Path.Combine(dir, @"bin\x64", "R.dll")).Returns(fvi);

            PretendRFilesAvailable(fs, dir);
            var ri = new RInstallation(tr, fs);

            var e = ri.GetCompatibleEngines(svl).FirstOrDefault();
            e.Should().NotBeNull();

            e = new RInterpreterInfo(e.Name, e.InstallPath, fs);
            var coreShell = Substitute.For<ICoreShell>();
            fs = Substitute.For<IFileSystem>();
            e.VerifyInstallation(svl, fs, coreShell).Should().BeFalse();

            coreShell.When(x => x.ShowMessage(Arg.Any<string>(), MessageButtons.OK)).Do(x => {
                var s = x.Args()[0] as string;
                s.Should().Contain("Cannot find");
            });
            coreShell.Received().ShowMessage(Arg.Any<string>(), MessageButtons.OK);
        }
Beispiel #8
0
 public void NormalizePath(string path, string expected)
 {
     RInterpreterInfo.NormalizeRPath(path).Should().Be(expected);
 }