예제 #1
0
 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);
         }
     }
 }
예제 #2
0
        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);
            }
        }
예제 #3
0
 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);
 }
예제 #4
0
        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);
        }