static Action <FileTemplateResult> ReadAction(XmlElement el) { switch (el.Name) { case "RunCommand": if (el.HasAttribute("path")) { try { ICommand command = (ICommand)SD.AddInTree.BuildItem(el.GetAttribute("path"), null); return(command.Execute); } catch (TreePathNotFoundException ex) { MessageService.ShowWarning(ex.Message + " - in " + el.OwnerDocument.DocumentElement.GetAttribute("fileName")); return(null); } } else { ProjectTemplateImpl.WarnAttributeMissing(el, "path"); return(null); } default: ProjectTemplateImpl.WarnObsoleteNode(el, "Unknown action element is ignored"); return(null); } }
/// <summary> /// Creates a project descriptor for the project node specified by the xml element. /// </summary> /// <param name="element">The <Project> node of the xml template file.</param> /// <param name="fileSystem">The file system from which referenced files are loaded. Use a ChrootFileSystem to specify the base directory for relative paths.</param> public ProjectDescriptor(XmlElement element, IReadOnlyFileSystem fileSystem) { if (element == null) { throw new ArgumentNullException("element"); } if (fileSystem == null) { throw new ArgumentNullException("fileSystem"); } if (element.HasAttribute("name")) { name = element.GetAttribute("name"); } else { name = "${ProjectName}"; } if (element.HasAttribute("directory")) { relativePath = element.GetAttribute("directory"); } languageName = element.GetAttribute("language"); if (string.IsNullOrEmpty(languageName)) { ProjectTemplateImpl.WarnAttributeMissing(element, "language"); } defaultPlatform = element.GetAttribute("defaultPlatform"); LoadElementChildren(element, fileSystem); }
static Action <object> ReadAction(XmlElement el) { switch (el.Name) { case "RunCommand": if (el.HasAttribute("path")) { string path = el.GetAttribute("path"); #if DEBUG ICommand command = (ICommand)SD.AddInTree.BuildItem(path, null); if (command == null) { throw new TemplateLoadException("Unknown create action " + path); } #endif return(project => { #if !DEBUG ICommand command = (ICommand)SD.AddInTree.BuildItem(path, null); #endif if (command != null) { command.Execute(project); } }); } else { ProjectTemplateImpl.WarnAttributeMissing(el, "path"); return(null); } default: throw new TemplateLoadException("Unknown node in <CreateActions>: " + el.Name); } }
void LoadElement(XmlElement node, IReadOnlyFileSystem fileSystem) { switch (node.Name) { case "Options": ProjectTemplateImpl.WarnObsoleteNode(node, "Options are no longer supported, use properties instead."); break; case "CreateActions": LoadCreateActions(node); break; case "PreCreateActions": LoadPreCreateActions(node); break; case "ProjectItems": LoadProjectItems(node); break; case "Files": LoadFiles(node, fileSystem); break; case "Imports": LoadImports(node); break; case "PropertyGroup": LoadPropertyGroup(node); break; case "Include": TemplateLoadException.AssertAttributeExists(node, "src"); FileName includeFileName = FileName.Create(node.GetAttribute("src")); try { XmlDocument doc = new XmlDocument(); using (var stream = fileSystem.OpenRead(includeFileName)) { doc.Load(stream); } doc.DocumentElement.SetAttribute("fileName", includeFileName); var fileSystemForInclude = new ReadOnlyChrootFileSystem(fileSystem, includeFileName.GetParentDirectory()); if (doc.DocumentElement.Name == "Include") { LoadElementChildren(doc.DocumentElement, fileSystemForInclude); } else { LoadElement(doc.DocumentElement, fileSystemForInclude); } } catch (XmlException ex) { throw new TemplateLoadException("Error loading include file " + includeFileName, ex); } break; default: throw new TemplateLoadException("Unknown node in <Project>: " + node.Name); } }
public FileDescriptionTemplate(XmlElement xml, IReadOnlyFileSystem fileSystem) { TemplateLoadException.AssertAttributeExists(xml, "name"); this.FileSystem = fileSystem; name = xml.GetAttribute("name"); language = xml.GetAttribute("language"); if (xml.HasAttribute("buildAction")) { itemType = xml.GetAttribute("buildAction"); } foreach (XmlAttribute attribute in xml.Attributes) { string attributeName = attribute.Name; if (!knownAttributes.Contains(attributeName)) { if (attributeName == "copyToOutputDirectory") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "CopyToOutputDirectory"; } if (attributeName == "dependentUpon") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "DependentUpon"; } if (attributeName == "subType") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "SubType"; } metadata[attributeName] = attribute.Value; } } if (xml.HasAttribute("src")) { FileName fileName = FileName.Create(StringParser.Parse(xml.GetAttribute("src"))); try { if (xml.HasAttribute("binary") && bool.Parse(xml.GetAttribute("binary"))) { binaryFileName = fileName; } else { content = fileSystem.ReadAllText(fileName); } } catch (Exception e) { content = "Error reading content from " + fileName + ":\n" + e.ToString(); LoggingService.Warn(content); } } else { content = xml.InnerText; } }