AddRange() public method

Adds a list of packages to the collection
public AddRange ( ICollection col ) : void
col ICollection /// The list of packages to add ///
return void
Ejemplo n.º 1
0
        internal bool Install(IProgressStatus monitor, params Package[] packages)
        {
            PackageCollection packs = new PackageCollection();

            packs.AddRange(packages);
            return(Install(monitor, packs));
        }
Ejemplo n.º 2
0
        internal bool ResolveDependencies(IProgressMonitor monitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved)
        {
            PackageCollection requested = new PackageCollection();
            requested.AddRange (packages);

            unresolved = new DependencyCollection ();
            toUninstall = new PackageCollection ();
            PackageCollection installedRequired = new PackageCollection ();

            for (int n=0; n<packages.Count; n++) {
                Package p = packages [n];
                p.Resolve (monitor, this, packages, toUninstall, installedRequired, unresolved);
            }

            if (unresolved.Count != 0) {
                foreach (Dependency dep in unresolved)
                    monitor.ReportError (string.Format ("The package '{0}' could not be found in any repository", dep.Name), null);
                return false;
            }

            // Check that we are not uninstalling packages that are required
            // by packages being installed.

            foreach (Package p in installedRequired) {
                if (toUninstall.Contains (p)) {
                    // Only accept to uninstall this package if we are
                    // going to install a newer version.
                    bool foundUpgrade = false;
                    foreach (Package tbi in packages)
                        if (tbi.Equals (p) || tbi.IsUpgradeOf (p)) {
                            foundUpgrade = true;
                            break;
                        }
                    if (!foundUpgrade)
                        return false;
                }
            }

            // Check that we are not trying to uninstall from a directory from
            // which we don't have write permissions

            foreach (Package p in toUninstall) {
                AddinPackage ap = p as AddinPackage;
                if (ap != null) {
                    Addin ia = service.Registry.GetAddin (ap.Addin.Id);
                    if (File.Exists (ia.AddinFile) && !HasWriteAccess (ia.AddinFile)) {
                        monitor.ReportError (GetUninstallErrorNoRoot (ap.Addin), null);
                        return false;
                    }
                }
            }

            // Check that we are not installing two versions of the same addin

            PackageCollection resolved = new PackageCollection();
            resolved.AddRange (packages);

            bool error = false;

            for (int n=0; n<packages.Count; n++) {
                AddinPackage ap = packages [n] as AddinPackage;
                if (ap == null) continue;

                for (int k=n+1; k<packages.Count; k++) {
                    AddinPackage otherap = packages [k] as AddinPackage;
                    if (otherap == null) continue;

                    if (ap.Addin.Id == otherap.Addin.Id) {
                        if (ap.IsUpgradeOf (otherap)) {
                            if (requested.Contains (otherap)) {
                                monitor.ReportError ("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null);
                                error = true;
                            } else {
                                packages.RemoveAt (k);
                            }
                        } else if (otherap.IsUpgradeOf (ap)) {
                            if (requested.Contains (ap)) {
                                monitor.ReportError ("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null);
                                error = true;
                            } else {
                                packages.RemoveAt (n);
                                n--;
                            }
                        } else {
                            error = true;
                            monitor.ReportError ("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null);
                        }
                        break;
                    }
                }
            }

            return !error;
        }
Ejemplo n.º 3
0
        internal bool ResolveDependencies(IProgressMonitor monitor, PackageCollection packages, out PackageCollection toUninstall, out DependencyCollection unresolved)
        {
            PackageCollection requested = new PackageCollection();

            requested.AddRange(packages);

            unresolved  = new DependencyCollection();
            toUninstall = new PackageCollection();
            PackageCollection installedRequired = new PackageCollection();

            for (int n = 0; n < packages.Count; n++)
            {
                Package p = packages [n];
                p.Resolve(monitor, this, packages, toUninstall, installedRequired, unresolved);
            }

            if (unresolved.Count != 0)
            {
                foreach (Dependency dep in unresolved)
                {
                    monitor.ReportError(string.Format("The package '{0}' could not be found in any repository", dep.Name), null);
                }
                return(false);
            }

            // Check that we are not uninstalling packages that are required
            // by packages being installed.

            foreach (Package p in installedRequired)
            {
                if (toUninstall.Contains(p))
                {
                    // Only accept to uninstall this package if we are
                    // going to install a newer version.
                    bool foundUpgrade = false;
                    foreach (Package tbi in packages)
                    {
                        if (tbi.Equals(p) || tbi.IsUpgradeOf(p))
                        {
                            foundUpgrade = true;
                            break;
                        }
                    }
                    if (!foundUpgrade)
                    {
                        return(false);
                    }
                }
            }

            // Check that we are not trying to uninstall from a directory from
            // which we don't have write permissions

            foreach (Package p in toUninstall)
            {
                AddinPackage ap = p as AddinPackage;
                if (ap != null)
                {
                    Addin ia = service.Registry.GetAddin(ap.Addin.Id);
                    if (File.Exists(ia.AddinFile) && !HasWriteAccess(ia.AddinFile) && IsUserAddin(ia.AddinFile))
                    {
                        monitor.ReportError(GetUninstallErrorNoRoot(ap.Addin), null);
                        return(false);
                    }
                }
            }

            // Check that we are not installing two versions of the same addin

            PackageCollection resolved = new PackageCollection();

            resolved.AddRange(packages);

            bool error = false;

            for (int n = 0; n < packages.Count; n++)
            {
                AddinPackage ap = packages [n] as AddinPackage;
                if (ap == null)
                {
                    continue;
                }

                for (int k = n + 1; k < packages.Count; k++)
                {
                    AddinPackage otherap = packages [k] as AddinPackage;
                    if (otherap == null)
                    {
                        continue;
                    }

                    if (ap.Addin.Id == otherap.Addin.Id)
                    {
                        if (ap.IsUpgradeOf(otherap))
                        {
                            if (requested.Contains(otherap))
                            {
                                monitor.ReportError("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null);
                                error = true;
                            }
                            else
                            {
                                packages.RemoveAt(k);
                            }
                        }
                        else if (otherap.IsUpgradeOf(ap))
                        {
                            if (requested.Contains(ap))
                            {
                                monitor.ReportError("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null);
                                error = true;
                            }
                            else
                            {
                                packages.RemoveAt(n);
                                n--;
                            }
                        }
                        else
                        {
                            error = true;
                            monitor.ReportError("Can't install two versions of the same add-in: '" + ap.Addin.Name + "'.", null);
                        }
                        break;
                    }
                }
            }

            // Don't allow installing add-ins which are scheduled for uninstall

            foreach (Package p in packages)
            {
                AddinPackage ap = p as AddinPackage;
                if (ap != null && Registry.IsRegisteredForUninstall(ap.Addin.Id))
                {
                    error = true;
                    monitor.ReportError("The addin " + ap.Addin.Name + " v" + ap.Addin.Version + " is scheduled for uninstallation. Please restart the application before trying to re-install it.", null);
                }
            }

            return(!error);
        }
Ejemplo n.º 4
0
 internal bool Install(IProgressStatus monitor, params Package[] packages)
 {
     PackageCollection packs = new PackageCollection ();
     packs.AddRange (packages);
     return Install (monitor, packs);
 }