private void AddDrive(DriveInfo validDrive) { VideoFileStorageDevice drive = new VideoFileStorageDevice().Initialize(validDrive, this); var treeViewDrive = drive.AsTreeViewDisplayableViewModel(null, () => string.Format("{0} => {1:##,#} Bytes free", drive.StorageDevice.RootDirectory.FullName, drive.AvailableFreeSpace)); treeViewDrive.LoadOnDemand = () => drive.ParentSeriesDirectory.GetDirectories().Select(videoSeriesDirectory => { var treeViewFolder = new SeriesFolder { Directory = videoSeriesDirectory }.AsTreeViewDisplayableViewModel(treeViewDrive, () => videoSeriesDirectory.Name, "ColoredX", "Green"); treeViewFolder.LoadOnDemand = () => videoSeriesDirectory.GetFiles().Select(fileInfoInSeriesDirectory => { var treeViewFile = new ManagedFile { File = fileInfoInSeriesDirectory }.AsTreeViewDisplayableViewModel(treeViewFolder, () => fileInfoInSeriesDirectory.Name, "ColoredX", "Green"); ((IActionMenu <MenuItemBase>)treeViewFile).AddAction("Reset", "CommandReset()"); ((IActionMenu <MenuItemBase>)treeViewFile).DefaultActionTarget = this; return(treeViewFile); }); treeViewFolder.LoadChildrenNow(); ((IActionMenu <MenuItemBase>)treeViewFolder).AddAction("Ended", "CommandSeriesEnded()"); ((IActionMenu <MenuItemBase>)treeViewFolder).AddAction("Finale", "CommandSeasonFinale()"); ((IActionMenu <MenuItemBase>)treeViewFolder).AddAction("Reset", "CommandReset()"); ((IActionMenu <MenuItemBase>)treeViewFolder).DefaultActionTarget = this; return(treeViewFolder); }); treeViewDrive.IsExpanded = true; VideoFileTree.Add(treeViewDrive); }
// Called by DriveDetector after removable device has been unplugged private void OnDriveRemoved(object sender, DriveDetectorEventArgs e) { DriveInfo drive = new DriveInfo(e.Drive); VideoFileTree.Cast <VideoFileStorageDevice>().Where(i => i.CompareTo(drive) == 0).Apply(itemToClose => VideoFileTree.Remove((ITreeViewDisplayable)itemToClose)); }