ExtensionLoadData GetAddinExtensions(string id, ExtensionPoint ep) { Addin pinfo = null; // Root add-ins are not returned by GetInstalledAddin. RuntimeAddin addin = AddinManager.SessionService.GetAddin(id); if (addin != null) { pinfo = addin.Addin; } else { pinfo = AddinManager.Registry.GetAddin(id); } if (pinfo == null) { AddinManager.ReportError("Required add-in not found", id, null, false); return(null); } if (!pinfo.Enabled) { return(null); } // Loads extensions defined in each module ExtensionLoadData data = null; AddinDescription conf = pinfo.Description; GetAddinExtensions(conf.MainModule, id, ep, ref data); foreach (ModuleDescription module in conf.OptionalModules) { if (CheckOptionalAddinDependencies(conf, module)) { GetAddinExtensions(module, id, ep, ref data); } } if (data != null) { data.Extensions.Sort(); } return(data); }
void GetAddinExtensions(ModuleDescription module, string addinId, ExtensionPoint ep, ref ExtensionLoadData data) { string basePath = ep.Path + "/"; foreach (Extension extension in module.Extensions) { if (extension.Path == ep.Path || extension.Path.StartsWith(basePath)) { if (data == null) { data = new ExtensionLoadData(); data.AddinId = addinId; data.Extensions = new ArrayList(); } data.Extensions.Add(extension); } } }
// Load the extension nodes at the specified path. If the path // contains extension nodes implemented in an add-in which is // not loaded, the add-in will be automatically loaded internal void LoadExtensions(string requestedExtensionPath) { TreeNode node = GetNode(requestedExtensionPath); if (node == null) { throw new InvalidOperationException("Extension point not defined: " + requestedExtensionPath); } ExtensionPoint ep = node.ExtensionPoint; if (ep != null) { // Collect extensions to be loaded from add-ins. Before loading the extensions, // they must be sorted, that's why loading is split in two steps (collecting + loading). ArrayList loadData = new ArrayList(); foreach (string addin in ep.Addins) { ExtensionLoadData ed = GetAddinExtensions(addin, ep); if (ed != null) { // Insert the addin data taking into account dependencies. // An add-in must be processed after all its dependencies. bool added = false; for (int n = 0; n < loadData.Count; n++) { ExtensionLoadData other = (ExtensionLoadData)loadData [n]; if (AddinManager.Registry.AddinDependsOn(other.AddinId, ed.AddinId)) { loadData.Insert(n, ed); added = true; break; } } if (!added) { loadData.Add(ed); } } } // Now load the extensions ArrayList loadedNodes = new ArrayList(); foreach (ExtensionLoadData data in loadData) { foreach (Extension ext in data.Extensions) { TreeNode cnode = GetNode(ext.Path); if (cnode != null && cnode.ExtensionNodeSet != null) { LoadModuleExtensionNodes(ext, data.AddinId, cnode.ExtensionNodeSet, loadedNodes); } else { AddinManager.ReportError("Extension node not found or not extensible: " + ext.Path, data.AddinId, null, false); } } } // Call the OnAddinLoaded method on nodes, if the add-in is already loaded foreach (TreeNode nod in loadedNodes) { nod.ExtensionNode.OnAddinLoaded(); } NotifyExtensionsChanged(new ExtensionEventArgs(requestedExtensionPath)); } }
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); } } } } }
void GetAddinExtensions (ModuleDescription module, string addinId, ExtensionPoint ep, ref ExtensionLoadData data) { string basePath = ep.Path + "/"; foreach (Extension extension in module.Extensions) { if (extension.Path == ep.Path || extension.Path.StartsWith (basePath)) { if (data == null) { data = new ExtensionLoadData (); data.AddinId = addinId; data.Extensions = new ArrayList (); } data.Extensions.Add (extension); } } }
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); } } } } }