Ejemplo n.º 1
0
        public void Simulate01() {
            var tr = new RegistryMock(SimulateRegistry01());

            string dir = @"C:\Program Files\MRO\R-3.2.3";
            string dir64 = dir + @"\bin\x64\";
            var fs = Substitute.For<IFileSystem>();
            PretendRFilesAvailable(fs, dir);

            var fvi = Substitute.For<IFileVersionInfo>();
            fvi.FileMajorPart.Returns(3);
            fvi.FileMinorPart.Returns(23);
            fs.GetVersionInfo(dir64 + "R.dll").Returns(fvi);

            var ri = new RInstallation(tr, fs);
            var svl = new SupportedRVersionRange(3, 2, 3, 2);

            var engines = ri.GetCompatibleEngines(svl);
            engines.Should().NotBeEmpty();

            var e = engines.FirstOrDefault();
            e.VerifyInstallation(svl, fs).Should().BeTrue();
            
            e.Version.Major.Should().BeGreaterOrEqualTo(3);
            e.Version.Minor.Should().BeGreaterOrEqualTo(2);
            e.InstallPath.Should().StartWithEquivalent(@"C:\Program Files");
            e.InstallPath.Should().Contain("R-");
            e.Version.Should().Be(new Version(3, 2, 3));
        }
Ejemplo n.º 2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            string latestRPath = Environment.SystemDirectory;

            try {
                latestRPath = new RInstallation().GetCompatibleEnginePathFromRegistry();
                if (string.IsNullOrEmpty(latestRPath) || !Directory.Exists(latestRPath))
                {
                    // Force 64-bit PF
                    latestRPath = Environment.GetEnvironmentVariable("ProgramFiles");
                }
            } catch (ArgumentException) { } catch (IOException) { }

            return(Dialogs.BrowseForDirectory(VsAppShell.Current.GetDialogOwnerWindow(), latestRPath, Resources.ChooseRInstallFolder));
        }
Ejemplo n.º 3
0
        public void RInstallation_Test02()
        {
            // Use actual files and registry
            RInstallation.Registry   = null;
            RInstallation.FileSystem = null;

            RInstallData data = RInstallation.GetInstallationData(null, 3, 2, 3, 2);

            data.Status.Should().Be(RInstallStatus.OK);
            data.Version.Major.Should().BeGreaterOrEqualTo(3);
            data.Version.Minor.Should().BeGreaterOrEqualTo(2);
            string path = Path.Combine(data.Path, @"bin\x64");

            Directory.Exists(path).Should().BeTrue();
        }
Ejemplo n.º 4
0
        private string ValidateRBasePath(string path)
        {
            // If path is null, folder selector dialog was canceled
            if (path != null)
            {
                path = RInstallation.NormalizeRPath(path);
                bool valid = RInstallationHelper.VerifyRIsInstalled(VsAppShell.Current, path, showErrors: !_allowLoadingFromStorage);
                if (!valid)
                {
                    path = null; // Prevents assignment of bad values to the property.
                }
            }

            return(path);
        }
Ejemplo n.º 5
0
        private Dictionary <string, IConnection> CreateConnectionList()
        {
            var connections  = GetConnectionsFromSettings();
            var localEngines = new RInstallation().GetCompatibleEngines().ToList();

            // 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[e.Name] = Connection.Create(_securityService, 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))
            {
                // Installation was removed or otherwise disappeared
                _settings.LastActiveConnection = null;
            }

            if (_settings.LastActiveConnection == null && connections.Any())
            {
                // Perhaps first time launch with R preinstalled.
                var connection = PickBestLocalRConnection(connections.Values, localEngines);
                connection.LastUsed            = DateTime.Now;
                _settings.LastActiveConnection = new ConnectionInfo(connection)
                {
                    LastUsed = DateTime.Now
                };
            }

            return(connections);
        }
Ejemplo n.º 6
0
        private void ReportLocalRConfiguration()
        {
            // Report local R installation
            string rInstallPath = new RInstallation().GetRInstallPath();

            TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RInstallPath, rInstallPath);

            string rClientPath = MicrosoftRClient.GetRClientPath();

            if (rClientPath != null)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RClientFound);
                if (rInstallPath != null && rInstallPath.EqualsIgnoreCase(rClientPath))
                {
                    TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RClientActive);
                }
            }

            var rEngines = GetRSubfolders("R");

            foreach (var s in rEngines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.REngine, s);
            }

            var rroEngines = GetRSubfolders("RRO");

            foreach (var s in rroEngines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RROEngine, s);
            }

            var mroEngines = GetRSubfolders("MRO");

            foreach (var s in mroEngines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.MROEngine, s);
            }

            if (_packageIndex != null)
            {
                foreach (var p in _packageIndex.Packages)
                {
                    TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RPackages, p.Name.GetMD5Hash());
                }
            }
        }
Ejemplo n.º 7
0
        private void ReportLocalRConfiguration()
        {
            // Report local R installations
            var engines = new RInstallation().GetCompatibleEngines();

            foreach (var e in engines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RInstallPath, e.InstallPath);
            }

            string rClientPath = SqlRClientInstallation.GetRClientPath();

            if (rClientPath != null)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RClientFound);
            }

            var rEngines = GetRSubfolders("R");

            foreach (var s in rEngines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.REngine, s);
            }

            var rroEngines = GetRSubfolders("RRO");

            foreach (var s in rroEngines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RROEngine, s);
            }

            var mroEngines = GetRSubfolders("MRO");

            foreach (var s in mroEngines)
            {
                TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.MROEngine, s);
            }

            if (_packageIndex != null)
            {
                foreach (var p in _packageIndex.Packages)
                {
                    TelemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RPackages, new TelemetryPiiProperty(p.Name));
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates R session
        /// </summary>
        /// <param name="name">Session name</param>
        /// <param name="url">Path to local R interpreter (folder with R.dll) or URL to the remote machine</param>
        /// <returns>R session</returns>
        public static IRHostSession Create(string name, string url = null)
        {
            if (string.IsNullOrEmpty(url))
            {
                var engine = new RInstallation().GetCompatibleEngines().FirstOrDefault();
                if (engine == null)
                {
                    throw new InvalidOperationException("No R engines installed");
                }
                url = engine.InstallPath;
            }

            var ci = BrokerConnectionInfo.Create(null, name, url);
            var bc = new LocalBrokerClient(name, ci, new CoreServices(), new NullConsole());

            return(new RHostSession(new RSession(0, name, bc, new NullLock(), () => { })));
        }
Ejemplo n.º 9
0
        public void ActualInstall() {
            // Use actual files and registry
            var svr = new SupportedRVersionRange(3, 2, 3, 9);
            var engine = new RInstallation().GetCompatibleEngines(svr).FirstOrDefault();

            engine.Should().NotBeNull();
            engine.Name.Should().NotBeNullOrEmpty();

            engine.Version.Major.Should().BeGreaterOrEqualTo(3);
            engine.Version.Minor.Should().BeGreaterOrEqualTo(2);

            Directory.Exists(engine.InstallPath).Should().BeTrue();
            Directory.Exists(engine.BinPath).Should().BeTrue();

            string path = Path.Combine(engine.InstallPath, @"bin\x64");
            Directory.Exists(path).Should().BeTrue();
        }
Ejemplo n.º 10
0
        public void ReportConfiguration()
        {
            if (_telemetryService.IsEnabled)
            {
                try {
                    Assembly thisAssembly = Assembly.GetExecutingAssembly();
                    _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RtvsVersion, thisAssembly.GetName().Version.ToString());

                    string rInstallPath = RInstallation.GetRInstallPath(RToolsSettings.Current.RBasePath);
                    _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RInstallPath, rInstallPath);

                    var rEngines = GetRSubfolders("R");
                    foreach (var s in rEngines)
                    {
                        _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.REngine, s);
                    }

                    var rroEngines = GetRSubfolders("RRO");
                    foreach (var s in rroEngines)
                    {
                        _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RROEngine, s);
                    }

                    var mroEngines = GetRSubfolders("MRO");
                    foreach (var s in mroEngines)
                    {
                        _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.MROEngine, s);
                    }

                    var hashes = RPackageData.GetInstalledPackageHashes(RPackageType.Base);
                    foreach (var s in hashes)
                    {
                        _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RBasePackages, s);
                    }

                    hashes = RPackageData.GetInstalledPackageHashes(RPackageType.User);
                    foreach (var s in hashes)
                    {
                        _telemetryService.ReportEvent(TelemetryArea.Configuration, ConfigurationEvents.RUserPackages, s);
                    }
                } catch (Exception ex) {
                    Trace.Fail("Telemetry exception: " + ex.Message);
                }
            }
        }
Ejemplo n.º 11
0
        public void ActualInstall()
        {
            // Use actual files and registry
            var svr    = new SupportedRVersionRange(3, 2, 3, 9);
            var engine = new RInstallation().GetCompatibleEngines(svr).FirstOrDefault();

            engine.Should().NotBeNull();
            engine.Name.Should().NotBeNullOrEmpty();

            engine.Version.Major.Should().BeGreaterOrEqualTo(3);
            engine.Version.Minor.Should().BeGreaterOrEqualTo(2);

            Directory.Exists(engine.InstallPath).Should().BeTrue();
            Directory.Exists(engine.BinPath).Should().BeTrue();

            string path = Path.Combine(engine.InstallPath, @"bin\x64");

            Directory.Exists(path).Should().BeTrue();
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
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;
                }
            }
        }
Ejemplo n.º 14
0
        private IBrokerClient CreateBrokerClient(string name, BrokerConnectionInfo connectionInfo, CancellationToken cancellationToken)
        {
            if (!connectionInfo.IsValid)
            {
                var path = new RInstallation().GetCompatibleEngines().FirstOrDefault()?.InstallPath;
                connectionInfo = BrokerConnectionInfo.Create(_services.Security, connectionInfo.Name, path);
            }

            if (!connectionInfo.IsValid)
            {
                return(null);
            }

            if (connectionInfo.IsRemote)
            {
                return(new RemoteBrokerClient(name, connectionInfo, _services, _console, cancellationToken));
            }

            return(new LocalBrokerClient(name, connectionInfo, _services, _console));
        }
Ejemplo n.º 15
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IVsUIShell uiShell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell));
            IntPtr     dialogOwner;

            uiShell.GetDialogOwnerHwnd(out dialogOwner);

            string latestRPath = Environment.SystemDirectory;

            try {
                latestRPath = RInstallation.GetCompatibleEnginePathFromRegistry();
                if (string.IsNullOrEmpty(latestRPath) || !Directory.Exists(latestRPath))
                {
                    // Force 64-bit PF
                    latestRPath = Environment.GetEnvironmentVariable("ProgramFiles");
                }
            } catch (ArgumentException) { } catch (IOException) { }

            return(Dialogs.BrowseForDirectory(dialogOwner, latestRPath, Resources.ChooseRInstallFolder));
        }
Ejemplo n.º 16
0
        public void MsRClient()
        {
            var rClientInstallPath = @"C:\Program Files\Microsoft\R Client\";
            var rClientRPath       = @"C:\Program Files\Microsoft\R Client\R_SERVER\";
            var tr = new RegistryMock(SimulateRegistryMsRClient(rClientInstallPath, rClientRPath));

            RInstallation.Registry = tr;

            RInstallation.GetRClientPath().Should().Be(rClientRPath);

            var shell = Substitute.For <ICoreShell>();

            shell.ShowMessage(Arg.Any <string>(), Arg.Any <MessageButtons>()).Returns(MessageButtons.Yes);

            RInstallation.GetRInstallPath(null, null, shell).Should().Be(rClientRPath);
            shell.Received(1).ShowMessage(Arg.Any <string>(), Arg.Any <MessageButtons>());

            RInstallation.GetRInstallPath(null, null, shell).Should().Be(rClientRPath);
            shell.Received(1).ShowMessage(Arg.Any <string>(), Arg.Any <MessageButtons>());
        }
Ejemplo n.º 17
0
        public void Test05()
        {
            var tr = new RegistryMock(SimulateRegistry04());

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

            PretendRFilesAvailable(fs, dir);

            var fvi = Substitute.For <IFileVersionInfo>();

            fvi.FileMajorPart.Returns(3);
            fvi.FileMinorPart.Returns(13);
            fs.GetVersionInfo(dir + "R.dll").Returns(fvi);

            var          ri   = new RInstallation(tr, fs);
            var          svl  = new SupportedRVersionRange(3, 2, 3, 2);
            RInstallData data = ri.GetInstallationData(dir, svl);

            data.Status.Should().Be(RInstallStatus.UnsupportedVersion);
        }
Ejemplo n.º 18
0
        public void IncompatibleVerson01()
        {
            var tr  = new RegistryMock(SimulateRegistry02());
            var svl = new SupportedRVersionRange(3, 2, 3, 9);
            var fs  = Substitute.For <IFileSystem>();
            var ri  = new RInstallation(tr, fs);

            ri.GetCompatibleEngines(svl).Should().BeEmpty();

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

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

            ri = new RInstallation(tr, fs);
            var engines = ri.GetCompatibleEngines(svl);

            engines.Should().BeEmpty();
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public void IncompatibleVersonInPF()
        {
            var tr  = new RegistryMock(SimulateRegistry02());
            var svl = new SupportedRVersionRange(3, 1, 3, 9);

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

            fs.DirectoryExists(root).Returns(true);
            fs.DirectoryExists(dir).Returns(true);

            var fsi = Substitute.For <IFileSystemInfo>();

            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(root).EnumerateFileSystemInfos().Returns(new IFileSystemInfo[] { fsi });

            var ri      = new RInstallation(tr, fs);
            var engines = ri.GetCompatibleEngines(svl);

            engines.Should().BeEmpty();
        }
Ejemplo n.º 21
0
        private static string GetInstallPath()
        {
            string rInstallPath = RInstallation.GetRInstallPath(RToolsSettings.Current != null ? RToolsSettings.Current.RBasePath : null);

            return(rInstallPath != null?Path.Combine(rInstallPath, "library") : null);
        }
Ejemplo n.º 22
0
        public void IncompatibleVersonInPF() {
            var tr = new RegistryMock(SimulateRegistry02());
            var svl = new SupportedRVersionRange(3, 1, 3, 9);

            var root = @"C:\Program Files\R";
            string dir = Path.Combine(root, "R-3.1.3");
            var fs = Substitute.For<IFileSystem>();
            fs.DirectoryExists(root).Returns(true);
            fs.DirectoryExists(dir).Returns(true);

            var fsi = Substitute.For<IFileSystemInfo>();
            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(root).EnumerateFileSystemInfos().Returns(new IFileSystemInfo[] { fsi });

            var ri = new RInstallation(tr, fs);
            var engines = ri.GetCompatibleEngines(svl);
            engines.Should().BeEmpty();
        }
Ejemplo n.º 23
0
        public void RInstallation_Test01()
        {
            RInstallData data = RInstallation.GetInstallationData(null, 0, 0, 0, 0);

            data.Status.Should().BeEither(RInstallStatus.PathNotSpecified, RInstallStatus.UnsupportedVersion);
        }
Ejemplo n.º 24
0
 public void NormalizePath(string path, string expected)
 {
     RInstallation.NormalizeRPath(path).Should().Be(expected);
 }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        public static void WriteGeneralData(TextWriter writer, bool detailed)
        {
            try {
                writer.WriteLine("OS Information");
                writer.WriteLine("    Version:       " + Environment.OSVersion);
                if (detailed)
                {
                    writer.WriteLine("    CPU Count:     " + Environment.ProcessorCount);
                    writer.WriteLine("    64 bit:        " + Environment.Is64BitOperatingSystem);
                    writer.WriteLine("    System Folder: " + Environment.SystemDirectory);
                    writer.WriteLine("    Working set:   " + Environment.WorkingSet);
                }
                writer.WriteLine();

                Assembly thisAssembly = Assembly.GetExecutingAssembly();
                writer.WriteLine("RTVS Information:");
                writer.WriteLine("    Assembly: " + thisAssembly.FullName);
                if (detailed)
                {
                    writer.WriteLine("    Codebase: " + thisAssembly.CodeBase);
                }
                writer.WriteLine();

                var ri       = new RInstallation();
                var workflow = VsAppShell.Current.GlobalServices.GetService <IRInteractiveWorkflowProvider>().GetOrCreate();
                if (detailed)
                {
                    var rEngines = ri.GetCompatibleEngines();
                    writer.WriteLine("Installed R Engines (from registry):");
                    foreach (var e in rEngines)
                    {
                        writer.WriteLine(Invariant($"{e.Name} {e.Version} {e.InstallPath}"));
                    }
                    writer.WriteLine();

                    var connections = workflow.Connections.RecentConnections;
                    writer.WriteLine("Installed R Engines (from registry):");
                    foreach (var connection in connections)
                    {
                        writer.WriteLine(Invariant($"    {connection.Name}: {connection.Path}"));
                    }
                    writer.WriteLine();
                }

                var activeConnection = workflow.Connections.ActiveConnection;
                if (activeConnection != null)
                {
                    writer.WriteLine("Active R URI:");
                    writer.WriteLine(Invariant($"    {activeConnection.Name}: {activeConnection.Path}"));
                    writer.WriteLine();
                }

                if (detailed)
                {
                    writer.WriteLine("Assemblies loaded by Visual Studio:");

                    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(assem => assem.FullName))
                    {
                        var assemFileVersion = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false).OfType <AssemblyFileVersionAttribute>().FirstOrDefault();

                        writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "    {0}, FileVersion={1}",
                                                       assembly.FullName,
                                                       assemFileVersion == null ? "(null)" : assemFileVersion.Version
                                                       ));
                    }
                }
            } catch (Exception ex) {
                writer.WriteLine("  Failed to access system data.");
                writer.WriteLine(ex.ToString());
                writer.WriteLine();
            } finally {
                writer.Flush();
            }
        }
Ejemplo n.º 28
0
        public void IncompatibleVerson01() {
            var tr = new RegistryMock(SimulateRegistry02());
            var svl = new SupportedRVersionRange(3, 2, 3, 9);
            var fs = Substitute.For<IFileSystem>();
            var ri = new RInstallation(tr, fs);

            ri.GetCompatibleEngines(svl).Should().BeEmpty();

            string dir = @"C:\Program Files\RRO\R-3.1.3";
            var fsi = Substitute.For<IFileSystemInfo>();
            fsi.Attributes.Returns(FileAttributes.Directory);
            fsi.FullName.Returns(dir);
            fs.GetDirectoryInfo(@"C:\Program Files\RRO").EnumerateFileSystemInfos().Returns(new[] { fsi });
            
            ri = new RInstallation(tr, fs);
            var engines = ri.GetCompatibleEngines(svl);
            engines.Should().BeEmpty();
        }
Ejemplo n.º 29
0
        public static void WriteGeneralData(TextWriter writer, bool detailed)
        {
            try {
                writer.WriteLine("OS Information");
                writer.WriteLine("    Version:       " + Environment.OSVersion.ToString());
                if (detailed)
                {
                    writer.WriteLine("    CPU Count:     " + Environment.ProcessorCount);
                    writer.WriteLine("    64 bit:        " + Environment.Is64BitOperatingSystem);
                    writer.WriteLine("    System Folder: " + Environment.SystemDirectory);
                    writer.WriteLine("    Working set:   " + Environment.WorkingSet);
                }
                writer.WriteLine();

                Assembly thisAssembly = Assembly.GetExecutingAssembly();
                writer.WriteLine("RTVS Information:");
                writer.WriteLine("    Assembly: " + thisAssembly.FullName);
                if (detailed)
                {
                    writer.WriteLine("    Codebase: " + thisAssembly.CodeBase);
                }
                writer.WriteLine();

                if (detailed)
                {
                    IEnumerable <string> rEngines = RInstallation.GetInstalledEngineVersionsFromRegistry();
                    writer.WriteLine("Installed R Engines (from registry):");
                    foreach (string e in rEngines)
                    {
                        writer.WriteLine("    " + e);
                    }
                    writer.WriteLine();

                    string latestEngine = RInstallation.GetCompatibleEnginePathFromRegistry();
                    writer.WriteLine("Latest R Engine (from registry):");
                    writer.WriteLine("    " + latestEngine);
                    writer.WriteLine();
                }

                string rInstallPath = RInstallation.GetRInstallPath(RToolsSettings.Current.RBasePath);
                writer.WriteLine("R Install path:");
                writer.WriteLine("    " + rInstallPath);
                writer.WriteLine();

                if (detailed)
                {
                    writer.WriteLine("Assemblies loaded by Visual Studio:");

                    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(assem => assem.FullName))
                    {
                        var assemFileVersion = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false).OfType <AssemblyFileVersionAttribute>().FirstOrDefault();

                        writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "    {0}, FileVersion={1}",
                                                       assembly.FullName,
                                                       assemFileVersion == null ? "(null)" : assemFileVersion.Version
                                                       ));
                    }
                }
            } catch (System.Exception ex) {
                writer.WriteLine("  Failed to access system data.");
                writer.WriteLine(ex.ToString());
                writer.WriteLine();
            } finally {
                writer.Flush();
            }
        }