コード例 #1
0
ファイル: InterpretersNode.cs プロジェクト: wenh123/PTVS
        private async Task CheckPackagesAsync() {
            var uiThread = ProjectMgr.Site.GetUIThread();
            uiThread.MustBeCalledFromUIThreadOrThrow();

            bool prevChecked = _checkedItems;
            // Use _checkingItems to prevent the expanded state from
            // disappearing too quickly.
            _checkingItems = true;
            _checkedItems = true;
            if (!Directory.Exists(_factory.Configuration.LibraryPath)) {
                _checkingItems = false;
                ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Expandable, 0);
                return;
            }

            HashSet<string> lines;
            bool anyChanges = false;
            try {
                lines = await Pip.List(_factory).ConfigureAwait(true);
            } catch (MissingInterpreterException) {
                return;
            } catch (NoInterpretersException) {
                return;
            } catch (FileNotFoundException) {
                return;
            }

            // Ensure we are back on the UI thread
            uiThread.MustBeCalledFromUIThread();

            if (ProjectMgr == null || ProjectMgr.IsClosed) {
                return;
            }

            var existing = AllChildren.ToDictionary(c => c.Url);

            // remove the nodes which were uninstalled.
            foreach (var keyValue in existing) {
                if (!lines.Contains(keyValue.Key)) {
                    RemoveChild(keyValue.Value);
                    anyChanges = true;
                }
            }

            // remove already existing nodes so we don't add them a 2nd time
            lines.ExceptWith(existing.Keys);

            // add the new nodes
            foreach (var line in lines) {
                AddChild(new InterpretersPackageNode(ProjectMgr, line));
                anyChanges = true;

                var packageInfo = PythonProjectNode.FindRequirementRegex.Match(line.ToLower());
                if (packageInfo.Groups["name"].Success) {
                    //Log the details of the Installation
                    var packageDetails = new Logging.PackageInstallDetails(
                        packageInfo.Groups["name"].Value,
                        packageInfo.Groups["ver"].Success ? packageInfo.Groups["ver"].Value : String.Empty,
                        _factory.GetType().Name,
                        _factory.Configuration.Version.ToString(),
                        _factory.Configuration.Architecture.ToString(),
                        "Existing", //Installer if we tracked it
                        false, //Installer was not run elevated
                        0); //The installation already existed
                    ProjectMgr.Site.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.PackageInstalled, packageDetails);
                }
            }
            _checkingItems = false;

            ProjectMgr.OnInvalidateItems(this);
            if (!prevChecked) {
                if (anyChanges) {
                    ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Expandable, 0);
                }
                if (ProjectMgr.ParentHierarchy != null) {
                    ExpandItem(EXPANDFLAGS.EXPF_CollapseFolder);
                }
            }

            if (prevChecked && anyChanges) {
                var withDb = _factory as IPythonInterpreterFactoryWithDatabase;
                if (withDb != null) {
                    withDb.GenerateDatabase(GenerateDatabaseOptions.SkipUnchanged);
                }
            }
        }
コード例 #2
0
        private async Task CheckPackagesAsync()
        {
            var uiThread = ProjectMgr.Site.GetUIThread();

            uiThread.MustBeCalledFromUIThreadOrThrow();

            bool prevChecked = _checkedItems;

            // Use _checkingItems to prevent the expanded state from
            // disappearing too quickly.
            _checkingItems = true;
            _checkedItems  = true;
            if (!Directory.Exists(_factory.Configuration.LibraryPath))
            {
                _checkingItems = false;
                ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Expandable, 0);
                return;
            }

            HashSet <string> lines;
            bool             anyChanges = false;

            try {
                lines = await Pip.List(_factory).ConfigureAwait(true);
            } catch (NoInterpretersException) {
                return;
            }

            // Ensure we are back on the UI thread
            uiThread.MustBeCalledFromUIThread();

            if (ProjectMgr == null || ProjectMgr.IsClosed)
            {
                return;
            }

            var existing = AllChildren.ToDictionary(c => c.Url);

            // remove the nodes which were uninstalled.
            foreach (var keyValue in existing)
            {
                if (!lines.Contains(keyValue.Key))
                {
                    RemoveChild(keyValue.Value);
                    anyChanges = true;
                }
            }

            // remove already existing nodes so we don't add them a 2nd time
            lines.ExceptWith(existing.Keys);

            // add the new nodes
            foreach (var line in lines)
            {
                AddChild(new InterpretersPackageNode(ProjectMgr, line));
                anyChanges = true;

                var packageInfo = PythonProjectNode.FindRequirementRegex.Match(line.ToLower());
                if (packageInfo.Groups["name"].Success)
                {
                    //Log the details of the Installation
                    var packageDetails = new Logging.PackageInstallDetails(
                        packageInfo.Groups["name"].Value,
                        packageInfo.Groups["ver"].Success ? packageInfo.Groups["ver"].Value : String.Empty,
                        _factory.GetType().Name,
                        _factory.Configuration.Version.ToString(),
                        _factory.Configuration.Architecture.ToString(),
                        "Existing", //Installer if we tracked it
                        false,      //Installer was not run elevated
                        0);         //The installation already existed
                    ProjectMgr.Site.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.PackageInstalled, packageDetails);
                }
            }
            _checkingItems = false;

            ProjectMgr.OnInvalidateItems(this);
            if (!prevChecked)
            {
                if (anyChanges)
                {
                    ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Expandable, 0);
                }
                if (ProjectMgr.ParentHierarchy != null)
                {
                    ExpandItem(EXPANDFLAGS.EXPF_CollapseFolder);
                }
            }

            if (prevChecked && anyChanges)
            {
                var withDb = _factory as IPythonInterpreterFactoryWithDatabase;
                if (withDb != null)
                {
                    withDb.GenerateDatabase(GenerateDatabaseOptions.SkipUnchanged);
                }
            }
        }