Пример #1
0
        private async Task RefreshPackagesAsync()
        {
            IEnumerable <DBPackageView> views;

            try {
                views = DBPackageView.FromModuleList(
                    await _provider.EnumerateAllModules(),
                    await _provider.EnumerateStdLibModules(),
                    _provider.Factory
                    ).ToList();
            } catch (InvalidOperationException) {
                // Configuration is invalid, so don't display any packages
                return;
            }

            if (_packages == null)
            {
                lock (_packagesLock) {
                    _packages = _packages ?? new ObservableCollection <DBPackageView>();
                }
            }

            await Dispatcher.InvokeAsync(() => {
                lock (_packagesLock) {
                    _packages.Merge(
                        views,
                        DBPackageViewComparer.Instance,
                        DBPackageViewComparer.Instance
                        );
                }
            });
        }
Пример #2
0
        public static IEnumerable <DBPackageView> FromModuleList(
            IList <string> modules,
            IList <string> stdLibModules,
            IPythonInterpreterFactoryWithDatabase factory
            )
        {
            var stdLib        = new HashSet <string>(stdLibModules, StringComparer.Ordinal);
            var stdLibPackage = new DBPackageView(Resources.StandardLibraryModuleListItem);

            yield return(stdLibPackage);

#if DEBUG
            var seenPackages = new HashSet <string>(StringComparer.Ordinal);
#endif

            HashSet <string> knownModules            = null;
            bool             areKnownModulesUpToDate = false;
            if (!factory.IsCurrent)
            {
                knownModules            = new HashSet <string>(factory.GetUpToDateModules(), StringComparer.Ordinal);
                areKnownModulesUpToDate = true;
            }
            for (int i = 0; i < modules.Count;)
            {
                if (stdLib.Contains(modules[i]))
                {
                    stdLibPackage._isUpToDate = knownModules == null ||
                                                knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                    stdLibPackage._moduleCount += 1;
                    i += 1;
                    continue;
                }

#if DEBUG
                Debug.Assert(seenPackages.Add(modules[i]));
#endif

                var package = new DBPackageView(modules[i]);
                package._isUpToDate = knownModules == null ||
                                      knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                package._moduleCount = 1;

                var dotName = package._fullname + ".";
                for (++i; i < modules.Count && modules[i].StartsWith(dotName, StringComparison.Ordinal); ++i)
                {
                    package._isUpToDate &= knownModules == null ||
                                           knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                    package._moduleCount += 1;
                }

                yield return(package);
            }
        }
Пример #3
0
        public static IEnumerable <DBPackageView> FromModuleList(
            IList <string> modules,
            IList <string> stdLibModules,
            IPythonInterpreterFactoryWithDatabase factory
            )
        {
            var stdLib        = new HashSet <string>(stdLibModules, StringComparer.Ordinal);
            var stdLibPackage = new DBPackageView("(Standard Library)");

            yield return(stdLibPackage);

#if DEBUG
            var seenPackages = new HashSet <string>(StringComparer.Ordinal);
#endif

            HashSet <string> knownModules            = null;
            bool             areKnownModulesUpToDate = false;
            if (!factory.IsCurrent)
            {
                var factory2 = factory as IPythonInterpreterFactoryWithDatabase2;
                if (factory2 == null)
                {
                    knownModules = new HashSet <string>(Regex.Matches(
                                                            factory.GetIsCurrentReason(CultureInfo.InvariantCulture),
                                                            @"\b[\w\d\.]+\b"
                                                            ).Cast <Match>().Select(m => m.Value),
                                                        StringComparer.Ordinal
                                                        );
                    areKnownModulesUpToDate = false;
                }
                else
                {
                    knownModules            = new HashSet <string>(factory2.GetUpToDateModules(), StringComparer.Ordinal);
                    areKnownModulesUpToDate = true;
                }
            }
            for (int i = 0; i < modules.Count;)
            {
                if (stdLib.Contains(modules[i]))
                {
                    stdLibPackage._isUpToDate = knownModules == null ||
                                                knownModules.Contains(modules[i]) == areKnownModulesUpToDate;;
                    stdLibPackage._moduleCount += 1;
                    i += 1;
                    continue;
                }

#if DEBUG
                Debug.Assert(seenPackages.Add(modules[i]));
#endif

                var package = new DBPackageView(modules[i]);
                package._isUpToDate = knownModules == null ||
                                      knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                package._moduleCount = 1;

                var dotName = package._fullname + ".";
                for (++i; i < modules.Count && modules[i].StartsWith(dotName, StringComparison.Ordinal); ++i)
                {
                    package._isUpToDate &= knownModules == null ||
                                           knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                    package._moduleCount += 1;
                }

                yield return(package);
            }
        }