RuntimeAddin[] GetDepAddins() { if (depAddins != null) { return(depAddins); } var plugList = new List <RuntimeAddin> (); string ns = ainfo.Description.Namespace; // Collect dependent ids foreach (Dependency dep in module.Dependencies) { AddinDependency pdep = dep as AddinDependency; if (pdep != null) { RuntimeAddin adn = addinEngine.GetAddin(Addin.GetFullId(ns, pdep.AddinId, pdep.Version)); if (adn != null) { plugList.Add(adn); } else { addinEngine.ReportError("Add-in dependency not loaded: " + pdep.FullAddinId, module.ParentAddinDescription.AddinId, null, false); } } } return(depAddins = plugList.ToArray()); }
internal RuntimeAddin(AddinEngine addinEngine, RuntimeAddin parentAddin, ModuleDescription module) { this.addinEngine = addinEngine; this.parentAddin = parentAddin; this.module = module; id = parentAddin.id; baseDirectory = parentAddin.baseDirectory; privatePath = parentAddin.privatePath; ainfo = parentAddin.ainfo; localizer = parentAddin.localizer; module.RuntimeAddin = this; }
internal void InsertExtensionPoint(RuntimeAddin addin, ExtensionPoint ep) { CreateExtensionPoint(ep); foreach (ExtensionNodeType nt in ep.NodeSet.NodeTypes) { if (nt.ObjectTypeName.Length > 0) { Type ntype = addin.GetType(nt.ObjectTypeName, true); RegisterAutoTypeExtensionPoint(ntype, ep.Path); } } }
void RegisterAssemblyResolvePaths(RuntimeAddin addin, ModuleDescription description) { lock (LocalLock) { foreach (var asm in description.AssemblyNames) { // TODO: This assertion seems to break add-in registration // Commenting it out allows add-in registration to work again, // but it likely indicates a deeper problem. Investigate. // Debug.Assert(assemblyResolvePaths[asm] == addin); assemblyResolvePaths[asm] = addin; } } }
public void NotifyAddinLoaded(RuntimeAddin ad, bool recursive) { if (extensionNode != null && extensionNode.AddinId == ad.Addin.Id) { extensionNode.OnAddinLoaded(); } if (recursive && childrenLoaded) { foreach (TreeNode node in Children.Clone()) { node.NotifyAddinLoaded(ad, true); } } }
bool InsertAddin(IProgressStatus statusMonitor, Addin iad) { try { RuntimeAddin p = new RuntimeAddin(this); RegisterAssemblyResolvePaths(p, iad.Description.MainModule); // Read the config file and load the add-in assemblies AddinDescription description = p.Load(iad); // Register the add-in var loadedAddinsCopy = new Dictionary <string, RuntimeAddin> (loadedAddins); loadedAddinsCopy [Addin.GetIdName(p.Id)] = p; loadedAddins = loadedAddinsCopy; if (!AddinDatabase.RunningSetupProcess) { // Load the extension points and other addin data RegisterNodeSets(iad.Id, description.ExtensionNodeSets); foreach (ConditionTypeDescription cond in description.ConditionTypes) { Type ctype = p.GetType(cond.TypeName, true); RegisterCondition(cond.Id, ctype); } } foreach (ExtensionPoint ep in description.ExtensionPoints) { InsertExtensionPoint(p, ep); } // Fire loaded event NotifyAddinLoaded(p); ReportAddinLoad(p.Id); return(true); } catch (Exception ex) { ReportError("Add-in could not be loaded", iad.Id, ex, false); if (statusMonitor != null) { statusMonitor.ReportError("Add-in '" + iad.Id + "' could not be loaded.", ex); } return(false); } }
internal RuntimeAddin GetModule(ModuleDescription module) { // If requesting the root module, return this if (module == module.ParentAddinDescription.MainModule) { return(this); } if (module.RuntimeAddin != null) { return(module.RuntimeAddin); } RuntimeAddin addin = new RuntimeAddin(addinEngine, this, module); return(addin); }
public void ResetCachedData() { if (extensionPoint != null) { string aid = Addin.GetIdName(extensionPoint.ParentAddinDescription.AddinId); RuntimeAddin ad = addinEngine.GetAddin(aid); if (ad != null) { extensionPoint = ad.Addin.Description.ExtensionPoints [GetPath()]; } } if (childrenList != null) { foreach (TreeNode cn in childrenList) { cn.ResetCachedData(); } } }
public bool FindExtensionPathByType(IProgressStatus monitor, Type type, string nodeName, out string path, out string pathNodeName) { if (extensionPoint != null) { foreach (ExtensionNodeType nt in extensionPoint.NodeSet.NodeTypes) { if (nt.ObjectTypeName.Length > 0 && (nodeName.Length == 0 || nodeName == nt.Id)) { RuntimeAddin addin = addinEngine.GetAddin(extensionPoint.RootAddin); Type ot = addin.GetType(nt.ObjectTypeName, true); if (ot != null) { if (ot.IsAssignableFrom(type)) { path = extensionPoint.Path; pathNodeName = nt.Id; return(true); } } else { monitor.ReportError("Type '" + nt.ObjectTypeName + "' not found in add-in '" + Id + "'", null); } } } } else { foreach (TreeNode node in Children) { if (node.FindExtensionPathByType(monitor, type, nodeName, out path, out pathNodeName)) { return(true); } } } path = null; pathNodeName = null; return(false); }
internal void UnloadAddin(string id) { RemoveAddinExtensions(id); RuntimeAddin addin = GetAddin(id); if (addin != null) { addin.UnloadExtensions(); lock (LocalLock) { var loadedAddinsCopy = new Dictionary <string, RuntimeAddin> (loadedAddins); loadedAddinsCopy.Remove(Addin.GetIdName(id)); loadedAddins = loadedAddinsCopy; foreach (var asm in addin.Module.AssemblyNames) { assemblyResolvePaths.Remove(asm); } } ReportAddinUnload(id); } }
bool InitializeNodeType(ExtensionNodeType ntype) { RuntimeAddin p = addinEngine.GetAddin(ntype.AddinId); if (p == null) { if (!addinEngine.IsAddinLoaded(ntype.AddinId)) { if (!addinEngine.LoadAddin(null, ntype.AddinId, false)) { return(false); } p = addinEngine.GetAddin(ntype.AddinId); if (p == null) { addinEngine.ReportError("Add-in not found", ntype.AddinId, null, false); return(false); } } } // If no type name is provided, use TypeExtensionNode by default if (ntype.TypeName == null || ntype.TypeName.Length == 0 || ntype.TypeName == typeof(TypeExtensionNode).AssemblyQualifiedName) { // If it has a custom attribute, use the generic version of TypeExtensionNode if (ntype.ExtensionAttributeTypeName.Length > 0) { Type attType = p.GetType(ntype.ExtensionAttributeTypeName, false); if (attType == null) { addinEngine.ReportError("Custom attribute type '" + ntype.ExtensionAttributeTypeName + "' not found.", ntype.AddinId, null, false); return(false); } if (ntype.ObjectTypeName.Length > 0 || ntype.TypeName == typeof(TypeExtensionNode).AssemblyQualifiedName) { ntype.Type = typeof(TypeExtensionNode <>).MakeGenericType(attType); } else { ntype.Type = typeof(ExtensionNode <>).MakeGenericType(attType); } } else { ntype.Type = typeof(TypeExtensionNode); return(true); } } else { ntype.Type = p.GetType(ntype.TypeName, false); if (ntype.Type == null) { addinEngine.ReportError("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false); return(false); } } // Check if the type has NodeAttribute attributes applied to fields. ExtensionNodeType.FieldData boundAttributeType = null; Dictionary <string, ExtensionNodeType.FieldData> fields = GetMembersMap(ntype.Type, out boundAttributeType); ntype.CustomAttributeMember = boundAttributeType; if (fields.Count > 0) { ntype.Fields = fields; } // If the node type is bound to a custom attribute and there is a member bound to that attribute, // get the member map for the attribute. if (boundAttributeType != null) { if (ntype.ExtensionAttributeTypeName.Length == 0) { throw new InvalidOperationException("Extension node not bound to a custom attribute."); } if (!Util.TryParseTypeName(ntype.ExtensionAttributeTypeName, out var type, out _) || type != boundAttributeType.MemberType.FullName) { throw new InvalidOperationException("Incorrect custom attribute type declaration in " + ntype.Type + ". Expected '" + ntype.ExtensionAttributeTypeName + "' found '" + boundAttributeType.MemberType.AssemblyQualifiedName + "'"); } fields = GetMembersMap(boundAttributeType.MemberType, out boundAttributeType); if (fields.Count > 0) { ntype.CustomAttributeFields = fields; } } return(true); }