/// <summary> /// Add an item that corresponds to the given source file. /// </summary> /// <param name="item">The source file to create an item for.</param> public void AddItem(SourceFile item) { if (item == null) { throw new ArgumentNullException("item"); } Load(); ManifestItemGroup group = null; foreach (ManifestItemGroup g in Groups) { if (g.Name == item.FileType.Name) { group = g; break; } } if (group == null) { group = new ManifestItemGroup(item.FileType.Name, this); _groups.Add(group); } group.AddItem(new ManifestItem(item.Name, group)); }
/// <summary> /// Load the manifest from file. /// </summary> /// <param name="input">The stream to read the input from.</param> /// <returns>The loaded manifest.</returns> public void Load(System.IO.Stream input) { if (input == null) { throw new ArgumentNullException("input"); } if (_groups == null) { _groups = new List <ManifestItemGroup>(); } else { _groups.Clear(); } XmlDocument xml = new XmlDocument(); xml.Load(input); // look for comment foreach (XmlNode node in xml.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { Comment = node.Value; break; } } XmlNamespaceManager namespaces = new XmlNamespaceManager(xml.NameTable); namespaces.AddNamespace("ns", "http://soap.sforce.com/2006/04/metadata"); XmlNodeList nodes = xml.SelectNodes("/ns:Package/ns:types", namespaces); if (nodes != null) { foreach (XmlNode node in nodes) { XmlNode groupName = node.SelectSingleNode("ns:name", namespaces); if (groupName == null) { continue; } ManifestItemGroup group = new ManifestItemGroup(groupName.InnerText); AddGroup(group); XmlNodeList members = node.SelectNodes("ns:members", namespaces); if (members != null) { foreach (XmlNode member in members) { group.AddItem(new ManifestItem(member.InnerText)); } } } } }
/// <summary> /// Constructor. /// </summary> /// <param name="name">Name.</param> /// <param name="group">Group.</param> public ManifestItem(string name, ManifestItemGroup group) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name is null or empty.", "name"); } Name = name; Group = group; }
/// <summary> /// Removes the given group from this manifest if it exists. /// </summary> /// <param name="group">The group to remove.</param> /// <returns>true if the group was removed, false if it wasn't.</returns> public bool RemoveGroup(ManifestItemGroup group) { if (group == null) { throw new ArgumentNullException("group"); } Load(); for (int i = 0; i < _groups.Count; i++) { if (String.Compare(_groups[i].Name, group.Name, true) == 0) { _groups[i].Manifest = null; _groups.RemoveAt(i); return(true); } } return(false); }
/// <summary> /// Add the given group to this manifest if it isn't already a member. /// </summary> /// <param name="group">The group to add.</param> /// <returns>true if the group was added, false if it wasn't.</returns> public bool AddGroup(ManifestItemGroup group) { if (group == null) { throw new ArgumentNullException("group"); } Load(); foreach (ManifestItemGroup g in Groups) { if (String.Compare(g.Name, group.Name, true) == 0) { return(false); } } group.Manifest = this; _groups.Add(group); return(true); }