aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-03-25 17:46:56 +0200
committerAvi Levkovich <avi@twine-s.com>2020-03-25 17:46:56 +0200
commitaa732a33f7c63ce4438ec2b79fedb641ffd22b05 (patch)
tree86ccf57c1dfb6801de16f15d681539c02b007508 /Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels
parentd29da53d6f71f45749c0ede5b4cd7281ed3a270e (diff)
parent8f57d4962fa84499c8a153ebfff6e7766434ee1c (diff)
downloadTango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.tar.gz
Tango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.zip
merge conflicts -take remote
Diffstat (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels')
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/ConsoleViewVM.cs30
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs203
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/MainViewVM.cs24
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs33
4 files changed, 280 insertions, 10 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/ConsoleViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/ConsoleViewVM.cs
index fd1567e0d..4c6eb9958 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/ConsoleViewVM.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/ConsoleViewVM.cs
@@ -4,7 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Console;
+using Tango.Console.Network;
+using Tango.Core.DI;
using Tango.FSE.Common;
+using Tango.FSE.Common.Console;
namespace Tango.FSE.PPCConsole.ViewModels
{
@@ -12,6 +15,9 @@ namespace Tango.FSE.PPCConsole.ViewModels
{
private List<ConsoleSuggestion> _lastSuggestions;
+ [TangoInject]
+ public IConsoleService ConsoleService { get; set; }
+
private ConsoleControlVM _consoleVM;
public ConsoleControlVM ConsoleVM
{
@@ -27,17 +33,35 @@ namespace Tango.FSE.PPCConsole.ViewModels
ConsoleVM.Clear();
}
+ public override void OnApplicationStarted()
+ {
+ ConsoleService.Initialized += ConsoleService_Initialized1;
+ }
+
+ private void ConsoleService_Initialized1(object sender, GetCurrentDirectoryResponse e)
+ {
+ ConsoleVM.Clear();
+ ConsoleVM.CurrentCommand.WorkingFolder = e.CurrentDirectory;
+ ConsoleVM.AppendSuggestions(e.Suggestions);
+ }
+
private async void ConsoleVM_CommandExecuting(object sender, ConsoleCommandExecutingEventArgs e)
{
try
{
- var result = await MachineProvider.MachineOperator.SendGenericRequest<ConsoleCommandDTO, ConsoleCommandExecutionResult>(new ConsoleCommandDTO()
+ var response = await ConsoleService.ExecuteCommand(new ConsoleCommandRequest()
{
Command = e.Command.CommandText,
WorkingFolder = e.Command.WorkingFolder,
});
- _lastSuggestions = result.Suggestions;
- e.Complete(result);
+
+ _lastSuggestions = response.Suggestions;
+ e.Complete(new ConsoleCommandExecutionResult()
+ {
+ Output = response.Output,
+ Suggestions = response.Suggestions,
+ WorkingFolder = response.WorkingFolder
+ });
}
catch (Exception ex)
{
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 cba25303e..e10cc0ad1 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,4 +1,5 @@
-using System;
+using MaterialDesignThemes.Wpf;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@@ -53,6 +54,11 @@ namespace Tango.FSE.PPCConsole.ViewModels
public RelayCommand<FileSystemHandler> DeleteFileSystemHandlerCommand { get; set; }
public RelayCommand<FileSystemHandler> OpenFileSystemHandlerDestinationCommand { get; set; }
public RelayCommand<FileSystemHandler> RetryFailedFileSystemHandlerCommand { get; set; }
+ public RelayCommand<List<FileSystemItem>> CopyPasteCommand { get; set; }
+ public RelayCommand<List<FileSystemItem>> CutPasteCommand { get; set; }
+ public RelayCommand<List<FileSystemItem>> DownloadCommand { get; set; }
+ public RelayCommand<FileSystemItem> RenameCommand { get; set; }
+ public RelayCommand NewFolderCommand { get; set; }
public FileSystemViewVM()
@@ -69,6 +75,11 @@ namespace Tango.FSE.PPCConsole.ViewModels
DeleteFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(DeleteFileSystemHandler);
OpenFileSystemHandlerDestinationCommand = new RelayCommand<FileSystemHandler>(OpenFileSystemHandlerDestination);
RetryFailedFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(RetryFailedFileSystemHandler);
+ CopyPasteCommand = new RelayCommand<List<FileSystemItem>>((items) => PasteItems(items, false));
+ CutPasteCommand = new RelayCommand<List<FileSystemItem>>((items) => PasteItems(items, true));
+ DownloadCommand = new RelayCommand<List<FileSystemItem>>(DownloadSelectedItems);
+ RenameCommand = new RelayCommand<FileSystemItem>(RenameFileSystemItem);
+ NewFolderCommand = new RelayCommand(CreateNewFolder);
}
private async void NavigateBack()
@@ -97,7 +108,10 @@ namespace Tango.FSE.PPCConsole.ViewModels
private async void MachineProvider_MachineConnected(object sender, MachineConnectedEventArgs e)
{
- await Navigate(null);
+ if (e.DifferentFromPrevious)
+ {
+ await Navigate(null);
+ }
}
private async void NavigateToCurrentPath()
@@ -123,9 +137,41 @@ namespace Tango.FSE.PPCConsole.ViewModels
{
if (items != null && items.Count > 0)
{
- if (await NotificationProvider.ShowWarningQuestion("Are you sure you want to delete the selected files/folders?", "DELETE"))
+ if (await NotificationProvider.ShowWarningQuestion($"Are you sure you want to delete {(items.Count == 1 ? $"'{items.First().Name}'" : $"the {items.Count} selected files/folders")}?", "DELETE"))
{
- //TODO: Delete items
+ using (var task = NotificationProvider.PushTaskItem("Removing..."))
+ {
+ int remainingItems = items.Count;
+
+ foreach (var item in items)
+ {
+ task.UpdateProgress($"Removing '{item.Name}'...");
+
+ try
+ {
+ remainingItems--;
+ await FileSystemProvider.Delete(item);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Could not remove '{item.Name}'.");
+
+ if (remainingItems > 0)
+ {
+ if (!await NotificationProvider.ShowWarningQuestion($"Could not remove '{item.Name}'.\n{ex.FlattenMessage()}\nDo you wish to continue removing the remaining items?"))
+ {
+ break;
+ }
+ }
+ else
+ {
+ await NotificationProvider.ShowError($"Could not remove '{item.Name}'.\n{ex.FlattenMessage()}");
+ }
+ }
+ }
+ }
+
+ NavigateToCurrentPath();
}
}
}
@@ -135,6 +181,15 @@ namespace Tango.FSE.PPCConsole.ViewModels
foreach (var item in items.Where(x => x.FileSystemItem.Type != FileSystemItemType.Drive))
{
Debug.WriteLine($"Dropped out: {item.FileSystemItem.Name} => {item.Destination}");
+
+ if (File.Exists(Path.Combine(item.Destination, item.FileSystemItem.Name)) || Directory.Exists(Path.Combine(item.Destination, item.FileSystemItem.Name)))
+ {
+ if (!await NotificationProvider.ShowWarningQuestion($"'{item.FileSystemItem.Name}' already exists on '{Path.GetDirectoryName(item.Destination)}'. Do you want to overwrite?"))
+ {
+ continue;
+ }
+ }
+
var handler = await FileSystemProvider.Download(item.FileSystemItem, item.Destination);
FileSystemHandlers.Insert(0, handler);
}
@@ -234,6 +289,146 @@ namespace Tango.FSE.PPCConsole.ViewModels
}
}
+ private async void PasteItems(List<FileSystemItem> items, bool move = false)
+ {
+ using (var task = NotificationProvider.PushTaskItem("Please wait..."))
+ {
+ int remainingItems = items.Count;
+
+ foreach (var item in items)
+ {
+ Debug.WriteLine($"{(move ? "Cut" : "Copy")} Paste Item '{item.Name}' To '{CurrentItem.Name}'.");
+
+ try
+ {
+ remainingItems--;
+
+ if (move)
+ {
+ task.UpdateProgress($"Moving '{item.Name}'...");
+ await FileSystemProvider.Move(item, CurrentItem);
+ }
+ else
+ {
+ task.UpdateProgress($"Copying '{item.Name}'...");
+ await FileSystemProvider.Copy(item, CurrentItem);
+ }
+ }
+ catch (Exception ex)
+ {
+ string operation = move ? "move" : "copy";
+
+ LogManager.Log(ex, $"Could not {operation} '{item.Name}'.");
+
+ if (remainingItems > 0)
+ {
+ if (!await NotificationProvider.ShowWarningQuestion($"Could not {operation} '{item.Name}'.\n{ex.FlattenMessage()}\nDo you wish to continue with the remaining items?"))
+ {
+ break;
+ }
+ }
+ else
+ {
+ await NotificationProvider.ShowError($"Could not {operation} '{item.Name}'.\n{ex.FlattenMessage()}");
+ }
+ }
+ }
+
+ NavigateToCurrentPath();
+ }
+ }
+
+ private async void DownloadSelectedItems(List<FileSystemItem> items)
+ {
+ var result = await StorageProvider.SelectFolder("Select download destination folder");
+ if (result)
+ {
+
+ String destination = result.SelectedItem;
+
+ Debug.WriteLine($"Download to {result.SelectedItem}");
+
+ foreach (var item in items.Where(x => x.Type != FileSystemItemType.Drive))
+ {
+ if (File.Exists(Path.Combine(destination, item.Name)) || Directory.Exists(Path.Combine(destination, item.Name)))
+ {
+ if (!await NotificationProvider.ShowWarningQuestion($"'{item.Name}' already exists on '{Path.GetDirectoryName(destination)}'. Do you want to overwrite?"))
+ {
+ continue;
+ }
+ }
+
+ var handler = await FileSystemProvider.Download(item, destination);
+ FileSystemHandlers.Insert(0, handler);
+ }
+ }
+ }
+
+ private async void RenameFileSystemItem(FileSystemItem item)
+ {
+ if (item.Type != FileSystemItemType.Drive)
+ {
+ var result = await NotificationProvider.ShowInputBox(
+ "Rename",
+ $"Please enter a new {(item.Type == FileSystemItemType.File ? "file" : "folder")} name and press 'ENTER'.",
+ PackIconKind.Rename, item.Name,
+ $"{(item.Type == FileSystemItemType.File ? "file" : "folder")} name",
+ 100,
+ "RENAME");
+
+ if (result.Confirmed && result.Input != item.Name)
+ {
+ try
+ {
+ using (NotificationProvider.PushTaskItem("Renaming..."))
+ {
+ await FileSystemProvider.Rename(item, result.Input);
+ item.Path = Path.Combine(Path.GetDirectoryName(item.Path), result.Input);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error renaming '{item.Path}' to {result.Input}.");
+ await NotificationProvider.ShowError($"Error renaming '{item.Name}'.\n{ex.FlattenMessage()}");
+ }
+ }
+ }
+ }
+
+ private async void CreateNewFolder()
+ {
+ if (CurrentItem == null) return;
+ if (CurrentItem is FolderItem)
+ {
+ if ((CurrentItem as FolderItem).IsRoot) return;
+ }
+
+ var result = await NotificationProvider.ShowInputBox(
+ "New Folder",
+ $"Please enter a folder name and press 'ENTER'.",
+ PackIconKind.FolderAdd, "untitled",
+ "folder name",
+ 100,
+ "CREATE");
+
+ if (result.Confirmed)
+ {
+ try
+ {
+ using (NotificationProvider.PushTaskItem("Creating new folder..."))
+ {
+ var folderItem = await FileSystemProvider.CreateFolder(CurrentItem, result.Input);
+ NavigateToCurrentPath(); //Instead of inserting folder item just refresh the current path...
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error creating new folder '{Path.Combine(CurrentItem.Path,result.Input)}.");
+ await NotificationProvider.ShowError($"Error creating folder '{result.Input}'.\n{ex.FlattenMessage()}");
+ }
+ }
+ }
+
private void OnCurrentItemChanged()
{
CurrentPath = CurrentItem.Path;
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/MainViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/MainViewVM.cs
index cd12bcdd9..5c73f70cc 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/MainViewVM.cs
@@ -13,6 +13,30 @@ namespace Tango.FSE.PPCConsole.ViewModels
{
public class MainViewVM : FSEViewModel
{
+ public enum NavigationView
+ {
+ ConsoleView,
+ RemoteDesktopView,
+ MonitoringView,
+ FileSystemView,
+ }
+
+ private NavigationView _selectedView;
+ public NavigationView SelectedView
+ {
+ get { return _selectedView; }
+ set
+ {
+ _selectedView = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+ }
+
public override void OnApplicationReady()
{
base.OnApplicationReady();
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
index f2ed84d8a..9c2b139d9 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
@@ -30,10 +30,16 @@ namespace Tango.FSE.PPCConsole.ViewModels
public RelayCommand StartCommand { get; set; }
public RelayCommand StopCommand { get; set; }
+ public RelayCommand OpenTaskManagerCommand { get; set; }
+
+ public RelayCommand HideAndOpenShellCommand { get; set; }
+
public RemoteDesktopViewVM()
{
StartCommand = new RelayCommand(StartRemoteDesktop);
StopCommand = new RelayCommand(StopRemoteDesktop);
+ OpenTaskManagerCommand = new RelayCommand(OpenTaskManager);
+ HideAndOpenShellCommand = new RelayCommand(HideAndOpenShell);
}
public override void OnApplicationStarted()
@@ -41,6 +47,12 @@ namespace Tango.FSE.PPCConsole.ViewModels
base.OnApplicationStarted();
RemoteDesktopProvider.FrameReceived += RemoteDesktopProvider_FrameReceived;
+ MachineProvider.MachineConnected += MachineProvider_MachineConnected;
+ }
+
+ private void MachineProvider_MachineConnected(object sender, Common.Connection.MachineConnectedEventArgs e)
+ {
+ Source = null;
}
private async void StartRemoteDesktop()
@@ -106,7 +118,7 @@ namespace Tango.FSE.PPCConsole.ViewModels
public void OnMouseMove(System.Windows.Point point, System.Windows.Size size)
{
- //RemoteDesktopProvider.MouseMove(point, size);
+ RemoteDesktopProvider.MouseMove(point, size);
}
public void OnMouseDoubleClick(MouseButton changedButton, System.Windows.Point point, System.Windows.Size size)
@@ -116,12 +128,27 @@ namespace Tango.FSE.PPCConsole.ViewModels
public void OnKeyboardDown(Key key, bool ctrlDown, bool shitDown, bool altDown)
{
- throw new NotImplementedException();
+ RemoteDesktopProvider.KeyboardDown(key, ctrlDown, shitDown, altDown);
}
public void OnKeyboardUp(Key key, bool ctrlDown, bool shitDown, bool altDown)
{
- throw new NotImplementedException();
+ RemoteDesktopProvider.KeyboardUp(key, ctrlDown, shitDown, altDown);
+ }
+
+ #endregion
+
+ #region Remote Actions
+
+ private void OpenTaskManager()
+ {
+ RemoteDesktopProvider.KeyboardDown(Key.Escape, true, true, false);
+ RemoteDesktopProvider.KeyboardDown(Key.Escape, false, false, false);
+ }
+
+ private void HideAndOpenShell()
+ {
+ RemoteDesktopProvider.SendCommand(RemoteDesktopCommand.HideAndOpenShell);
}
#endregion