public override void Load (XmlElement filenode, FilePath baseDirectory)
		{
			name = filenode.GetAttribute ("name");
			string templateID = filenode.GetAttribute ("TemplateID");
			if (string.IsNullOrEmpty (templateID))
				throw new InvalidOperationException ("TemplateID not set");
			innerTemplate = FileTemplate.GetFileTemplateByID (templateID);
			if (innerTemplate == null)
				throw new InvalidOperationException ("Could not find template with ID " + templateID);
			
			string suppressAutoOpenStr = filenode.GetAttribute ("SuppressAutoOpen");
			if (!string.IsNullOrEmpty (suppressAutoOpenStr)) {
				try {
					suppressAutoOpen = bool.Parse (suppressAutoOpenStr);
				} catch (FormatException) {
					throw new InvalidOperationException ("Invalid value for SuppressAutoOpen in template.");
				}
			}
		}
示例#2
0
 static void OnExtensionChanged(object s, ExtensionNodeEventArgs args)
 {
     if (args.Change == ExtensionChange.Add)
     {
         var codon = (ProjectTemplateCodon)args.ExtensionNode;
         try {
             FileTemplate t = LoadFileTemplate(codon.Addin, codon);
             t.Id = codon.Id;
             fileTemplates.Add(t);
         } catch (Exception e) {
             string extId = null, addinId = null;
             if (codon != null)
             {
                 if (codon.HasId)
                 {
                     extId = codon.Id;
                 }
                 if (codon.Addin != null)
                 {
                     addinId = codon.Addin.Id;
                 }
             }
             LoggingService.LogError("Error loading template id {0} in addin {1}:\n{2}",
                                     extId ?? "(null)", addinId ?? "(null)", e.ToString());
         }
     }
     else
     {
         var codon = (ProjectTemplateCodon)args.ExtensionNode;
         foreach (FileTemplate t in fileTemplates)
         {
             if (t.Id == codon.Id)
             {
                 fileTemplates.Remove(t);
                 break;
             }
         }
     }
 }
示例#3
0
 static FileTemplate LoadTemplate(ProjectTemplateCodon codon)
 {
     try {
         FileTemplate t = LoadFileTemplate(codon.Addin, codon);
         t.Id = codon.Id;
         return(t);
     } catch (Exception e) {
         string extId = null, addinId = null;
         if (codon != null)
         {
             if (codon.HasId)
             {
                 extId = codon.Id;
             }
             if (codon.Addin != null)
             {
                 addinId = codon.Addin.Id;
             }
         }
         LoggingService.LogError("Error loading template id {0} in addin {1}:\n{2}",
                                 extId ?? "(null)", addinId ?? "(null)", e.ToString());
     }
     return(null);
 }
示例#4
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);
        }
示例#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);
        }
示例#6
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;
        }
			public TemplateItem (FileTemplate template, string language)
			{
				this.template = template;
				this.language = language;
			}
		public void InitializeTest (string template)
		{
			var document = new XmlDocument ();
			document.LoadXml (template);
			fileTemplate = FileTemplate.LoadFileTemplate (null, document);
		}
		public void Init ()
		{
			fileTemplate = null;
		}
示例#10
0
 public void Init()
 {
     fileTemplate = null;
 }
示例#11
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;
		}