コード例 #1
0
 internal void ActivateAddin(string id)
 {
     defaultContext.ActivateAddinExtensions(id);
 }
コード例 #2
0
        internal void ActivateAddinExtensions(string id)
        {
            // Looks for loaded extension points which are extended by the provided
            // add-in, and adds the new nodes

            try {
                fireEvents = true;

                Addin addin = AddinManager.Registry.GetAddin(id);
                if (addin == null)
                {
                    AddinManager.ReportError("Required add-in not found", id, null, false);
                    return;
                }

                // Look for loaded extension points
                Hashtable eps = new Hashtable();
                foreach (ModuleDescription mod in addin.Description.AllModules)
                {
                    foreach (Extension ext in mod.Extensions)
                    {
                        ExtensionPoint ep = tree.FindExtensionPoint(ext.Path);
                        if (ep != null && !eps.Contains(ep))
                        {
                            eps.Add(ep, ep);
                        }
                    }
                }

                // Add the new nodes
                ArrayList loadedNodes = new ArrayList();
                foreach (ExtensionPoint ep in eps.Keys)
                {
                    ExtensionLoadData data = GetAddinExtensions(id, ep);
                    if (data != null)
                    {
                        foreach (Extension ext in data.Extensions)
                        {
                            TreeNode node = GetNode(ext.Path);
                            if (node != null && node.ExtensionNodeSet != null)
                            {
                                LoadModuleExtensionNodes(ext, data.AddinId, node.ExtensionNodeSet, loadedNodes);
                            }
                            else
                            {
                                AddinManager.ReportError("Extension node not found or not extensible: " + ext.Path, id, null, false);
                            }
                        }

                        // Global extension change event. Other events are fired by LoadModuleExtensionNodes.
                        NotifyExtensionsChanged(new ExtensionEventArgs(ep.Path));
                    }
                }

                // Call the OnAddinLoaded method on nodes, if the add-in is already loaded
                foreach (TreeNode nod in loadedNodes)
                {
                    nod.ExtensionNode.OnAddinLoaded();
                }
            }
            finally {
                fireEvents = false;
            }
            // Do the same in child contexts

            lock (conditionTypes) {
                if (childContexts != null)
                {
                    foreach (WeakReference wref in childContexts)
                    {
                        ExtensionContext ctx = wref.Target as ExtensionContext;
                        if (ctx != null)
                        {
                            ctx.ActivateAddinExtensions(id);
                        }
                    }
                }
            }
        }
コード例 #3
0
        internal void ActivateAddinExtensions(string id)
        {
            // Looks for loaded extension points which are extended by the provided
            // add-in, and adds the new nodes

            try {
                fireEvents = true;

                Addin addin = AddinManager.Registry.GetAddin(id);
                if (addin == null)
                {
                    AddinManager.ReportError("Required add-in not found", id, null, false);
                    return;
                }
                // Take note that this add-in has been enabled at run-time
                // Needed because loaded add-in descriptions may not include this add-in.
                RegisterRuntimeEnabledAddin(id);

                // Look for loaded extension points
                Hashtable eps           = new Hashtable();
                ArrayList newExtensions = new ArrayList();
                foreach (ModuleDescription mod in addin.Description.AllModules)
                {
                    foreach (Extension ext in mod.Extensions)
                    {
                        if (!newExtensions.Contains(ext.Path))
                        {
                            newExtensions.Add(ext.Path);
                        }
                        ExtensionPoint ep = tree.FindLoadedExtensionPoint(ext.Path);
                        if (ep != null && !eps.Contains(ep))
                        {
                            eps.Add(ep, ep);
                        }
                    }
                }

                // Add the new nodes
                ArrayList loadedNodes = new ArrayList();
                foreach (ExtensionPoint ep in eps.Keys)
                {
                    ExtensionLoadData data = GetAddinExtensions(id, ep);
                    if (data != null)
                    {
                        foreach (Extension ext in data.Extensions)
                        {
                            TreeNode node = GetNode(ext.Path);
                            if (node != null && node.ExtensionNodeSet != null)
                            {
                                if (node.ChildrenLoaded)
                                {
                                    LoadModuleExtensionNodes(ext, data.AddinId, node.ExtensionNodeSet, loadedNodes);
                                }
                            }
                            else
                            {
                                AddinManager.ReportError("Extension node not found or not extensible: " + ext.Path, id, null, false);
                            }
                        }
                    }
                }

                // Call the OnAddinLoaded method on nodes, if the add-in is already loaded
                foreach (TreeNode nod in loadedNodes)
                {
                    nod.ExtensionNode.OnAddinLoaded();
                }

                // Global extension change event. Other events are fired by LoadModuleExtensionNodes.
                // The event is called for all extensions, even for those not loaded. This is for coherence,
                // although that something that it doesn't make much sense to do (subcribing the ExtensionChanged
                // event without first getting the list of nodes that may change).
                foreach (string newExt in newExtensions)
                {
                    NotifyExtensionsChanged(new ExtensionEventArgs(newExt));
                }
            }
            finally {
                fireEvents = false;
            }
            // Do the same in child contexts

            lock (conditionTypes) {
                if (childContexts != null)
                {
                    foreach (WeakReference wref in childContexts)
                    {
                        ExtensionContext ctx = wref.Target as ExtensionContext;
                        if (ctx != null)
                        {
                            ctx.ActivateAddinExtensions(id);
                        }
                    }
                }
            }
        }