public ProfileDictionary(IEnumerable <Profile> profileList) { //m_Path = DocumentPath; //m_Doc = new XmlDocument //{ // InnerXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <Items> </Items>" //}; var root = new ProfileFolder("ROOT", Guid.Empty, 1, DateTime.MinValue); foreach (var profile in profileList) { root.Childrens.Add(profile); } Root = root; PlainCollection = new ObservableCollection <Profile>(profileList); }
private ProfileDictionaryObject LoadFromXml() { try { var root = new ProfileFolder("ROOT", Guid.Empty, DateTime.MinValue); if (m_Doc.DocumentElement != null) { foreach (var element in (from XmlElement element in m_Doc.DocumentElement select ParseElement(element, ParentType.Folder)).OrderBy( Item => Item.Name)) { root.Childrens.Add(element); } } return(root); } catch (Exception ex) { throw new Exception(string.Format("Error while parsing document: {0}", ex.Message)); } }
private static ProfileDictionaryObject ParseElement(XmlNode Element, ParentType Parent) { if (Element.Attributes != null) { var name = Element.Attributes[0].Value; var key = (Element.Attributes.Count > 1) ? Guid.Parse(Element.Attributes[1].Value) : Guid.NewGuid(); var timestamp = (Element.Attributes.Count > 2) ? DateTime.ParseExact(Element.Attributes[2].Value, DT_FORMAT_STRING, CultureInfo.InvariantCulture) : DateTime.Now; if (Element.Name == PROFILE_TAG) { if (Parent == ParentType.Set) { return(ParseProfile(Element, name, key, timestamp)); } var prof = ParseProfile(Element, name, key, timestamp); prof.IsTop = true; var set = new ProfileSet(prof.Name, Guid.NewGuid(), prof.Timestamp); set.Childrens.Add(prof); prof.Parent = set; return(set); } if (Element.Name == SET_TAG) { var set = new ProfileSet(name, key, timestamp); foreach (var element in (from XmlElement element in Element select ParseElement(element, ParentType.Set)) .OfType <Profile>().OrderByDescending( Item => Item.Timestamp)) { element.Name = name; element.Parent = set; set.Childrens.Add(element); } if (set.Childrens.Count > 0) { ((Profile)set.Childrens[0]).IsTop = true; } return(set); } if (Element.Name == FOLDER_TAG) { var folder = new ProfileFolder(name, key, timestamp); foreach (var element in (from XmlElement element in Element select ParseElement(element, ParentType.Folder)).OrderBy( Item => Item.Name)) { element.Parent = folder; folder.Childrens.Add(element); } return(folder); } throw new ApplicationException(string.Format("Unknown XML node: {0}", Element.Name)); } throw new ApplicationException(string.Format("No required attributes found on element {0}", Element.Name)); }