aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs152
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml16
2 files changed, 150 insertions, 18 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs
index 1c6371f43..12bb8242a 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Win32;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@@ -36,7 +37,7 @@ namespace Tango.MachineStudio.Storage.ViewModels
public StorageItem SelectedStorageItem
{
get { return _selectedStorageItem; }
- set { _selectedStorageItem = value; RaisePropertyChangedAuto(); }
+ set { _selectedStorageItem = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private String _currentPath;
@@ -46,6 +47,8 @@ namespace Tango.MachineStudio.Storage.ViewModels
set { _currentPath = value; RaisePropertyChangedAuto(); }
}
+ public ObservableCollection<StorageFileHandlerModel> FileHandlers { get; set; }
+
public RelayCommand BackCommand { get; set; }
public RelayCommand RefreshCommand { get; set; }
@@ -58,7 +61,15 @@ namespace Tango.MachineStudio.Storage.ViewModels
public RelayCommand<StorageFileHandlerModel> RemoveFileHandlerCommand { get; set; }
- public ObservableCollection<StorageFileHandlerModel> FileHandlers { get; set; }
+ public RelayCommand DownloadFileCommand { get; set; }
+
+ public RelayCommand DeleteFileCommand { get; set; }
+
+ public RelayCommand CreateFolderCommand { get; set; }
+
+ public RelayCommand DeleteFolderCommand { get; set; }
+
+ public RelayCommand UploadFileCommand { get; set; }
public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider)
{
@@ -74,6 +85,89 @@ namespace Tango.MachineStudio.Storage.ViewModels
OpenFileHandlerCommand = new RelayCommand<StorageFileHandlerModel>(OpenFileHandler);
RefreshCommand = new RelayCommand(Refresh, () => StorageManager != null);
RemoveFileHandlerCommand = new RelayCommand<StorageFileHandlerModel>(RemoveFileHandler);
+ DownloadFileCommand = new RelayCommand(DownloadFile, () => StorageManager != null && SelectedStorageItem != null && SelectedStorageItem is StorageFile);
+ DeleteFileCommand = new RelayCommand(DeleteFile, () => StorageManager != null && SelectedStorageItem != null && SelectedStorageItem is StorageFile);
+ CreateFolderCommand = new RelayCommand(CreateFolder, () => StorageManager != null && StorageManager.CurrentFolder != null);
+ DeleteFolderCommand = new RelayCommand(DeleteFolder, () => StorageManager != null && SelectedStorageItem != null && SelectedStorageItem is StorageFolder);
+ UploadFileCommand = new RelayCommand(UploadFile, () => StorageManager != null && StorageManager.CurrentFolder != null);
+ }
+
+ private void UploadFile()
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Title = "Selected a file to upload";
+ if (dlg.ShowDialog().Value)
+ {
+ UploadFile(dlg.FileName);
+ }
+ }
+
+ private async void DeleteFolder()
+ {
+ if (SelectedStorageItem == null) return;
+
+ if (_notification.ShowQuestion("Are you sure you want to delete the selected folder?"))
+ {
+ try
+ {
+ IsFree = false;
+ await StorageManager.DeleteItem(SelectedStorageItem);
+ Refresh();
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error deleting the selected folder.\n{ex.Message}");
+ }
+
+ IsFree = true;
+ }
+ }
+
+ private async void CreateFolder()
+ {
+ try
+ {
+ var name = _notification.ShowTextInput("Enter Folder Name", "");
+
+ if (!String.IsNullOrWhiteSpace(name))
+ {
+ IsFree = false;
+ await StorageManager.CreateFolder(Path.Combine(StorageManager.CurrentPath, name));
+ Refresh();
+ }
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error creating the new folder.\n{ex.Message}");
+ }
+
+ IsFree = true;
+ }
+
+ private async void DeleteFile()
+ {
+ if (SelectedStorageItem == null) return;
+
+ if (_notification.ShowQuestion("Are you sure you want to delete the selected file?"))
+ {
+ try
+ {
+ IsFree = false;
+ await StorageManager.DeleteItem(SelectedStorageItem);
+ Refresh();
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error deleting the selected file.\n{ex.Message}");
+ }
+
+ IsFree = true;
+ }
+ }
+
+ private void DownloadFile()
+ {
+ DownloadStorageItem(SelectedStorageItem as StorageFile);
}
private void OpenFileHandler(StorageFileHandlerModel handler)
@@ -112,7 +206,7 @@ namespace Tango.MachineStudio.Storage.ViewModels
}
}
- private async void NavigateToPath(String path)
+ private async void NavigateToPath(String path, bool raiseEvent = true)
{
IsFree = false;
@@ -120,7 +214,11 @@ namespace Tango.MachineStudio.Storage.ViewModels
{
await StorageManager.GetFolder(path);
CurrentPath = StorageManager.CurrentPath;
- CurrentFolderChanged?.Invoke(this, new EventArgs());
+
+ if (raiseEvent)
+ {
+ CurrentFolderChanged?.Invoke(this, new EventArgs());
+ }
}
catch (Exception ex)
{
@@ -171,16 +269,44 @@ namespace Tango.MachineStudio.Storage.ViewModels
private void Refresh()
{
- NavigateToPath(StorageManager.CurrentFolder.Path);
+ NavigateToPath(StorageManager.CurrentFolder.Path, false);
}
private async void DownloadStorageItem(StorageFile storageFile)
{
- var downloadsFolder = KnownFolders.GetPath(KnownFolder.Downloads);
- var file = Path.Combine(downloadsFolder, storageFile.Name);
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Title = "Select download location";
+ dlg.DefaultExt = Path.GetExtension(storageFile.Path);
+ dlg.FileName = storageFile.Name;
+ if (dlg.ShowDialog().Value)
+ {
+ FileStream fs = new FileStream(dlg.FileName, FileMode.Create);
+ var handler = await StorageManager.DownloadFile(storageFile, fs);
+ handler.Completed += (_, __) =>
+ {
+ fs.Dispose();
+ };
- FileStream fs = new FileStream(Path.Combine(downloadsFolder, storageFile.Name), FileMode.Create);
- var handler = await StorageManager.DownloadFile(storageFile, fs);
+ handler.Canceled += (_, __) =>
+ {
+ fs.Dispose();
+ File.Delete(dlg.FileName);
+ };
+
+ handler.Failed += (_, __) =>
+ {
+ fs.Dispose();
+ File.Delete(dlg.FileName);
+ };
+
+ FileHandlers.Insert(0, new StorageFileHandlerModel(handler, dlg.FileName, StorageFileHandlerType.Download));
+ }
+ }
+
+ private async void UploadFile(String path)
+ {
+ FileStream fs = new FileStream(path, FileMode.Open);
+ var handler = await StorageManager.UploadFile(Path.Combine(StorageManager.CurrentPath, Path.GetFileName(path)), fs);
handler.Completed += (_, __) =>
{
fs.Dispose();
@@ -189,16 +315,16 @@ namespace Tango.MachineStudio.Storage.ViewModels
handler.Canceled += (_, __) =>
{
fs.Dispose();
- File.Delete(file);
+ File.Delete(path);
};
handler.Failed += (_, __) =>
{
fs.Dispose();
- File.Delete(file);
+ File.Delete(path);
};
- FileHandlers.Insert(0, new StorageFileHandlerModel(handler, file, StorageFileHandlerType.Download));
+ FileHandlers.Insert(0, new StorageFileHandlerModel(handler, path, StorageFileHandlerType.Upload));
}
/// <summary>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml
index a4a5c2946..311d18f54 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml
@@ -29,27 +29,33 @@
<DockPanel>
<TextBlock HorizontalAlignment="Left" DockPanel.Dock="Top" Margin="30 55 20 20" FontSize="30" FontStyle="Italic" Foreground="{StaticResource AccentColorBrush}" FontWeight="Bold">ACTIONS</TextBlock>
<StackPanel Margin="0 40 0 0">
- <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <Button Command="{Binding CreateFolderCommand}" Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
<DockPanel>
<materialDesign:PackIcon Kind="FolderPlus" Foreground="#E79F20" Width="32" Height="32" />
<TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">CREATE FOLDER</TextBlock>
</DockPanel>
</Button>
+ <Button Command="{Binding DeleteFolderCommand}" Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="FolderRemove" Foreground="#E14141" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">DELETE FOLDER</TextBlock>
+ </DockPanel>
+ </Button>
<Separator/>
- <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <Button Command="{Binding UploadFileCommand}" Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
<DockPanel>
<materialDesign:PackIcon Kind="Upload" Foreground="#E97E28" Width="32" Height="32" />
<TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">UPLOAD FILE</TextBlock>
</DockPanel>
</Button>
- <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <Button Command="{Binding DownloadFileCommand}" Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
<DockPanel>
<materialDesign:PackIcon Kind="Download" Foreground="#2DD42D" Width="32" Height="32" />
<TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">DOWNLOAD FILE</TextBlock>
</DockPanel>
</Button>
<Separator/>
- <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <Button Command="{Binding DeleteFileCommand}" Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
<DockPanel>
<materialDesign:PackIcon Kind="Delete" Foreground="#E14141" Width="32" Height="32" />
<TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">DELETE FILE</TextBlock>
@@ -75,7 +81,7 @@
</DockPanel>
</Button>
<Separator/>
- <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <Button Command="{Binding RefreshCommand}" Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
<DockPanel>
<materialDesign:PackIcon Kind="Refresh" Foreground="{StaticResource AccentColorBrush}" Width="32" Height="32" />
<TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">REFRESH</TextBlock>