aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs')
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs105
1 files changed, 96 insertions, 9 deletions
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 e10cc0ad1..3a4a87884 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
@@ -9,6 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Tango.Core.Commands;
+using Tango.Core.Helpers;
using Tango.FileSystem;
using Tango.FSE.Common;
using Tango.FSE.Common.Connection;
@@ -57,6 +58,7 @@ namespace Tango.FSE.PPCConsole.ViewModels
public RelayCommand<List<FileSystemItem>> CopyPasteCommand { get; set; }
public RelayCommand<List<FileSystemItem>> CutPasteCommand { get; set; }
public RelayCommand<List<FileSystemItem>> DownloadCommand { get; set; }
+ public RelayCommand UploadCommand { get; set; }
public RelayCommand<FileSystemItem> RenameCommand { get; set; }
public RelayCommand NewFolderCommand { get; set; }
@@ -72,6 +74,7 @@ namespace Tango.FSE.PPCConsole.ViewModels
NavigateToFolderCommand = new RelayCommand<string>(async (x) => await Navigate(x));
DeleteCommand = new RelayCommand<IList<FileSystemItem>>(DeleteSelectedItems);
DragCommand = new RelayCommand<List<DragItem>>(OnItemsDraggedOut);
+ DropCommand = new RelayCommand<List<FileSystemItem>>(OnItemsDroppedIn);
DeleteFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(DeleteFileSystemHandler);
OpenFileSystemHandlerDestinationCommand = new RelayCommand<FileSystemHandler>(OpenFileSystemHandlerDestination);
RetryFailedFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(RetryFailedFileSystemHandler);
@@ -80,6 +83,7 @@ namespace Tango.FSE.PPCConsole.ViewModels
DownloadCommand = new RelayCommand<List<FileSystemItem>>(DownloadSelectedItems);
RenameCommand = new RelayCommand<FileSystemItem>(RenameFileSystemItem);
NewFolderCommand = new RelayCommand(CreateNewFolder);
+ UploadCommand = new RelayCommand(UploadFilesAndFolder);
}
private async void NavigateBack()
@@ -114,9 +118,12 @@ namespace Tango.FSE.PPCConsole.ViewModels
}
}
- private async void NavigateToCurrentPath()
+ private void NavigateToCurrentPath()
{
- await Navigate(CurrentPath);
+ InvokeUI(async () =>
+ {
+ await Navigate(CurrentPath);
+ });
}
private async void OpenFileSystemItem(FileSystemItem item)
@@ -195,6 +202,36 @@ namespace Tango.FSE.PPCConsole.ViewModels
}
}
+ private async void OnItemsDroppedIn(List<FileSystemItem> items)
+ {
+ String currentPathBefore = CurrentPath;
+
+ foreach (var item in items.Where(x => x.Type != FileSystemItemType.Drive))
+ {
+ Debug.WriteLine($"Dropped in: {item.Name} => {CurrentItem.Path}");
+
+ if ((CurrentItem as IFileSystemContainer).Items.ToList().Exists(x => x.Name.ToLower() == item.Name.ToLower()))
+ {
+ if (!await NotificationProvider.ShowWarningQuestion($"'{item.Name}' already exists on '{CurrentItem.Name}'. Do you want to overwrite?"))
+ {
+ continue;
+ }
+ }
+
+ var handler = await FileSystemProvider.Upload(item.Path, CurrentItem);
+
+ handler.StatusChanged += (x, status) =>
+ {
+ if (status == FileSystemHandlerStatus.Completed && currentPathBefore == CurrentPath)
+ {
+ NavigateToCurrentPath();
+ }
+ };
+
+ FileSystemHandlers.Insert(0, handler);
+ }
+ }
+
private async void DeleteFileSystemHandler(FileSystemHandler handler)
{
if (handler.Status != FileSystemHandlerStatus.Completed && handler.Status != FileSystemHandlerStatus.Failed)
@@ -216,19 +253,26 @@ namespace Tango.FSE.PPCConsole.ViewModels
}
}
- private void OpenFileSystemHandlerDestination(FileSystemHandler handler)
+ private async void OpenFileSystemHandlerDestination(FileSystemHandler handler)
{
String destination = String.Empty;
- if (File.Exists(handler.Destination) || Directory.Exists(handler.Destination))
+ if (handler.Type == FileSystemHandlerType.FileDownload || handler.Type == FileSystemHandlerType.FolderDownload)
{
- destination = handler.Destination;
- Process.Start("explorer.exe", string.Format("/select,\"{0}\"", destination));
+ if (File.Exists(handler.Destination) || Directory.Exists(handler.Destination))
+ {
+ destination = handler.Destination;
+ Process.Start("explorer.exe", string.Format("/select,\"{0}\"", destination));
+ }
+ else
+ {
+ destination = Path.GetDirectoryName(handler.Destination);
+ Process.Start("explorer.exe", destination);
+ }
}
else
{
- destination = Path.GetDirectoryName(handler.Destination);
- Process.Start("explorer.exe", destination);
+ await Navigate(Path.GetDirectoryName(handler.Destination));
}
}
@@ -364,6 +408,49 @@ namespace Tango.FSE.PPCConsole.ViewModels
}
}
+ private async void UploadFilesAndFolder()
+ {
+ var result = await StorageProvider.SelectFilesAndFolders("Select files and folders to upload");
+ if (result)
+ {
+ String currentPathBefore = CurrentPath;
+
+ foreach (var item in result.SelectedItems)
+ {
+ if (!File.Exists(item) && !Directory.Exists(item))
+ {
+ await NotificationProvider.ShowError($"File or folder '{item}' cannot be uploaded.");
+ return;
+ }
+ }
+
+ foreach (var item in result.SelectedItems)
+ {
+ String itemName = Path.GetFileName(item);
+
+ if ((CurrentItem as IFileSystemContainer).Items.ToList().Exists(x => x.Name.ToLower() == itemName.ToLower()))
+ {
+ if (!await NotificationProvider.ShowWarningQuestion($"'{itemName}' already exists on '{CurrentItem.Name}'. Do you want to overwrite?"))
+ {
+ continue;
+ }
+ }
+
+ var handler = await FileSystemProvider.Upload(item, CurrentItem);
+
+ handler.StatusChanged += (x, status) =>
+ {
+ if (status == FileSystemHandlerStatus.Completed && currentPathBefore == CurrentPath)
+ {
+ NavigateToCurrentPath();
+ }
+ };
+
+ FileSystemHandlers.Insert(0, handler);
+ }
+ }
+ }
+
private async void RenameFileSystemItem(FileSystemItem item)
{
if (item.Type != FileSystemItemType.Drive)
@@ -423,7 +510,7 @@ namespace Tango.FSE.PPCConsole.ViewModels
}
catch (Exception ex)
{
- LogManager.Log(ex, $"Error creating new folder '{Path.Combine(CurrentItem.Path,result.Input)}.");
+ LogManager.Log(ex, $"Error creating new folder '{Path.Combine(CurrentItem.Path, result.Input)}.");
await NotificationProvider.ShowError($"Error creating folder '{result.Input}'.\n{ex.FlattenMessage()}");
}
}