GetType() public method

Gets a type defined in the add-in
The type will be looked up in the assemblies that implement the add-in, and recursivelly in all add-ins on which it depends. This method throws an InvalidOperationException if the type can't be found.
public GetType ( string typeName ) : Type
typeName string /// Full name of the type ///
return System.Type
Esempio n. 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);
         }
     }
 }
Esempio n. 2
0
        bool InsertAddin(IProgressStatus statusMonitor, Addin iad)
        {
            try {
                RuntimeAddin p = new RuntimeAddin();

                // Read the config file and load the add-in assemblies
                AddinDescription description = p.Load(iad);

                // Register the add-in
                loadedAddins [Addin.GetIdName(p.Id)] = p;

                if (!AddinDatabase.RunningSetupProcess)
                {
                    // Load the extension points and other addin data

                    foreach (ExtensionNodeSet rel in description.ExtensionNodeSets)
                    {
                        RegisterNodeSet(rel);
                    }

                    foreach (ConditionTypeDescription cond in description.ConditionTypes)
                    {
                        Type ctype = p.GetType(cond.TypeName, true);
                        defaultContext.RegisterCondition(cond.Id, ctype);
                    }
                }

                foreach (ExtensionPoint ep in description.ExtensionPoints)
                {
                    InsertExtensionPoint(p, ep);
                }

                foreach (Assembly asm in p.Assemblies)
                {
                    loadedAssemblies [asm] = p;
                }

                // Fire loaded event
                defaultContext.NotifyAddinLoaded(p);
                AddinManager.ReportAddinLoad(p.Id);
                return(true);
            }
            catch (Exception ex) {
                AddinManager.ReportError("Extension could not be loaded", iad.Id, ex, false);
                if (statusMonitor != null)
                {
                    statusMonitor.ReportError("Extension '" + iad.Id + "' could not be loaded.", ex);
                }
                return(false);
            }
        }
Esempio n. 3
0
        bool InsertAddin(IProgressStatus statusMonitor, Addin iad)
        {
            try {
                RuntimeAddin p = new RuntimeAddin(this);

                // 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);
            }
        }
Esempio n. 4
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 = AddinManager.SessionService.GetAddin(extensionPoint.RootAddin);
                 Type         ot    = addin.GetType(nt.ObjectTypeName);
                 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);
 }
Esempio n. 5
0
        private static FileTemplate LoadFileTemplate (RuntimeAddin addin, ProjectTemplateCodon codon)
        {
			XmlDocument xmlDocument = codon.GetTemplate ();
			FilePath baseDirectory = codon.BaseDirectory;
			
            //Configuration
			XmlElement xmlNodeConfig = xmlDocument.DocumentElement["TemplateConfiguration"];

            FileTemplate fileTemplate = null;
            if (xmlNodeConfig["Type"] != null) {
                Type configType = addin.GetType (xmlNodeConfig["Type"].InnerText);

                if (typeof (FileTemplate).IsAssignableFrom (configType)) {
                    fileTemplate = (FileTemplate)Activator.CreateInstance (configType);
                }
                else
                    throw new InvalidOperationException (string.Format ("The file template class '{0}' must be a subclass of MonoDevelop.Ide.Templates.FileTemplate", xmlNodeConfig["Type"].InnerText));
            }
            else
                fileTemplate = new FileTemplate ();

            fileTemplate.originator = xmlDocument.DocumentElement.GetAttribute ("Originator");
            fileTemplate.created = xmlDocument.DocumentElement.GetAttribute ("Created");
            fileTemplate.lastModified = xmlDocument.DocumentElement.GetAttribute ("LastModified");

            if (xmlNodeConfig["_Name"] != null) {
                fileTemplate.name = xmlNodeConfig["_Name"].InnerText;
            }
            else {
                throw new InvalidOperationException (string.Format ("Missing element '_Name' in file template: {0}", codon.Id));
            }

            if (xmlNodeConfig["_Category"] != null) {
                fileTemplate.category = xmlNodeConfig["_Category"].InnerText;
            }
            else {
                throw new InvalidOperationException (string.Format ("Missing element '_Category' in file template: {0}", codon.Id));
            }

            if (xmlNodeConfig["LanguageName"] != null) {
                fileTemplate.languageName = xmlNodeConfig["LanguageName"].InnerText;
            }

            if (xmlNodeConfig["ProjectType"] != null) {
                fileTemplate.projecttype = xmlNodeConfig["ProjectType"].InnerText;
            }

            if (xmlNodeConfig["_Description"] != null) {
                fileTemplate.description = xmlNodeConfig["_Description"].InnerText;
            }

            if (xmlNodeConfig["Icon"] != null) {
                fileTemplate.icon = ImageService.GetStockId (addin, xmlNodeConfig["Icon"].InnerText, IconSize.Dnd); //xmlNodeConfig["_Description"].InnerText;
            }

            if (xmlNodeConfig["Wizard"] != null) {
                fileTemplate.icon = xmlNodeConfig["Wizard"].Attributes["path"].InnerText;
            }

            if (xmlNodeConfig["DefaultFilename"] != null) {
                fileTemplate.defaultFilename = xmlNodeConfig["DefaultFilename"].InnerText;
				string isFixed = xmlNodeConfig["DefaultFilename"].GetAttribute ("IsFixed");
				if (isFixed.Length > 0) {
					bool bFixed;
					if (bool.TryParse (isFixed, out bFixed))
						fileTemplate.isFixedFilename = bFixed;
					else
						throw new InvalidOperationException ("Invalid value for IsFixed in template.");
				}
            }

            //Template files
            XmlNode xmlNodeTemplates = xmlDocument.DocumentElement["TemplateFiles"];

			if(xmlNodeTemplates != null) {
				foreach(XmlNode xmlNode in xmlNodeTemplates.ChildNodes) {
					if(xmlNode is XmlElement) {
						fileTemplate.files.Add (
							FileDescriptionTemplate.CreateTemplate ((XmlElement)xmlNode, baseDirectory));
					}
				}
			}

            //Conditions
            XmlNode xmlNodeConditions = xmlDocument.DocumentElement["Conditions"];
			if(xmlNodeConditions != null) {
				foreach(XmlNode xmlNode in xmlNodeConditions.ChildNodes) {
					if(xmlNode is XmlElement) {
						fileTemplate.conditions.Add (FileTemplateCondition.CreateCondition ((XmlElement)xmlNode));
					}
				}
			}

            return fileTemplate;
        }
Esempio n. 6
0
        bool InsertAddin(IProgressStatus statusMonitor, Addin iad)
        {
            try {
                RuntimeAddin p = new RuntimeAddin (this);

                // Read the config file and load the add-in assemblies
                AddinDescription description = p.Load (iad);

                // Register the add-in
                loadedAddins [Addin.GetIdName (p.Id)] = p;

                if (!AddinDatabase.RunningSetupProcess) {
                    // Load the extension points and other addin data

                    foreach (ExtensionNodeSet rel in description.ExtensionNodeSets) {
                        RegisterNodeSet (rel);
                    }

                    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;
            }
        }
Esempio n. 7
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);
         }
     }
 }
Esempio n. 8
0
		public void UnregisterProperty (RuntimeAddin addin, string targetType, string name)
		{
			TypeRef tr;
			if (!pendingTypesByTypeName.TryGetValue (targetType, out tr))
				return;

			if (tr.DataType != null) {
				Type t = addin.GetType (targetType, false);
				if (t != null)
					UnregisterProperty (t, name);
				return;
			}
			
			PropertyRef prop = tr.Properties;
			PropertyRef prev = null;
			while (prop != null) {
				if (prop.Name == name) {
					if (prev != null)
						prev.Next = prop.Next;
					else
						tr.Properties = null;
					break;
				}
				prev = prop;
				prop = prop.Next;
			}
		}
Esempio n. 9
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).FullName)
            {
                // 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).FullName)
                    {
                        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 (ntype.ExtensionAttributeTypeName != boundAttributeType.MemberType.FullName)
                {
                    throw new InvalidOperationException("Incorrect custom attribute type declaration in " + ntype.Type + ". Expected '" + ntype.ExtensionAttributeTypeName + "' found '" + boundAttributeType.MemberType.FullName + "'");
                }

                fields = GetMembersMap(boundAttributeType.MemberType, out boundAttributeType);
                if (fields.Count > 0)
                {
                    ntype.CustomAttributeFields = fields;
                }
            }

            return(true);
        }
Esempio n. 10
0
		public void RegisterProperty (RuntimeAddin addin, string targetType, string name, string propertyType, bool isExternal, bool skipEmpty)
		{
			TypeRef tr;
			if (!pendingTypesByTypeName.TryGetValue (targetType, out tr)) {
				tr = new TypeRef (addin, targetType);
				pendingTypesByTypeName [targetType] = tr;
			}
			if (tr.DataType != null) {
				RegisterProperty (addin.GetType (targetType, true), name, addin.GetType (propertyType, true), isExternal, skipEmpty);
				return;
			}
			PropertyRef prop = new PropertyRef (addin, targetType, name, propertyType, isExternal, skipEmpty);
			if (tr.Properties == null)
				tr.Properties = prop;
			else {
				PropertyRef plink = tr.Properties;
				while (plink.Next != null)
					plink = plink.Next;
				plink.Next = prop;
			}
		}
		public void AddMap (RuntimeAddin addin, string xmlMap, string fileId)
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (xmlMap);
			
			foreach (XmlElement elem in doc.DocumentElement.SelectNodes ("DataItem")) {
				string tname = elem.GetAttribute ("class");
				Type type = addin.GetType (tname);
				if (type == null) {
					LoggingService.LogError ("[SerializationMap " + fileId + "] Type not found: '" + tname + "'");
					continue;
				}
				
				string cname = elem.GetAttribute ("name");
				string ftname = elem.GetAttribute ("fallbackType");

				SerializationMap map;
				if (!maps.TryGetValue (type, out map)) {
					map = new SerializationMap (type);
					maps [type] = map;
					map.FileId = fileId;
					if (cname.Length > 0 || ftname.Length > 0) {
						DataItemAttribute iat = new DataItemAttribute ();
						if (cname.Length > 0)
							iat.Name = cname;
						if (ftname.Length > 0)
							iat.FallbackType = addin.GetType (ftname, true);
						map.TypeAttributes.Add (iat);
					}
				} else {
					if (!string.IsNullOrEmpty (cname))
						throw new InvalidOperationException (string.Format ("Type name for type '{0}' in map '{1}' already specified in another serialization map for the same type ({2}).", type, fileId, map.FileId));
					if (!string.IsNullOrEmpty (ftname))
						throw new InvalidOperationException (string.Format ("Fallback type for type '{0}' in map '{1}' already specified in another serialization map for the same type ({2}).", type, fileId, map.FileId));
				}
				
				string customDataItem = elem.GetAttribute ("customDataItem");
				if (customDataItem.Length > 0) {
					ICustomDataItemHandler ch = (ICustomDataItemHandler) addin.CreateInstance (customDataItem, true);
					if (map.CustomHandler != null)
						map.CustomHandler = new CustomDataItemHandlerChain (map.CustomHandler, ch);
					else
						map.CustomHandler = ch;
				}
				
				ItemMember lastMember = null;
				int litc = 0;
				
				foreach (XmlElement att in elem.SelectNodes ("ItemProperty|ExpandedCollection|LiteralProperty|ItemMember"))
				{
					string memberName = null;
					ItemMember prevMember = lastMember;
					lastMember = null;
					
					if (att.Name == "LiteralProperty") {
						ItemMember mem = new ItemMember ();
						memberName = mem.Name = "_literal_" + (++litc);
						mem.Type = typeof(string);
						mem.InitValue = att.GetAttribute ("value");
						mem.DeclaringType = map.Type;
						map.ExtendedMembers.Add (mem);
						ItemPropertyAttribute itemAtt = new ItemPropertyAttribute ();
						itemAtt.Name = att.GetAttribute ("name");
						map.AddMemberAttribute (mem, itemAtt);
						lastMember = mem;
						continue;
					}
					else if (att.Name == "ItemMember") {
						ItemMember mem = new ItemMember ();
						memberName = mem.Name = att.GetAttribute ("name");
						mem.Type = addin.GetType (att.GetAttribute ("type"), true);
						mem.DeclaringType = map.Type;
						map.ExtendedMembers.Add (mem);
						lastMember = mem;
						continue;
					}
					else
					{
						memberName = att.GetAttribute ("member");
						
						Type mt;
						object mi;
						if (!FindMember (map, memberName, out mi, out mt)) {
							LoggingService.LogError ("[SerializationMap " + fileId + "] Member '" + memberName + "' not found in type '" + tname + "'");
							continue;
						}
						
						if (att.Name == "ItemProperty")
						{
							ItemPropertyAttribute itemAtt = new ItemPropertyAttribute ();
							
							string val = att.GetAttribute ("name");
							if (val.Length > 0)
								itemAtt.Name = val;
							
							val = att.GetAttribute ("scope");
							if (val.Length > 0)
								itemAtt.Scope = val;
							
							if (att.Attributes ["defaultValue"] != null) {
								if (mt.IsEnum)
									itemAtt.DefaultValue = Enum.Parse (mt, att.GetAttribute ("defaultValue"));
								else
									itemAtt.DefaultValue = Convert.ChangeType (att.GetAttribute ("defaultValue"), mt);
							}
							
							val = att.GetAttribute ("serializationDataType");
							if (val.Length > 0)
								itemAtt.SerializationDataType = addin.GetType (val, true);
							
							val = att.GetAttribute ("valueType");
							if (val.Length > 0)
								itemAtt.ValueType = addin.GetType (val, true);
							
							val = att.GetAttribute ("readOnly");
							if (val.Length > 0)
								itemAtt.ReadOnly = bool.Parse (val);
							
							val = att.GetAttribute ("writeOnly");
							if (val.Length > 0)
								itemAtt.WriteOnly = bool.Parse (val);
							
							val = att.GetAttribute ("fallbackType");
							if (val.Length > 0)
								itemAtt.FallbackType = addin.GetType (val, true);
							
							val = att.GetAttribute ("isExternal");
							if (val.Length > 0)
								itemAtt.IsExternal = bool.Parse (val);
							
							val = att.GetAttribute ("skipEmpty");
							if (val.Length > 0)
								itemAtt.SkipEmpty = bool.Parse (val);
							
							map.AddMemberAttribute (mi, itemAtt);
						}
						else if (att.Name == "ExpandedCollection")
						{
							ExpandedCollectionAttribute eat = new ExpandedCollectionAttribute ();
							map.AddMemberAttribute (mi, eat);
						}
					}
					if (prevMember != null)
						prevMember.InsertBefore = memberName;
				}
			}
		}
Esempio n. 12
0
        bool InitializeNodeType(ExtensionNodeType ntype)
        {
            RuntimeAddin p = AddinManager.SessionService.GetAddin(ntype.AddinId);

            if (p == null)
            {
                if (!AddinManager.SessionService.IsAddinLoaded(ntype.AddinId))
                {
                    if (!AddinManager.SessionService.LoadAddin(null, ntype.AddinId, false))
                    {
                        return(false);
                    }
                    p = AddinManager.SessionService.GetAddin(ntype.AddinId);
                    if (p == null)
                    {
                        AddinManager.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.Type = typeof(TypeExtensionNode);
                return(true);
            }

            ntype.Type = p.GetType(ntype.TypeName, false);
            if (ntype.Type == null)
            {
                AddinManager.ReportError("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false);
                return(false);
            }

            Hashtable fields = new Hashtable();

            // Check if the type has NodeAttribute attributes applied to fields.
            Type type = ntype.Type;

            while (type != typeof(object) && type != null)
            {
                foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    NodeAttributeAttribute at = (NodeAttributeAttribute)Attribute.GetCustomAttribute(field, typeof(NodeAttributeAttribute), true);
                    if (at != null)
                    {
                        ExtensionNodeType.FieldData fdata = new ExtensionNodeType.FieldData();
                        fdata.Field       = field;
                        fdata.Required    = at.Required;
                        fdata.Localizable = at.Localizable;

                        string name;
                        if (at.Name != null && at.Name.Length > 0)
                        {
                            name = at.Name;
                        }
                        else
                        {
                            name = field.Name;
                        }

                        fields [name] = fdata;
                    }
                }
                type = type.BaseType;
            }
            if (fields.Count > 0)
            {
                ntype.Fields = fields;
            }

            return(true);
        }
Esempio n. 13
0
		internal static FileTemplate LoadFileTemplate (RuntimeAddin addin, XmlDocument xmlDocument, FilePath baseDirectory = new FilePath (), string templateId = "")
		{
			//Configuration
			XmlElement xmlNodeConfig = xmlDocument.DocumentElement ["TemplateConfiguration"];

			FileTemplate fileTemplate;
			if (xmlNodeConfig ["Type"] != null) {
				Type configType = addin.GetType (xmlNodeConfig ["Type"].InnerText);

				if (typeof(FileTemplate).IsAssignableFrom (configType)) {
					fileTemplate = (FileTemplate)Activator.CreateInstance (configType);
				} else
					throw new InvalidOperationException (string.Format ("The file template class '{0}' must be a subclass of MonoDevelop.Ide.Templates.FileTemplate", xmlNodeConfig ["Type"].InnerText));
			} else
				fileTemplate = new FileTemplate ();

			fileTemplate.Originator = xmlDocument.DocumentElement.GetAttribute ("Originator");
			fileTemplate.Created = xmlDocument.DocumentElement.GetAttribute ("Created");
			fileTemplate.LastModified = xmlDocument.DocumentElement.GetAttribute ("LastModified");

			if (xmlNodeConfig ["_Name"] != null) {
				fileTemplate.Name = xmlNodeConfig ["_Name"].InnerText;
			} else {
				throw new InvalidOperationException (string.Format ("Missing element '_Name' in file template: {0}", templateId));
			}

			if (xmlNodeConfig ["LanguageName"] != null) {
				fileTemplate.LanguageName = xmlNodeConfig ["LanguageName"].InnerText;
			}

			if (xmlNodeConfig ["ProjectType"] != null) {
				var projectTypeList = new List<string> ();
				foreach (var item in xmlNodeConfig["ProjectType"].InnerText.Split (','))
					projectTypeList.Add (item.Trim ());
				fileTemplate.ProjectTypes = projectTypeList;
			}

			fileTemplate.Categories = new Dictionary<string, string> ();
			if (xmlNodeConfig ["_Category"] != null) {
				foreach (XmlNode xmlNode in xmlNodeConfig.GetElementsByTagName ("_Category")) {
					if (xmlNode is XmlElement) {
						string projectType = "";
						if (xmlNode.Attributes ["projectType"] != null)
							projectType = xmlNode.Attributes ["projectType"].Value;

						if (!string.IsNullOrEmpty (projectType) && fileTemplate.ProjectTypes.Contains (projectType))
							fileTemplate.Categories.Add (projectType, xmlNode.InnerText);
						else if (!fileTemplate.Categories.ContainsKey (DefaultCategoryKey))
							fileTemplate.Categories.Add (DefaultCategoryKey, xmlNode.InnerText);
					}
				}
			} else {
				throw new InvalidOperationException (string.Format ("Missing element '_Category' in file template: {0}", templateId));
			}

			if (xmlNodeConfig ["_Description"] != null) {
				fileTemplate.Description = xmlNodeConfig ["_Description"].InnerText;
			}

			if (xmlNodeConfig ["Icon"] != null) {
				fileTemplate.Icon = ImageService.GetStockId (addin, xmlNodeConfig ["Icon"].InnerText, IconSize.Dnd);
			}

			if (xmlNodeConfig ["Wizard"] != null) {
				fileTemplate.Icon = xmlNodeConfig ["Wizard"].Attributes ["path"].InnerText;
			}

			if (xmlNodeConfig ["DefaultFilename"] != null) {
				fileTemplate.DefaultFilename = xmlNodeConfig ["DefaultFilename"].InnerText;
				string isFixed = xmlNodeConfig ["DefaultFilename"].GetAttribute ("IsFixed");
				if (isFixed.Length > 0) {
					bool bFixed;
					if (bool.TryParse (isFixed, out bFixed))
						fileTemplate.IsFixedFilename = bFixed;
					else
						throw new InvalidOperationException ("Invalid value for IsFixed in template.");
				}
			}

			//Template files
			XmlNode xmlNodeTemplates = xmlDocument.DocumentElement ["TemplateFiles"];

			if (xmlNodeTemplates != null) {
				foreach (XmlNode xmlNode in xmlNodeTemplates.ChildNodes) {
					var xmlElement = xmlNode as XmlElement;
					if (xmlElement != null) {
						fileTemplate.Files.Add (
							FileDescriptionTemplate.CreateTemplate (xmlElement, baseDirectory));
					}
				}
			}

			//Conditions
			XmlNode xmlNodeConditions = xmlDocument.DocumentElement ["Conditions"];
			if (xmlNodeConditions != null) {
				foreach (XmlNode xmlNode in xmlNodeConditions.ChildNodes) {
					var xmlElement = xmlNode as XmlElement;
					if (xmlElement != null) {
						fileTemplate.Conditions.Add (FileTemplateCondition.CreateCondition (xmlElement));
					}
				}
			}

			return fileTemplate;
		}
Esempio n. 14
0
        bool InitializeNodeType(ExtensionNodeType ntype)
        {
            RuntimeAddin p = AddinManager.SessionService.GetAddin(ntype.AddinId);

            if (p == null)
            {
                if (!AddinManager.SessionService.IsAddinLoaded(ntype.AddinId))
                {
                    if (!AddinManager.SessionService.LoadAddin(null, ntype.AddinId, false))
                    {
                        return(false);
                    }
                    p = AddinManager.SessionService.GetAddin(ntype.AddinId);
                    if (p == null)
                    {
                        AddinManager.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.Type = typeof(TypeExtensionNode);
                return(true);
            }

            ntype.Type = p.GetType(ntype.TypeName, false);
            if (ntype.Type == null)
            {
                AddinManager.ReportError("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false);
                return(false);
            }

            Hashtable fields    = new Hashtable();
            ArrayList reqFields = new ArrayList();

            // Check if the type has NodeAttribute attributes applied to fields.
            foreach (FieldInfo field in ntype.Type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                NodeAttributeAttribute at = (NodeAttributeAttribute)Attribute.GetCustomAttribute(field, typeof(NodeAttributeAttribute), true);
                if (at != null)
                {
                    string name;
                    if (at.Name != null && at.Name.Length > 0)
                    {
                        name = at.Name;
                    }
                    else
                    {
                        name = field.Name;
                    }

                    if (at.Required)
                    {
                        reqFields.Add(name);
                    }
                    fields [name] = field;
                }
            }
            if (fields.Count > 0)
            {
                ntype.Fields = fields;
                if (reqFields.Count > 0)
                {
                    ntype.RequiredFields = (string[])reqFields.ToArray(typeof(string));
                }
            }

            return(true);
        }