FromInstalledAddin() public static method

public static FromInstalledAddin ( Addin sinfo ) : AddinPackage
sinfo Mono.Addins.Addin
return AddinPackage
Esempio n. 1
0
        internal override void Resolve(IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved)
        {
            Addin ia = service.Registry.GetAddin(Mono.Addins.Addin.GetIdName(info.Id));

            if (ia != null)
            {
                Package p = AddinPackage.FromInstalledAddin(ia);
                if (!toUninstall.Contains(p))
                {
                    toUninstall.Add(p);
                }

                if (!info.SupportsVersion(ia.Version))
                {
                    // This addin breaks the api of the currently installed one,
                    // it has to be removed, together with all dependencies

                    Addin[] ainfos = service.GetDependentAddins(info.Id, true);
                    foreach (Addin ainfo in ainfos)
                    {
                        p = AddinPackage.FromInstalledAddin(ainfo);
                        if (!toUninstall.Contains(p))
                        {
                            toUninstall.Add(p);
                        }
                    }
                }
            }

            foreach (Dependency dep in info.Dependencies)
            {
                service.ResolveDependency(monitor, dep, this, toInstall, toUninstall, installedRequired, unresolved);
            }
        }
Esempio n. 2
0
        internal void ResolveDependency(IProgressMonitor monitor, Dependency dep, AddinPackage parentPackage, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved)
        {
            AddinDependency adep = dep as AddinDependency;

            if (adep == null)
            {
                return;
            }

            string nsid = Addin.GetFullId(parentPackage.Addin.Namespace, adep.AddinId, null);

            foreach (Package p in toInstall)
            {
                AddinPackage ap = p as AddinPackage;
                if (ap != null)
                {
                    if (Addin.GetIdName(ap.Addin.Id) == nsid && ((AddinInfo)ap.Addin).SupportsVersion(adep.Version))
                    {
                        return;
                    }
                }
            }

            ArrayList addins = new ArrayList();

            addins.AddRange(service.Registry.GetAddins());
            addins.AddRange(service.Registry.GetAddinRoots());

            foreach (Addin addin in addins)
            {
                if (Addin.GetIdName(addin.Id) == nsid && addin.SupportsVersion(adep.Version))
                {
                    AddinPackage p = AddinPackage.FromInstalledAddin(addin);
                    if (!installedRequired.Contains(p))
                    {
                        installedRequired.Add(p);
                    }
                    return;
                }
            }

            AddinRepositoryEntry[] avaddins = service.Repositories.GetAvailableAddins();
            foreach (PackageRepositoryEntry avAddin in avaddins)
            {
                if (Addin.GetIdName(avAddin.Addin.Id) == nsid && ((AddinInfo)avAddin.Addin).SupportsVersion(adep.Version))
                {
                    toInstall.Add(AddinPackage.FromRepository(avAddin));
                    return;
                }
            }
            unresolved.Add(adep);
        }
Esempio n. 3
0
        public void Uninstall(IProgressStatus statusMonitor, IEnumerable <string> ids)
        {
            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor);

            monitor.BeginTask("Uninstalling add-ins", ids.Count());

            foreach (string id in ids)
            {
                bool      rollback          = false;
                ArrayList toUninstall       = new ArrayList();
                ArrayList uninstallPrepared = new ArrayList();

                Addin ia = service.Registry.GetAddin(id);
                if (ia == null)
                {
                    throw new InstallException("The add-in '" + id + "' is not installed.");
                }

                toUninstall.Add(AddinPackage.FromInstalledAddin(ia));

                Addin[] deps = GetDependentAddins(id, true);
                foreach (Addin dep in deps)
                {
                    toUninstall.Add(AddinPackage.FromInstalledAddin(dep));
                }

                monitor.BeginTask("Deleting files", toUninstall.Count * 2 + uninstallPrepared.Count + 1);

                // Prepare install

                foreach (Package mpack in toUninstall)
                {
                    try
                    {
                        mpack.PrepareUninstall(monitor, this);
                        monitor.Step(1);
                        uninstallPrepared.Add(mpack);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                        rollback = true;
                        break;
                    }
                }

                // Commit install

                if (!rollback)
                {
                    foreach (Package mpack in toUninstall)
                    {
                        try
                        {
                            mpack.CommitUninstall(monitor, this);
                            monitor.Step(1);
                        }
                        catch (Exception ex)
                        {
                            ReportException(monitor, ex);
                            rollback = true;
                            break;
                        }
                    }
                }

                // Rollback if failed

                if (rollback)
                {
                    monitor.BeginTask("Rolling back uninstall", uninstallPrepared.Count);
                    foreach (Package mpack in uninstallPrepared)
                    {
                        try
                        {
                            mpack.RollbackUninstall(monitor, this);
                        }
                        catch (Exception ex)
                        {
                            ReportException(monitor, ex);
                        }
                    }
                    monitor.EndTask();
                }
                monitor.Step(1);

                // Cleanup

                foreach (Package mpack in uninstallPrepared)
                {
                    try
                    {
                        mpack.EndUninstall(monitor, this);
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        monitor.Log.WriteLine(ex);
                    }
                }

                monitor.EndTask();
                monitor.Step(1);
            }

            // Update the extension maps
            service.Registry.Update(statusMonitor);

            monitor.EndTask();

            service.SaveConfiguration();
            ResetCachedData();
        }