From adabe4e1b99bc57f0381fb0a5bb3192ac0fdff18 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 16 Mar 2020 14:32:39 +0200 Subject: Working on FSE/PPC FileSystem Provider/Service. --- .../ViewModels/FileSystemViewVM.cs | 80 +++++++++++++++++++--- 1 file changed, 72 insertions(+), 8 deletions(-) (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs index 44bd03c39..f9eff7e6f 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs @@ -1,15 +1,19 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; using Tango.Core.Commands; using Tango.FileSystem; using Tango.FSE.Common; +using Tango.FSE.Common.Connection; +using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.FSE.PPCConsole.ViewModels { - public class FileSystemViewVM : FSEViewModel + public class FileSystemViewVM : FSEViewModel, INavigationViewModel { private FileSystemItem _currentItem; public FileSystemItem CurrentItem @@ -26,32 +30,92 @@ namespace Tango.FSE.PPCConsole.ViewModels } public RelayCommand NavigateCommand { get; set; } + public RelayCommand OpenItemCommand { get; set; } + public RelayCommand BackCommand { get; set; } public FileSystemViewVM() { - NavigateCommand = new RelayCommand(Navigate); + NavigateCommand = new RelayCommand(NavigateToCurrentPath); + OpenItemCommand = new RelayCommand(OpenFileSystemItem); + BackCommand = new RelayCommand(NavigateBack, () => !(CurrentItem is FolderItem) || !(CurrentItem as FolderItem).IsRoot); + } + + private async void NavigateBack() + { + if (CurrentItem.Path.Length == 3) + { + await Navigate(null); + } + else + { + String parent = Path.GetDirectoryName(CurrentItem.Path); + await Navigate(parent); + } + } + + public override void OnApplicationStarted() + { + base.OnApplicationStarted(); + MachineProvider.MachineConnected += MachineProvider_MachineConnected; } public override void OnApplicationReady() { base.OnApplicationReady(); + } + + private async void MachineProvider_MachineConnected(object sender, MachineConnectedEventArgs e) + { + await Navigate(null); + } + + private async void NavigateToCurrentPath() + { + await Navigate(CurrentPath); + } - FileSystemManager manager = new FileSystemManager(); - CurrentItem = FileSystemItem.FromDTO(manager.GetFolder(@"C:\")); + private async void OpenFileSystemItem(FileSystemItem item) + { + if (item != null) + { + await Navigate(item.Path); + } } - private void Navigate() + private async Task Navigate(String path) { - if (CurrentPath.IsNotNullOrEmpty()) + try + { + IsFree = false; + + Mouse.OverrideCursor = Cursors.AppStarting; + + if (path != null) + { + CurrentItem = await FileSystemProvider.GetFolder(path) as FileSystemItem; + } + else + { + CurrentItem = await FileSystemProvider.GetThisPC() as FileSystemItem; + } + } + catch (Exception ex) + { + IsFree = true; + Mouse.OverrideCursor = null; + await NotificationProvider.ShowError($"Error navigating to the specified path.\n{ex.FlattenMessage()}"); + } + finally { - FileSystemManager manager = new FileSystemManager(); - CurrentItem = FileSystemItem.FromDTO(manager.GetFolder(CurrentPath)); + IsFree = true; + Mouse.OverrideCursor = null; } } private void OnCurrentItemChanged() { CurrentPath = CurrentItem.Path; + InvalidateRelayCommands(); } } } -- cgit v1.3.1