Exemple #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
                );
            }
        }
Exemple #2
0
        public PackageInstaller(ContextName context, string packagePath)
            : base(context)
        {
            if (packagePath == null)
                throw new ArgumentNullException("packagePath");

            _packagePath = packagePath;
        }
Exemple #3
0
        public PackageUninstaller(ContextName context, string packageId)
            : base(context)
        {
            if (packageId == null)
                throw new ArgumentNullException("packageId");

            _packageId = packageId;
        }
Exemple #4
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;
        }
Exemple #5
0
        protected PackageManager(ContextName context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            Context = context;

            if (Context.Name.IndexOfAny(new[] { '/', '\\' }) != -1)
                throw new PackageInstallationException(Labels.ContextNameInvalid, 1);
        }
        public PackageRuntimeInstaller(ContextName context, string packagePath, bool inPlace)
            : base(context)
        {
            if (packagePath == null)
                throw new ArgumentNullException("packagePath");
            if (context == null)
                throw new ArgumentNullException("context");

            _packagePath = packagePath;
            _inPlace = inPlace;
        }
Exemple #7
0
        public static RegistryKey OpenRegistryRoot(bool writable, ContextName context)
        {
            string contextKey = RegistryRootKey + "\\" + context.Name;

            if (context.Experimental)
                contextKey += "$Exp";

            if (writable)
                return Registry.CurrentUser.CreateSubKey(contextKey);
            else
                return Registry.CurrentUser.OpenSubKey(contextKey);
        }
        public NiRegistrationContext(ContextName context, string packageId, string fileSystemRoot)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (packageId == null)
                throw new ArgumentNullException("packageId");
            if (fileSystemRoot == null)
                throw new ArgumentNullException("fileSystemRoot");

            PackageId = packageId;
            FileSystemRoot = fileSystemRoot;
            RegistryRoot = context;
        }
Exemple #9
0
        public static void EnablePackage(ContextName context, string packageId, bool enabled)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (packageId == null)
                throw new ArgumentNullException("packageId");

            using (var contextKey = OpenRegistryRoot(true, context))
            using (var key = contextKey.CreateSubKey("InstalledProducts\\" + packageId))
            {
                if (enabled)
                    key.DeleteValue("Disabled");
                else
                    key.SetValue("Disabled", 1);
            }
        }
Exemple #10
0
        public Configuration()
        {
            string basePath = Path.GetDirectoryName(GetType().Assembly.Location);

            string licenseFileName = Path.Combine(basePath, "license.txt");

            if (File.Exists(licenseFileName))
                License = licenseFileName;

            string fileName = Path.Combine(basePath, "config.ini");

            foreach (string line in File.ReadAllLines(fileName))
            {
                string trimmed = line.Trim();

                if (trimmed.Length == 0 || trimmed[0] == '#')
                    continue;

                string[] parts = trimmed.Split(new[] { '=' }, 2);

                if (parts.Length == 2)
                {
                    switch (parts[0])
                    {
                        case "Context": Context = new ContextName(parts[1]); break;
                        case "Title": Title = parts[1]; break;
                        case "NuGetWebsite": NuGetWebsite = parts[1]; break;
                        case "Packages": Packages = new ReadOnlyCollection<string>(parts[1].Split(';')); break;
                        case "StartMenu": StartMenu = parts[1]; break;
                    }
                }
            }

            if (
                Context == null ||
                Title == null ||
                NuGetWebsite == null ||
                Packages == null || Packages.Count == 0
            )
                throw new InvalidOperationException("Invalid configuration");

            using (var key = PackageRegistry.OpenRegistryRoot(false, Context))
            {
                if (key != null)
                    InstallationPath = (string)key.GetValue("InstallationPath");
            }
        }
Exemple #11
0
        public static PackageQueryResult GetInstalledPackages(ContextName context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var packages = new List <PackageMetadata>();

            using (var contextKey = OpenRegistryRoot(false, context))
            {
                string packagesPath = Path.Combine(
                    (string)contextKey.GetValue("InstallationPath"),
                    "Packages"
                    );

                using (var key = contextKey.OpenSubKey("InstalledProducts"))
                {
                    foreach (var packageId in key.GetSubKeyNames())
                    {
                        using (var packageKey = key.OpenSubKey(packageId))
                        {
                            string packagePath = Path.Combine(
                                packagesPath,
                                packageId
                                );

                            var state = GetPackageState(contextKey, context, packageId);

                            if (state.HasFlag(PackageState.Installed))
                            {
                                packages.Add(LoadPackage(packagePath, packageKey, state));
                            }
                        }
                    }
                }
            }

            return(new PackageQueryResult(packages.Count, 0, 1, packages));
        }
Exemple #12
0
        public static string GetInstalledVersion(ContextName context, string packageId)
        {
            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                if (contextKey != null)
                {
                    using (var packageKey = contextKey.OpenSubKey("InstalledProducts\\" + packageId))
                    {
                        // 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 (packageKey != null)
                            return (string)packageKey.GetValue("Version");
                    }
                }
            }

            return null;
        }
Exemple #13
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
                           ));
            }
        }
Exemple #14
0
        public static string GetInstalledVersion(ContextName context, string packageId)
        {
            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                if (contextKey != null)
                {
                    using (var packageKey = contextKey.OpenSubKey("InstalledProducts\\" + packageId))
                    {
                        // 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 (packageKey != null)
                        {
                            return((string)packageKey.GetValue("Version"));
                        }
                    }
                }
            }

            return(null);
        }
Exemple #15
0
        public static void EnablePackage(ContextName context, string packageId, bool enabled)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (packageId == null)
            {
                throw new ArgumentNullException("packageId");
            }

            using (var contextKey = OpenRegistryRoot(true, context))
                using (var key = contextKey.CreateSubKey("InstalledProducts\\" + packageId))
                {
                    if (enabled)
                    {
                        key.DeleteValue("Disabled");
                    }
                    else
                    {
                        key.SetValue("Disabled", 1);
                    }
                }
        }
Exemple #16
0
        public static PackageQueryResult GetInstalledPackages(ContextName context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var packages = new List<PackageMetadata>();

            using (var contextKey = OpenRegistryRoot(false, context))
            {
                string packagesPath = Path.Combine(
                    (string)contextKey.GetValue("InstallationPath"),
                    "Packages"
                );

                using (var key = contextKey.OpenSubKey("InstalledProducts"))
                {
                    foreach (var packageId in key.GetSubKeyNames())
                    {
                        using (var packageKey = key.OpenSubKey(packageId))
                        {
                            string packagePath = Path.Combine(
                                packagesPath,
                                packageId
                            );

                            var state = GetPackageState(contextKey, context, packageId);

                            if (state.HasFlag(PackageState.Installed))
                                packages.Add(LoadPackage(packagePath, packageKey, state));
                        }
                    }
                }
            }

            return new PackageQueryResult(packages.Count, 0, 1, packages);
        }
Exemple #17
0
        public static void QueueUpdate(ContextName context, PackageMetadata metadata)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (metadata == null)
                throw new ArgumentNullException("metadata");

            using (var contextKey = OpenRegistryRoot(true, context))
            using (var packageKey = contextKey.CreateSubKey("InstalledProducts\\" + metadata.Id))
            {
                packageKey.SetValue("NuGetSite", metadata.NuGetSite);
                packageKey.SetValue("GalleryDetailsUrl", metadata.GalleryDetailsUrl);
                packageKey.SetValue("PendingVersion", metadata.Version);
            }
        }
Exemple #18
0
 public static PackageQueryResult Query(ContextName context, string nuGetSite, PackageStability stability, PackageQueryOrder queryOrder, int page)
 {
     return Query(context, nuGetSite, null, stability, queryOrder, page);
 }
Exemple #19
0
        public static void QueueUninstall(ContextName context, string packageId)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (packageId == null)
                throw new ArgumentNullException("packageId");

            using (var contextKey = OpenRegistryRoot(true, context))
            using (var packageKey = contextKey.CreateSubKey("InstalledProducts\\" + packageId))
            {
                packageKey.SetValue("UninstallPending", 1);
            }
        }
Exemple #20
0
        public static int Main(string[] args)
        {
            Console.WriteLine("Net IDE Package Registration");

            string package = null;
            string contextName = null;
            bool experimental = false;
            bool uninstall = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLowerInvariant())
                {
                    case "/context":
                    case "/c":
                        if (++i < args.Length)
                            contextName = args[i];
                        break;

                    case "/uninstall":
                    case "/u":
                        uninstall = true;
                        break;

                    case "/experimental":
                        experimental = true;
                        break;

                    default:
                        package = args[i];
                        break;
                }
            }

            if (package == null || contextName == null)
            {
                Console.Error.WriteLine("Usage: niinstall.exe /context|c <context> [/uninstall|u] [/experimental] <package>");
                return 1;
            }

            var context = new ContextName(contextName, experimental);

            if (!uninstall && !File.Exists(package))
            {
                Console.Error.WriteLine("Package not found");
                return 3;
            }

            try
            {
                if (uninstall)
                    new PackageUninstaller(context, package).Execute();
                else
                    new PackageInstaller(context, package).Execute();

                return 0;
            }
            catch (PackageInstallationException ex)
            {
                Console.WriteLine(ex.Message);

                return ex.ExitCode + 10;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Package could not be installed: " + ex.Message);

                if (ex.StackTrace != null)
                    Console.Error.WriteLine(ex.StackTrace);

                return 2;
            }
        }
Exemple #21
0
 public static bool IsValidPackageId(ContextName context, string packageId)
 {
     return
         (packageId.StartsWith("NetIde.Package.", StringComparison.OrdinalIgnoreCase) ||
          packageId.StartsWith(context.Name + ".Package.", StringComparison.OrdinalIgnoreCase));
 }
 public PackageRuntimeInstaller(ContextName context, string packagePath)
     : this(context, packagePath, false)
 {
 }
Exemple #23
0
        private static PackageQueryResult Query(ContextName context, string nuGetSite, IList <string> packageIds, PackageStability stability, PackageQueryOrder queryOrder, int?page)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (nuGetSite == null)
            {
                throw new ArgumentNullException("nuGetSite");
            }

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

            IQueryable <V2FeedPackage> query = service.Packages
                                               .IncludeTotalCount()
                                               .Where(p =>
                                                      p.IsAbsoluteLatestVersion &&
                                                      p.IsLatestVersion
                                                      );

            if (packageIds != null)
            {
                if (packageIds.Count == 0)
                {
                    throw new ArgumentOutOfRangeException("packageIds");
                }

                // The feed doesn't support contains. Because of this, we're
                // building the ||'s of all ID's here dynamically.

                var idProperty          = typeof(V2FeedPackage).GetProperty("Id");
                var parameterExpression = Expression.Parameter(typeof(V2FeedPackage), "p");

                Expression predicate = null;

                foreach (string id in packageIds)
                {
                    var thisPredicate = Expression.Equal(
                        Expression.Property(parameterExpression, idProperty),
                        Expression.Constant(id)
                        );

                    predicate =
                        predicate == null
                        ? thisPredicate
                        : Expression.OrElse(predicate, thisPredicate);
                }

                query = query.Where(Expression.Lambda <Func <V2FeedPackage, bool> >(
                                        predicate, new[] { parameterExpression }
                                        ));
            }
            else
            {
                string prefix = context.Name + ".Package.";

                query = query.Where(p =>
                                    p.Id.StartsWith(prefix) ||
                                    p.Id.StartsWith("NetIde.Package.")
                                    );
            }

            if (stability == PackageStability.StableOnly)
            {
                query = query.Where(p => !p.IsPrerelease);
            }

            switch (queryOrder)
            {
            case PackageQueryOrder.MostDownloads:
                query = query.OrderByDescending(p => p.DownloadCount);
                break;

            case PackageQueryOrder.PublishedDate:
                query = query.OrderByDescending(p => p.Published);
                break;

            case PackageQueryOrder.NameAscending:
                query = query.OrderBy(p => p.Title);
                break;

            case PackageQueryOrder.NameDescending:
                query = query.OrderByDescending(p => p.Title);
                break;
            }

            if (page.HasValue)
            {
                if (page.Value > 0)
                {
                    query = query.Skip(page.Value * PageCount);
                }

                query = query.Take(PageCount);
            }

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

            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                return(new PackageQueryResult(
                           response.TotalCount,
                           page.GetValueOrDefault(0),
                           (int)((response.TotalCount / PageCount) + 1),
                           response.Select(p => Deserialize(p, context, contextKey, nuGetSite)).ToArray()
                           ));
            }
        }
Exemple #24
0
        public static bool IsCorePackage(string packageId, ContextName context)
        {
            if (packageId == null)
                throw new ArgumentNullException("packageId");
            if (context == null)
                throw new ArgumentNullException("context");

            return String.Equals(packageId, context.Name + ".Package.Core", StringComparison.OrdinalIgnoreCase);
        }
Exemple #25
0
        private static PackageQueryResult Query(ContextName context, string nuGetSite, IList<string> packageIds, PackageStability stability, PackageQueryOrder queryOrder, int? page)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (nuGetSite == null)
                throw new ArgumentNullException("nuGetSite");

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

            IQueryable<V2FeedPackage> query = service.Packages
                .IncludeTotalCount()
                .Where(p =>
                    p.IsAbsoluteLatestVersion &&
                    p.IsLatestVersion
                );

            if (packageIds != null)
            {
                if (packageIds.Count == 0)
                    throw new ArgumentOutOfRangeException("packageIds");

                // The feed doesn't support contains. Because of this, we're
                // building the ||'s of all ID's here dynamically.

                var idProperty = typeof(V2FeedPackage).GetProperty("Id");
                var parameterExpression = Expression.Parameter(typeof(V2FeedPackage), "p");

                Expression predicate = null;

                foreach (string id in packageIds)
                {
                    var thisPredicate = Expression.Equal(
                        Expression.Property(parameterExpression, idProperty),
                        Expression.Constant(id)
                    );

                    predicate =
                        predicate == null
                        ? thisPredicate
                        : Expression.OrElse(predicate, thisPredicate);
                }

                query = query.Where(Expression.Lambda<Func<V2FeedPackage, bool>>(
                    predicate, new[] { parameterExpression }
                ));
            }
            else
            {
                string prefix = context.Name + ".Package.";

                query = query.Where(p =>
                    p.Id.StartsWith(prefix) ||
                    p.Id.StartsWith("NetIde.Package.")
                );
            }

            if (stability == PackageStability.StableOnly)
                query = query.Where(p => !p.IsPrerelease);

            switch (queryOrder)
            {
                case PackageQueryOrder.MostDownloads:
                    query = query.OrderByDescending(p => p.DownloadCount);
                    break;

                case PackageQueryOrder.PublishedDate:
                    query = query.OrderByDescending(p => p.Published);
                    break;

                case PackageQueryOrder.NameAscending:
                    query = query.OrderBy(p => p.Title);
                    break;

                case PackageQueryOrder.NameDescending:
                    query = query.OrderByDescending(p => p.Title);
                    break;
            }

            if (page.HasValue)
            {
                if (page.Value > 0)
                    query = query.Skip(page.Value * PageCount);

                query = query.Take(PageCount);
            }

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

            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                return new PackageQueryResult(
                    response.TotalCount,
                    page.GetValueOrDefault(0),
                    (int)((response.TotalCount / PageCount) + 1),
                    response.Select(p => Deserialize(p, context, contextKey, nuGetSite)).ToArray()
                );
            }
        }
Exemple #26
0
        private void LoadContextFromFile(string fileName)
        {
            var context = Serialization.Deserialize<Context>(fileName);

            if (context.Name.IndexOfAny(new[] { '/', '\\' }) != -1)
                return;

            string registryRoot = "Software\\Net IDE\\" + context.Name;

            if (Experimental)
                registryRoot += "$Exp";

            // Attempt to create the registry root to see whether the context
            // name is a legal name.

            string fileSystemRoot;

            using (var key = Registry.CurrentUser.OpenSubKey(registryRoot))
            {
                if (key == null)
                    return;

                fileSystemRoot = (string)key.GetValue("InstallationPath");
            }

            if (fileSystemRoot == null || !Directory.Exists(fileSystemRoot))
                return;

            ContextName = context.Name;
            Context = new ContextName(ContextName, Experimental);
            NuGetSite = context.NuGetSite;
            FileSystemRoot = fileSystemRoot;
            RegistryRoot = registryRoot;
        }
Exemple #27
0
 public static PackageQueryResult Query(ContextName context, string nuGetSite, IList <string> packageIds, PackageStability stability)
 {
     return(Query(context, nuGetSite, packageIds, stability, PackageQueryOrder.NameAscending, null));
 }
Exemple #28
0
        private string GetInstalledRuntimeVersion(ContextName context)
        {
            using (var contextKey = PackageRegistry.OpenRegistryRoot(false, context))
            {
                if (contextKey == null)
                    return null;

                string installationPath = (string)contextKey.GetValue("InstallationPath");

                return VersionResolver.GetVersion(
                    PackageManager.GetEntryAssemblyLocation(installationPath)
                );
            }
        }
Exemple #29
0
        private string GetInstalledVersion(ContextName context, string packageId, string installedRuntimeVersion)
        {
            if (String.Equals(packageId, PackageManager.RuntimePackageId, StringComparison.OrdinalIgnoreCase))
                return installedRuntimeVersion;

            return PackageManager.GetInstalledVersion(context, packageId);
        }
Exemple #30
0
 public static bool IsValidPackageId(ContextName context, string packageId)
 {
     return
         packageId.StartsWith("NetIde.Package.", StringComparison.OrdinalIgnoreCase) ||
         packageId.StartsWith(context.Name + ".Package.", StringComparison.OrdinalIgnoreCase);
 }
Exemple #31
0
        internal static PackageState GetPackageState(RegistryKey contextKey, ContextName context, string packageId)
        {
            if (packageId == null)
                throw new ArgumentNullException("packageId");

            if (contextKey == null)
                return GetPackageState(context, packageId, null);

            using (var key = contextKey.OpenSubKey("InstalledProducts\\" + packageId))
            {
                return GetPackageState(context, packageId, key);
            }
        }
Exemple #32
0
 public static PackageQueryResult Query(ContextName context, string nuGetSite, IList<string> packageIds, PackageStability stability)
 {
     return Query(context, nuGetSite, packageIds, stability, PackageQueryOrder.NameAscending, null);
 }
Exemple #33
0
        private static PackageState GetPackageState(ContextName context, string packageId, RegistryKey packageKey)
        {
            PackageState state = 0;

            if (
                String.Equals(packageId, PackageManager.RuntimePackageId, StringComparison.OrdinalIgnoreCase) ||
                String.Equals(packageId, PackageManager.CorePackageId, StringComparison.OrdinalIgnoreCase)
            )
                state |= PackageState.CorePackage | PackageState.SystemPackage;

            if (PackageManager.IsCorePackage(packageId, context))
                state |= PackageState.CorePackage;

            if (packageKey != null)
            {
                if ((packageKey.GetValue("UninstallPending") as int?).GetValueOrDefault() != 0)
                {
                    state |= PackageState.UninstallPending;
                }
                else
                {
                    if (packageKey.GetValue("Version") != null)
                    {
                        state |= PackageState.Installed;

                        if ((packageKey.GetValue("Disabled") as int?).GetValueOrDefault() != 0)
                            state |= PackageState.Disabled;
                        if (packageKey.GetValue("PendingVersion") != null)
                            state |= PackageState.UpdatePending;
                    }
                    else
                    {
                        state |= PackageState.UpdatePending | PackageState.InstallPending;
                    }
                }
            }

            return state;
        }
Exemple #34
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);
        }
 public PackageRuntimeInstaller(ContextName context, string packagePath)
     : this(context, packagePath, false)
 {
 }
Exemple #36
0
 public static PackageQueryResult Query(ContextName context, string nuGetSite, PackageStability stability, PackageQueryOrder queryOrder, int page)
 {
     return(Query(context, nuGetSite, null, stability, queryOrder, page));
 }
Exemple #37
0
 private static PackageMetadata Deserialize(V2FeedPackage package, ContextName context, RegistryKey contextKey, string nuGetSite)
 {
     return new PackageMetadata
     {
         Authors = package.Authors,
         Description = package.Description,
         DownloadCount = package.DownloadCount,
         GalleryDetailsUrl = package.GalleryDetailsUrl,
         IconUrl = package.IconUrl,
         Id = package.Id,
         Published = package.Published,
         Tags = package.Tags,
         Title = package.Title,
         Version = package.Version,
         NuGetSite = nuGetSite,
         Dependencies = ParseDependencies(package.Dependencies),
         State = PackageRegistry.GetPackageState(contextKey, context, package.Id)
     };
 }