Esempio n. 1
0
        public static PackageQueryResult GetUpdates(ContextName context, string nuGetSite, PackageStability stability, IEnumerable <IPackageId> ids)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (nuGetSite == null)
            {
                throw new ArgumentNullException("nuGetSite");
            }
            if (ids == null)
            {
                throw new ArgumentNullException("ids");
            }

            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                var service = new FeedContext_x0060_1(new Uri(nuGetSite));

                var query = service.CreateQuery <V2FeedPackage>("GetUpdates")
                            .AddQueryOption("packageIds", "'" + String.Join("|", ids.Select(p => p.Id)) + "'")
                            .AddQueryOption("versions", "'" + String.Join("|", ids.Select(p => p.Version)) + "'")
                            .AddQueryOption("includePrerelease", (stability == PackageStability.IncludePrerelease) ? "true" : "false")
                            .AddQueryOption("includeAllVersions", "false");

                var response = (QueryOperationResponse <V2FeedPackage>)query.Execute();

                var packageMetadatas = response.Select(p => Deserialize(p, context, contextKey, nuGetSite)).ToArray();

                return(new PackageQueryResult(
                           GetTotalCount(response, packageMetadatas),
                           0,
                           1,
                           packageMetadatas
                           ));
            }
        }
Esempio n. 2
0
        public static PackageMetadata ResolvePackageVersion(ContextName context, string nuGetSite, string packageId, string versionRestriction, PackageStability stability)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (nuGetSite == null)
            {
                throw new ArgumentNullException("nuGetSite");
            }
            if (packageId == null)
            {
                throw new ArgumentNullException("packageId");
            }
            if (versionRestriction == null)
            {
                throw new ArgumentNullException("versionRestriction");
            }

            string installedVersion = PackageManager.GetInstalledVersion(context, packageId);

            if (installedVersion == null)
            {
                // This method is used to resolve dependencies. If we don't
                // have the package installed, we check whether it's a valid
                // package ID at all. If not, the dependency probably is an
                // invalid dependency (or the NetIde.Runtime dependency)
                // and we completely ignore it.

                if (!PackageManager.IsValidPackageId(context, packageId))
                {
                    return(null);
                }

                // We default to 0.0.0.0 for uninstalled packages. This could
                // give issues when the package available in NuGet has
                // version 0.0.0.0. The only way to use this API is to provide
                // a valid version number, so this currently is a limitation,
                // i.e. that you can't have NuGet packages of version 0.0.0.0.

                installedVersion = "0.0.0.0";
            }

            var service = new FeedContext_x0060_1(new Uri(nuGetSite));

            var query = service.CreateQuery <V2FeedPackage>("GetUpdates")
                        .AddQueryOption("packageIds", "'" + packageId + "'")
                        .AddQueryOption("versions", "'" + installedVersion + "'")
                        .AddQueryOption("includePrerelease", (stability == PackageStability.IncludePrerelease) ? "true" : "false")
                        .AddQueryOption("includeAllVersions", "false")
                        .AddQueryOption("versionConstraints", "'" + versionRestriction + "'");

            var response = (QueryOperationResponse <V2FeedPackage>)query.Execute();

            PackageMetadata[] packages;

            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                packages = response.Select(p => Deserialize(p, context, contextKey, nuGetSite)).ToArray();
            }

            Debug.Assert(packages.Length <= 1);

            if (packages.Length > 0)
            {
                return(packages[0]);
            }

            return(null);
        }