private static void AddFileElements(BakeComponent component, XElement parent, XNamespace xns) { foreach (var bakeFile in component.ItsBakeFiles) { var fileElement = new XElement(xns + "File", new XAttribute("Id", bakeFile.ItsId), new XAttribute("Source", bakeFile.ItsSource)); parent.Add(fileElement); } }
public static BakeMetadata ReadBakeFile(string bakeSrc) { var xdoc = XDocument.Load(bakeSrc); var metadata = new BakeMetadata(); try { var root = xdoc.Element("metadata"); // ReSharper disable PossibleNullReferenceException var company_name = root.Element("company_name").Value; var icon_name = root.Element("icon_name").Value; var executable_display_name = root.Element("executable_display_name").Value; var executable_source = root.Element("executable_source").Value; var manufacturer = root.Element("manufacturer").Value; var product_name = root.Element("product_name").Value; var upgrade_code = root.Element("upgrade_code").Value; var add_license = Convert.ToBoolean(root.Element("add_license").Value); var add_banner = Convert.ToBoolean(root.Element("add_banner").Value); metadata.ItsCompanyName = company_name; metadata.ItsIconName = icon_name; metadata.ItsMainExecutableDisplayName = executable_display_name; metadata.ItsMainExecutableSource = executable_source; metadata.ItsManufacturer = manufacturer; metadata.ItsProductName = product_name; metadata.ItsUpgradeCode = new Guid(upgrade_code); metadata.ItsAddLicenseFlag = add_license; metadata.ItsAddBannerFlag = add_banner; var executableCompElem = root.Element("executable_component"); var guid = new Guid(executableCompElem.Attribute("Guid").Value); metadata.ItsMainExecutableComponent = new BakeComponent(executableCompElem.Attribute("Id").Value, guid); var programMenuElem = root.Element("program_menu_dir"); guid = new Guid(programMenuElem.Attribute("Guid").Value); metadata.ItsProgramMenuComponent = new BakeComponent(programMenuElem.Attribute("Id").Value, guid); // read subdirectories and files var directories = root.Elements("Directory"); var list = new List<BakeDirectory>(); foreach (var directory in directories) { var id = directory.Attribute("Id").Value; var name = directory.Attribute("Name").Value; var bakeDir = new BakeDirectory(id, name); var component = directory.Element("Component"); id = component.Attribute("Id").Value; guid = new Guid(component.Attribute("Guid").Value); var bakeComp = new BakeComponent(id, guid); var files = component.Elements("File"); foreach (var file in files) { id = file.Attribute("Id").Value; var src = file.Attribute("Source").Value; var bakeFile = new BakeFile(id, src, bakeComp); bakeComp.ItsBakeFiles.Add(bakeFile); } bakeDir.ItsComponent = bakeComp; } metadata.ItsSubDirectories = list; var main_component_files = root.Element("main_component_files").Elements("File"); var fileList = new List<BakeFile>(); foreach (var file in main_component_files) { fileList.Add(new BakeFile(file.Attribute("Id").Value, file.Attribute("Source").Value, metadata.ItsMainExecutableComponent)); } metadata.ItsMainExecutableComponent.ItsBakeFiles = fileList; // ReSharper restore PossibleNullReferenceException return metadata; } catch (NullReferenceException) { return null; } }
public BakeFile(string id, string source, BakeComponent parentComponent) { ItsId = id; ItsSource = source; ItsParentComponent = parentComponent; }