Ejemplo n.º 1
0
        private void ProcessPackages(string source, PackageFetchOption fetchOptions, IEnumerable <NuGetPackage> package)
        {
            var packageToData = package
                                .GroupBy(x => x.Id, Id, PACKAGE_ID_COMPARER)
                                .ToDictionary(x => x.Key, Id, PACKAGE_ID_COMPARER);

            if (packageToData.Count == 0)
            {
                return;
            }
            var count = 0;

            foreach (var p in GetAllPackages(source, fetchOptions, packageToData.Keys))
            {
                count++;
                IGrouping <string, NuGetPackage> res;
                if (!packageToData.TryGetValue(p.Id, out res))
                {
                    continue;
                }

                foreach (var r in res)
                {
                    if (!r.VersionChecker(p))
                    {
                        continue;
                    }
                    r.AddEntry(new NuGetPackageEntry {
                        Version = p.VersionString()
                    });
                }
            }

            System.Console.Out.WriteLine("Scanned {0} packages for feed {1}", count, source);
        }
Ejemplo n.º 2
0
        public static Expression GenerateQuery(PackageFetchOption fetchOption, IEnumerable <string> ids, ParameterExpression param)
        {
            var idFilter = GeneratePackageIdFilter(ids, param);

            switch (fetchOption)
            {
            case PackageFetchOption.IncludeAll:
                return(idFilter);

            case PackageFetchOption.IncludeLatest:
            {
                var pi = typeof(IPackage).GetProperty("IsLatestVersion");
                if (pi == null)
                {
                    goto case PackageFetchOption.IncludeAll;
                }
                return(Expression.And(Expression.Property(param, pi), idFilter));
            }

            case PackageFetchOption.IncludeLatestAndPrerelease:
            {
                var pi = typeof(IPackage).GetProperty("IsAbsoluteLatestVersion");
                if (pi == null)
                {
                    goto case PackageFetchOption.IncludeAll;
                }
                return(Expression.And(Expression.Property(param, pi), idFilter));
            }

            default:
                throw new Exception("Unexpected PackageFetchOption: " + fetchOption);
            }
        }
Ejemplo n.º 3
0
        protected IEnumerable <IPackage> GetAllPackages(string source, PackageFetchOption fetchOption, IEnumerable <string> ids)
        {
            Uri uri;

            try
            {
                uri = new Uri(source);
            }
            catch (Exception e)
            {
                throw new InvalidFeedUrlException(source, e.Message);
            }

            if (uri.IsFile && !Directory.Exists(uri.LocalPath))
            {
                throw new InvalidFeedUrlException(source, "Local path does not exist");
            }

            System.Console.Out.WriteLine("Checking packages on source: {0}", source);
            var items = GetPackageRepository(source).GetPackages();

            var        param  = Expression.Parameter(typeof(IPackage));
            Expression filter = QueryBuilder.GenerateQuery(fetchOption, ids, param);

            return(items.Where(Expression.Lambda <Func <IPackage, bool> >(filter, param)));
        }
Ejemplo n.º 4
0
        protected IEnumerable <IPackage> GetAllPackages(string source, PackageFetchOption fetchOption, IEnumerable <string> ids)
        {
            var items = GetPackageRepository(source).GetPackages();

            var        param  = Expression.Parameter(typeof(IPackage));
            Expression filter = QueryBuilder.GenerateQuery(fetchOption, ids, param);

            return(items.Where(Expression.Lambda <Func <IPackage, bool> >(filter, param)));
        }
        /// <exception cref="InvalidFeedUrlException">may be thrown on error</exception>
        protected void GetAllPackages(INuGetSource feed,
                                      PackageFetchOption fetchOption,
                                      IEnumerable <string> ids,
                                      Action <IPackage> processor)
        {
            System.Console.Out.WriteLine("Checking packages on source: {0}", feed);

            ValidateSourceUrl(feed);


            var repo = RepositoryFactoryTC.CreateRepository(feed.Source);

            var        param  = Expression.Parameter(typeof(IPackage));
            Expression filter = QueryBuilder.GenerateQuery(fetchOption, ids, param);

            var filtered = repo.GetPackages().Where(Expression.Lambda <Func <IPackage, bool> >(filter, param));

            foreach (var package in filtered)
            {
                processor(package);
            }
        }