Mono.Addins.AddinEngine.ResolveLoadDependencies C# (CSharp) Method

ResolveLoadDependencies() private method

private ResolveLoadDependencies ( ArrayList addins, Stack depCheck, string id, bool optional ) : bool
addins System.Collections.ArrayList
depCheck System.Collections.Stack
id string
optional bool
return bool
        bool ResolveLoadDependencies(ArrayList 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.");

            depCheck.Push (id);

            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);

            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;
                    }
                }
            }

            depCheck.Pop ();
            return true;
        }