public static FolderModel Convert(XElement element, bool includeChildren = true) { if (!element.Attribute("type").Value.Equals("FOLDER", System.StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Element type is not valid, an element of type 'FOLDER' was expected."); } string name = element.Attribute("name").Value; string displayName = element.Attribute("displayName").Value; string description = element.Attribute("description").Value; return(new FolderModel() { Name = name, DisplayName = string.IsNullOrWhiteSpace(displayName) ? name : displayName, Description = string.IsNullOrWhiteSpace(description) ? displayName : description, Path = FileOrFolderModel.InferPath(element), Children = includeChildren == true?ConvertChildren(element.Elements()) : new List <FolderModel>(), //(from c in element.Elements().Select(p=> ConvertChild(p)).ToList() where (c != null) select c).ToList(), // recursively converts all files and folders belonging to the current folder. }); }
public static FileModel Convert(XElement element) { if (!element.Attribute("type").Value.Equals("FILE", System.StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Element type is not valid, an element of type 'FILE' was expected."); } string name = element.Attribute("name").Value; string displayName = element.Attribute("displayName").Value; string description = element.Attribute("description").Value; string mimeType = element.Attribute("mimeType").Value; string size = element.Attribute("size").Value; return(new FileModel() { Name = name, DisplayName = string.IsNullOrWhiteSpace(displayName) ? name : displayName, Description = string.IsNullOrWhiteSpace(description) ? displayName : description, MimeType = string.IsNullOrWhiteSpace(mimeType) ? "application/text" : mimeType, Path = FileOrFolderModel.InferPath(element), Size = string.IsNullOrWhiteSpace(size) ? 0 : long.Parse(size) }); }