using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using UAF; using UAF.WPF.Models; namespace DataFileAnalyzer { /// /// A dependency to a data file. /// public class DataFileDependency : ListViewItemData { /// /// Normalized path of the target file /// public string Path { get; set; } /// /// Key of the target file if it exists /// public DataFileKey Key { get; set; } /// /// On which platform this dependency exists /// public HashSet Platforms { get; set; } /// /// Constructor /// public DataFileDependency() { Key = DataFileKey.Invalid; Platforms = new HashSet(); } /// /// Save in an XML element /// public bool Save(XElement _element) { _element.SetAttributeValue("Path", Path); DataFileKey.Save(Key, _element); _element.SetAttributeValue("Missing", Missing); if (Platforms.Count != 0) { string platformListString = string.Join(",", Enum.GetValues(typeof (PlatformId)).Cast().Select(x => new Platform(x).Name)); _element.SetAttributeValue("Platforms", platformListString); } return true; } /// /// Load from an XML element /// public bool Load(XElement _element) { bool result = true; Path = _element.Attribute("Path").Value; Key = DataFileKey.Load(_element); Missing = Convert.ToBoolean(_element.Attribute("Missing").Value); XAttribute attr = _element.Attribute("Platforms"); if (attr != null && !string.IsNullOrEmpty(attr.Value)) { string listString = attr.Value; foreach(string platformName in listString.Split(',')) { Platform platform = new Platform(platformName); result &= (platform.Id != PlatformId.UNDEFINED); Platforms.Add(platform); } } return result; } /// /// Is the dependency valid /// public bool IsValid { get { return !Key.IsInvalid() && !Missing; } } /// /// Is the dependency missing /// public bool Missing { get; set; } } }