/// <summary> /// Add disk. /// </summary> /// <param name="disk">Disk to add.</param> public void AddDisk(MochaDisk disk) { if (ExistsDisk(disk.Root)) { throw new MochaException("There is already a disk with this root!"); } Database.OnChanging(this, new EventArgs()); var xDisk = new XElement(disk.Root); xDisk.Add(new XAttribute("Type", "Disk")); xDisk.Add(new XAttribute("Name", disk.Name)); xDisk.Add(new XAttribute("Description", disk.Description)); Database.Doc.Root.Element("FileSystem").Add(xDisk); for (int index = 0; index < disk.Directories.Count; index++) { AddDirectory(disk.Directories[index], disk.Root); } if (disk.Directories.Count == 0) { Database.Save(); } }
/// <summary> /// Returns disk by root. /// </summary> /// <param name="root">Root of disk.</param> public MochaDisk GetDisk(string root) { if (!ExistsDisk(root)) { return(null); } var diskElement = Database.GetXElement($"FileSystem/{root}"); var disk = new MochaDisk(diskElement.Name.LocalName, diskElement.Attribute("Name").Value); disk.Description = diskElement.Attribute("Description").Value; disk.Directories.AddRange(GetDirectories(root)); disk.Files.AddRange(GetFiles(root)); return(disk); }