Exemple #1
0
        /// <summary>
        /// Returns a new database loaded from the specified path. If null is
        /// returned, <see cref="GetCurrentDatabase"/> will assume the default
        /// completion DB is intended.
        /// </summary>
        /// <remarks>
        /// This is intended for overriding in derived classes. To get a
        /// queryable database instance, use <see cref="GetCurrentDatabase"/> or
        /// <see cref="CreateInterpreter"/>.
        /// </remarks>
        public virtual PythonTypeDatabase MakeTypeDatabase(string databasePath, bool includeSitePackages = true)
        {
            if (!_generating && PythonTypeDatabase.IsDatabaseVersionCurrent(databasePath))
            {
                var paths = new List <string>();
                paths.Add(databasePath);
                if (includeSitePackages)
                {
                    paths.AddRange(Directory.EnumerateDirectories(databasePath));
                }

                try {
                    return(new PythonTypeDatabase(this, paths));
                } catch (IOException) {
                } catch (UnauthorizedAccessException) {
                }
            }

            return(PythonTypeDatabase.CreateDefaultTypeDatabase(this));
        }
Exemple #2
0
        /// <summary>
        /// Called to manually trigger a refresh of <see cref="IsCurrent"/>.
        /// After completion, <see cref="IsCurrentChanged"/> will always be
        /// raised, regardless of whether the values were changed.
        /// </summary>
        public virtual void RefreshIsCurrent()
        {
            lock (_isCurrentLock) {
                try {
                    _isCheckingDatabase = true;
                    OnIsCurrentChanged();

                    _generating     = PythonTypeDatabase.IsDatabaseRegenerating(DatabasePath);
                    WatchingLibrary = !_generating;

                    if (_generating)
                    {
                        // Skip the rest of the checks, because we know we're
                        // not current.
                    }
                    else if (!PythonTypeDatabase.IsDatabaseVersionCurrent(DatabasePath))
                    {
                        _isValid            = false;
                        _missingModules     = null;
                        _isCurrentException = null;
                    }
                    else
                    {
                        _isValid = true;
                        HashSet <string> existingDatabase = null;
                        string[]         missingModules   = null;

                        for (int retries = 3; retries > 0; --retries)
                        {
                            try {
                                existingDatabase = GetExistingDatabase(DatabasePath);
                                break;
                            } catch (UnauthorizedAccessException) {
                            } catch (IOException) {
                            }
                            Thread.Sleep(100);
                        }

                        if (existingDatabase == null)
                        {
                            // This will either succeed or throw again. If it throws
                            // then the error is reported to the user.
                            existingDatabase = GetExistingDatabase(DatabasePath);
                        }

                        for (int retries = 3; retries > 0; --retries)
                        {
                            try {
                                missingModules = GetMissingModules(existingDatabase);
                                break;
                            } catch (UnauthorizedAccessException) {
                            } catch (IOException) {
                            }
                            Thread.Sleep(100);
                        }

                        if (missingModules == null)
                        {
                            // This will either succeed or throw again. If it throws
                            // then the error is reported to the user.
                            missingModules = GetMissingModules(existingDatabase);
                        }

                        if (missingModules.Length > 0)
                        {
                            var oldModules = _missingModules;
                            if (oldModules == null ||
                                oldModules.Length != missingModules.Length ||
                                !oldModules.SequenceEqual(missingModules))
                            {
                            }
                            _missingModules = missingModules;
                        }
                        else
                        {
                            _missingModules = null;
                        }
                    }
                    _isCurrentException = null;
                } catch (Exception ex) {
                    // Report the exception text as the reason.
                    _isCurrentException = ex.ToString();
                    _missingModules     = null;
                } finally {
                    _isCheckingDatabase = false;
                }
            }

            OnIsCurrentChanged();
        }