Ejemplo n.º 1
0
        /// <summary>
        /// Add the specified package to the list.
        /// </summary>
        private void AddRecentPackage(RecentPackage package, bool replaceExistingItem)
        {
            if (_packagesCache.Contains(package))
            {
                if (replaceExistingItem)
                {
                    _packagesCache.Remove(package);
                }
                else
                {
                    return;
                }
            }

            _packagesCache.Add(package);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add the specified package to the list.
        /// </summary>
        private void AddRecentPackage(RecentPackage package, bool updateOnly = false)
        {
            var index = _packagesCache.FindIndex(p => p.Id == package.Id);

            if (index != -1)
            {
                var cachedPackage = _packagesCache[index];
                if (package.Version > cachedPackage.Version)
                {
                    _packagesCache[index] = package;
                }
                _packagesCache[index].LastUsedDate = (package.LastUsedDate > cachedPackage.LastUsedDate) ?
                                                     package.LastUsedDate : cachedPackage.LastUsedDate;
            }
            else if (!updateOnly)
            {
                _packagesCache.Add(package);
            }
        }
Ejemplo n.º 3
0
        private void LoadPackagesFromSettingsStore(IPackageRepository repository)
        {
            // get the metadata of recent packages from registry
            IEnumerable <IPersistencePackageMetadata> packagesMetadata = LoadPackageMetadataFromSettingsStore();

            if (!packagesMetadata.Any())
            {
                return;
            }

            // look up the package metadata in the machine cache first before searching the aggregate repository

            // this will contain the package metadata that are not found in the machine cache
            var remainingMetadata = new List <IPersistencePackageMetadata>();

            foreach (var metadata in packagesMetadata)
            {
                var cachedPackage = _cacheRepository.FindPackage(metadata.Id, metadata.Version);
                if (cachedPackage != null)
                {
                    // found a package with the same Id and Version, use it
                    RecentPackage package = ConvertToRecentPackage(cachedPackage, metadata.LastUsedDate);
                    AddRecentPackage(package);
                }
                else
                {
                    // if not, put it in the remaining queue to be searched from aggregate repository
                    remainingMetadata.Add(metadata);
                }
            }

            // for the remaining metadata, find packages from the Aggregate repository based on Id only
            IEnumerable <IPackage> newPackages = repository.FindPackages(remainingMetadata.Select(p => p.Id));

            // newPackages contains all versions of a package Id. Filter out the versions that we don't care.
            IEnumerable <RecentPackage> filteredPackages = FilterPackages(remainingMetadata, newPackages);

            foreach (var package in filteredPackages)
            {
                AddRecentPackage(package);
            }
        }