Ejemplo n.º 1
0
        private static IPackageMetadataProvider CreatePackageMetadataProvider(PackageLoadContext context)
        {
            var logger = new VisualStudioActivityLogger();

            return(new MultiSourcePackageMetadataProvider(
                       context.SourceRepositories,
                       context.PackageManager?.PackagesFolderSourceRepository,
                       context.PackageManager?.GlobalPackageFolderRepositories,
                       logger));
        }
        private static async Task <IPackageFeed> CreatePackageFeedAsync(PackageLoadContext context, ItemFilter filter, INuGetUILogger uiLogger)
        {
            // Go off the UI thread to perform non-UI operations
            await TaskScheduler.Default;

            var logger = new VisualStudioActivityLogger();

            if (filter == ItemFilter.All)
            {
                return(new MultiSourcePackageFeed(context.SourceRepositories, uiLogger));
            }

            var metadataProvider  = CreatePackageMetadataProvider(context);
            var installedPackages = await context.GetInstalledPackagesAsync();

            if (filter == ItemFilter.Installed)
            {
                return(new InstalledPackageFeed(installedPackages, metadataProvider, logger));
            }

            if (filter == ItemFilter.Consolidate)
            {
                return(new ConsolidatePackageFeed(installedPackages, metadataProvider, logger));
            }

            // Search all / updates available cannot work without a source repo
            if (context.SourceRepositories == null)
            {
                return(null);
            }

            if (filter == ItemFilter.UpdatesAvailable)
            {
                return(new UpdatePackageFeed(
                           installedPackages,
                           metadataProvider,
                           context.Projects,
                           context.CachedPackages,
                           logger));
            }

            throw new InvalidOperationException("Unsupported feed type");
        }