public override void Load(XmlElement filenode, FilePath baseDirectory) { dirName = filenode.GetAttribute("name"); if (string.IsNullOrEmpty(dirName) || !FileService.IsValidFileName(dirName)) { throw new InvalidOperationException("Invalid name in directory template"); } foreach (XmlNode node in filenode) { if (!(node is XmlElement)) { continue; } FileDescriptionTemplate t = FileDescriptionTemplate.CreateTemplate((XmlElement)node, baseDirectory); if (t == null) { throw new InvalidOperationException("Invalid file template in directory template"); } templates.Add(t); } }
public static ProjectDescriptor CreateProjectDescriptor(XmlElement xmlElement, FilePath baseDirectory) { ProjectDescriptor projectDescriptor = new ProjectDescriptor(); projectDescriptor.name = xmlElement.GetAttribute("name"); projectDescriptor.directory = xmlElement.GetAttribute("directory"); projectDescriptor.createCondition = xmlElement.GetAttribute("if"); projectDescriptor.type = xmlElement.GetAttribute("type"); if (xmlElement ["Files"] != null) { foreach (XmlNode xmlNode in xmlElement["Files"].ChildNodes) { if (xmlNode is XmlElement) { projectDescriptor.files.Add( FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory)); } } } if (xmlElement ["Resources"] != null) { foreach (XmlNode xmlNode in xmlElement["Resources"].ChildNodes) { if (xmlNode is XmlElement) { var fileTemplate = FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory); if (fileTemplate is SingleFileDescriptionTemplate) { projectDescriptor.resources.Add((SingleFileDescriptionTemplate)fileTemplate); } else { MessageService.ShowError(GettextCatalog.GetString("Only single-file templates allowed to generate resource files")); } } } } if (xmlElement ["References"] != null) { foreach (XmlNode xmlNode in xmlElement["References"].ChildNodes) { projectDescriptor.references.Add(new ProjectReferenceDescription((XmlElement)xmlNode)); } } projectDescriptor.projectOptions = xmlElement ["Options"]; if (projectDescriptor.projectOptions == null) { projectDescriptor.projectOptions = xmlElement.OwnerDocument.CreateElement("Options"); } if (xmlElement ["Packages"] != null) { foreach (XmlNode xmlNode in xmlElement["Packages"].ChildNodes) { if (xmlNode is XmlElement) { var packageReference = ProjectTemplatePackageReference.Create((XmlElement)xmlNode, baseDirectory); projectDescriptor.packageReferences.Add(packageReference); } } } return(projectDescriptor); }
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); }
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 static ProjectDescriptor CreateProjectDescriptor(XmlElement xmlElement, FilePath baseDirectory) { ProjectDescriptor projectDescriptor = new ProjectDescriptor(); projectDescriptor.name = xmlElement.GetAttribute("name"); projectDescriptor.type = xmlElement.GetAttribute("type"); if (String.IsNullOrEmpty(projectDescriptor.type)) { projectDescriptor.type = "DotNet"; } if (xmlElement["Files"] != null) { foreach (XmlNode xmlNode in xmlElement["Files"].ChildNodes) { if (xmlNode is XmlElement) { projectDescriptor.files.Add( FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory)); } } } if (xmlElement["Resources"] != null) { foreach (XmlNode xmlNode in xmlElement["Resources"].ChildNodes) { if (xmlNode is XmlElement) { var fileTemplate = FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory); if (fileTemplate is SingleFileDescriptionTemplate) { projectDescriptor.resources.Add((SingleFileDescriptionTemplate)fileTemplate); } else { MessageService.ShowError(GettextCatalog.GetString("Only single-file templates allowed to generate resource files")); } } } } if (xmlElement["References"] != null) { foreach (XmlNode xmlNode in xmlElement["References"].ChildNodes) { XmlElement elem = (XmlElement)xmlNode; var refType = elem.GetAttribute("type"); ProjectReference projectReference = new ProjectReference((ReferenceType)Enum.Parse(typeof(ReferenceType), refType), elem.GetAttribute("refto")); string specificVersion = elem.GetAttribute("SpecificVersion"); if (!string.IsNullOrEmpty(specificVersion)) { projectReference.SpecificVersion = bool.Parse(specificVersion); } projectDescriptor.references.Add(projectReference); } } projectDescriptor.projectOptions = xmlElement["Options"]; if (projectDescriptor.projectOptions == null) { projectDescriptor.projectOptions = xmlElement.OwnerDocument.CreateElement("Options"); } return(projectDescriptor); }