Ejemplo n.º 1
0
        public AddinRepository RegisterRepository(IProgressStatus monitor, string url, bool updateNow)
        {
            if (!url.EndsWith(".mrep"))
            {
                url = url + "/main.mrep";
            }

            RepositoryRecord rr = FindRepositoryRecord(url);

            if (rr != null)
            {
                return(rr);
            }

            rr = RegisterRepository(url, false);

            try {
                if (updateNow)
                {
                    UpdateRepository(monitor, url);
                    rr = FindRepositoryRecord(url);
                    Repository rep = rr.GetCachedRepository();
                    if (rep != null)
                    {
                        rr.Name = rep.Name;
                    }
                }
                service.SaveConfiguration();
                return(rr);
            } catch (Exception ex) {
                if (monitor != null)
                {
                    monitor.ReportError("The repository could not be registered", ex);
                }
                if (ContainsRepository(url))
                {
                    RemoveRepository(url);
                }
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Subscribes to an on-line repository
        /// </summary>
        /// <param name="monitor">
        /// Progress monitor where to show progress status and log
        /// </param>
        /// <param name="url">
        /// URL of the repository
        /// </param>
        /// <param name="updateNow">
        /// When set to True, the repository index will be downloaded.
        /// </param>
        /// <param name="providerId">
        /// What kind of repository
        /// </param>
        /// <returns>
        /// A repository reference
        /// </returns>
        public AddinRepository RegisterRepository(IProgressStatus monitor, string url, bool updateNow, string providerId)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException("Emtpy url");
            }

            if (providerId == "MonoAddins")
            {
                if (!url.EndsWith(".mrep"))
                {
                    if (url [url.Length - 1] != '/')
                    {
                        url += "/";
                    }
                    url = url + "main.mrep";
                }
            }

            RepositoryRecord rr = FindRepositoryRecord(url);

            if (rr != null)
            {
                return(rr);
            }

            rr = RegisterRepository(url, false, providerId);

            try {
                if (updateNow)
                {
                    UpdateRepository(monitor, url);
                    rr = FindRepositoryRecord(url);
                    Repository rep = rr.GetCachedRepository();
                    if (rep != null)
                    {
                        rr.Name = rep.Name;
                    }
                }
                service.SaveConfiguration();
                return(rr);
            } catch (Exception ex) {
                if (monitor != null)
                {
                    monitor.ReportError("The repository could not be registered", ex);
                }
                if (ContainsRepository(url))
                {
                    RemoveRepository(url);
                }
                return(null);
            }
        }
Ejemplo n.º 3
0
        internal bool Install(IProgressStatus statusMonitor, PackageCollection packs)
        {
            // Make sure the registry is up to date
            service.Registry.Update(statusMonitor);

            IProgressMonitor monitor = ProgressStatusMonitor.GetProgressMonitor(statusMonitor);

            PackageCollection    toUninstall;
            DependencyCollection unresolved;

            if (!ResolveDependencies(monitor, packs, out toUninstall, out unresolved))
            {
                monitor.ReportError("Not all dependencies could be resolved.", null);
                return(false);
            }

            ArrayList prepared          = new ArrayList();
            ArrayList uninstallPrepared = new ArrayList();
            bool      rollback          = false;

            monitor.BeginTask("Installing add-ins...", 100);

            // Prepare install

            monitor.BeginStepTask("Initializing installation", toUninstall.Count + packs.Count + 1, 75);

            foreach (Package mpack in toUninstall)
            {
                try
                {
                    mpack.PrepareUninstall(monitor, this);
                    uninstallPrepared.Add(mpack);
                    if (monitor.IsCancelRequested)
                    {
                        throw new InstallException("Installation cancelled.");
                    }
                    monitor.Step(1);
                }
                catch (Exception ex)
                {
                    ReportException(monitor, ex);
                    rollback = true;
                    break;
                }
            }

            monitor.Step(1);

            foreach (Package mpack in packs)
            {
                try
                {
                    mpack.PrepareInstall(monitor, this);
                    if (monitor.IsCancelRequested)
                    {
                        throw new InstallException("Installation cancelled.");
                    }
                    prepared.Add(mpack);
                    monitor.Step(1);
                }
                catch (Exception ex)
                {
                    ReportException(monitor, ex);
                    rollback = true;
                    break;
                }
            }

            monitor.EndTask();

            monitor.BeginStepTask("Installing", toUninstall.Count + packs.Count + 1, 20);

            // Commit install

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

            monitor.Step(1);

            if (!rollback)
            {
                foreach (Package mpack in packs)
                {
                    try
                    {
                        mpack.CommitInstall(monitor, this);
                        if (monitor.IsCancelRequested)
                        {
                            throw new InstallException("Installation cancelled.");
                        }
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                        rollback = true;
                        break;
                    }
                }
            }

            monitor.EndTask();

            // Rollback if failed

            if (monitor.IsCancelRequested)
            {
                monitor = new NullProgressMonitor();
            }

            if (rollback)
            {
                monitor.BeginStepTask("Finishing installation", (prepared.Count + uninstallPrepared.Count) * 2 + 1, 5);

                foreach (Package mpack in prepared)
                {
                    try
                    {
                        mpack.RollbackInstall(monitor, this);
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                    }
                }

                foreach (Package mpack in uninstallPrepared)
                {
                    try
                    {
                        mpack.RollbackUninstall(monitor, this);
                        monitor.Step(1);
                    }
                    catch (Exception ex)
                    {
                        ReportException(monitor, ex);
                    }
                }
            }
            else
            {
                monitor.BeginStepTask("Finishing installation", prepared.Count + uninstallPrepared.Count + 1, 5);
            }

            // Cleanup

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

            monitor.Step(1);

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

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

            monitor.EndTask();

            monitor.EndTask();

            service.SaveConfiguration();
            ResetCachedData();

            return(!rollback);
        }