Exemplo n.º 1
0
        bool ResolveLoadDependencies(List <Addin> addins, Stack depCheck, string id, bool optional)
        {
            if (IsAddinLoaded(id))
            {
                return(true);
            }

            if (depCheck.Contains(id))
            {
                throw new InvalidOperationException("A cyclic addin dependency has been detected.");
            }

            Addin iad = Registry.GetAddin(id);

            if (iad == null || !iad.Enabled)
            {
                if (optional)
                {
                    return(false);
                }
                else if (iad != null && !iad.Enabled)
                {
                    throw new MissingDependencyException(GettextCatalog.GetString("The required addin '{0}' is disabled.", id));
                }
                else
                {
                    throw new MissingDependencyException(GettextCatalog.GetString("The required addin '{0}' is not installed.", id));
                }
            }

            // If this addin has already been requested, bring it to the head
            // of the list, so it is loaded earlier than before.
            addins.Remove(iad);
            addins.Add(iad);

            depCheck.Push(id);

            try {
                foreach (Dependency dep in iad.AddinInfo.Dependencies)
                {
                    AddinDependency adep = dep as AddinDependency;
                    if (adep != null)
                    {
                        try {
                            string adepid = Addin.GetFullId(iad.AddinInfo.Namespace, adep.AddinId, adep.Version);
                            ResolveLoadDependencies(addins, depCheck, adepid, false);
                        } catch (MissingDependencyException) {
                            if (optional)
                            {
                                return(false);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }

                if (iad.AddinInfo.OptionalDependencies != null)
                {
                    foreach (Dependency dep in iad.AddinInfo.OptionalDependencies)
                    {
                        AddinDependency adep = dep as AddinDependency;
                        if (adep != null)
                        {
                            string adepid = Addin.GetFullId(iad.Namespace, adep.AddinId, adep.Version);
                            if (!ResolveLoadDependencies(addins, depCheck, adepid, true))
                            {
                                return(false);
                            }
                        }
                    }
                }
            } finally {
                depCheck.Pop();
            }
            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Checks if an add-in has been loaded.
 /// </summary>
 /// <param name="id">
 /// Full identifier of the add-in.
 /// </param>
 /// <returns>
 /// True if the add-in is loaded.
 /// </returns>
 public bool IsAddinLoaded(string id)
 {
     CheckInitialized();
     ValidateAddinRoots();
     return(loadedAddins.ContainsKey(Addin.GetIdName(id)));
 }
Exemplo n.º 3
0
        internal bool LoadAddin(IProgressStatus statusMonitor, string id, bool throwExceptions)
        {
            try {
                lock (LocalLock) {
                    if (IsAddinLoaded(id))
                    {
                        return(true);
                    }

                    if (!Registry.IsAddinEnabled(id))
                    {
                        string msg = GettextCatalog.GetString("Disabled add-ins can't be loaded.");
                        ReportError(msg, id, null, false);
                        if (throwExceptions)
                        {
                            throw new InvalidOperationException(msg);
                        }
                        return(false);
                    }

                    var   addins   = new List <Addin> ();
                    Stack depCheck = new Stack();
                    ResolveLoadDependencies(addins, depCheck, id, false);
                    addins.Reverse();

                    if (statusMonitor != null)
                    {
                        statusMonitor.SetMessage("Loading Addins");
                    }

                    for (int n = 0; n < addins.Count; n++)
                    {
                        if (statusMonitor != null)
                        {
                            statusMonitor.SetProgress((double)n / (double)addins.Count);
                        }

                        Addin iad = addins [n];
                        if (IsAddinLoaded(iad.Id))
                        {
                            continue;
                        }

                        if (statusMonitor != null)
                        {
                            statusMonitor.SetMessage(string.Format(GettextCatalog.GetString("Loading {0} add-in"), iad.Id));
                        }

                        if (!InsertAddin(statusMonitor, iad))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            catch (Exception ex) {
                ReportError("Add-in could not be loaded: " + ex.Message, id, ex, false);
                if (statusMonitor != null)
                {
                    statusMonitor.ReportError("Add-in '" + id + "' could not be loaded.", ex);
                }
                if (throwExceptions)
                {
                    throw;
                }
                return(false);
            }
        }
Exemplo n.º 4
0
 public int CompareVersionTo(AddinInfo other)
 {
     return(Addin.CompareVersions(this.version, other.Version));
 }