From a9c3aaed4d5c007f138bfc16f05aecdee73f1268 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 21 Nov 2018 16:24:37 +0200 Subject: Working on PPC Storage Provider !!! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes Software/Graphics/Mobile/flash-drive.png | Bin 0 -> 1377 bytes .../Tango.PPC.Common/Navigation/NavigationView.cs | 1 + .../PPC/Tango.PPC.Common/PPCViewModel.cs | 7 ++ .../Storage/DefaultStorageProvider.cs | 111 +++++++++++++++++++++ .../Tango.PPC.Common/Storage/IStorageProvider.cs | 35 +++++++ .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 4 +- .../PPC/Tango.PPC.UI/Images/flash-drive.png | Bin 0 -> 1377 bytes .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 15 ++- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 12 +++ .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 12 +++ .../PPC/Tango.PPC.UI/ViewModels/StorageViewVM.cs | 97 ++++++++++++++++++ .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 24 +++-- .../PPC/Tango.PPC.UI/Views/MainView.xaml | 13 +++ .../PPC/Tango.PPC.UI/Views/StorageView.xaml | 33 ++++++ .../PPC/Tango.PPC.UI/Views/StorageView.xaml.cs | 28 ++++++ .../Tango.Explorer/ExplorerControl.cs | 23 ++++- 18 files changed, 403 insertions(+), 12 deletions(-) create mode 100644 Software/Graphics/Mobile/flash-drive.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/flash-drive.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/StorageViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml.cs diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 775d76141..7a6f9c9b5 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 2907879e7..d6d01a0ab 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Graphics/Mobile/flash-drive.png b/Software/Graphics/Mobile/flash-drive.png new file mode 100644 index 000000000..252e42e38 Binary files /dev/null and b/Software/Graphics/Mobile/flash-drive.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs index ef8f1c2ad..c86cf148b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs @@ -17,6 +17,7 @@ namespace Tango.PPC.Common.Navigation MachineSetupView, MachineUpdateView, ExternalBridgeView, + StorageView, HomeModule, ShutdownView, } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs index fdcaa9830..3393689d1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs @@ -13,6 +13,7 @@ using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Printing; +using Tango.PPC.Common.Storage; using Tango.Settings; using Tango.SharedUI; using static Tango.SharedUI.Controls.NavigationControl; @@ -81,6 +82,12 @@ namespace Tango.PPC.Common [TangoInject] public IConnectivityProvider ConnectivityProvider { get; set; } + /// + /// Gets or sets the storage provider. + /// + [TangoInject] + public IStorageProvider StorageProvider { get; set; } + private PPCSettings _settings; /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs new file mode 100644 index 000000000..5714f5dfb --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.DI; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.Threading; + +namespace Tango.PPC.Common.Storage +{ + /// + /// Represents the default . + /// + /// + /// + public class DefaultStorageProvider : ExtendedObject, IStorageProvider + { + private Thread _scanThread; + + /// + /// Occurs when a new storage drive has been inserted. + /// + public event EventHandler StorageConnected; + + /// + /// Occurs when a storage drive has been removed. + /// + public event EventHandler StorageDisconnected; + + private bool _isConnected; + /// + /// Gets a value indicating whether a storage drive is currently inserted. + /// + public bool IsConnected + { + get { return _isConnected; } + set { _isConnected = value; RaisePropertyChangedAuto(); } + } + + private DriveInfo _drive; + /// + /// Gets the inserted storage drive information. + /// + public DriveInfo Drive + { + get { return _drive; } + set { _drive = value; RaisePropertyChangedAuto(); } + } + + /// + /// Initializes a new instance of the class. + /// + public DefaultStorageProvider(IPPCApplicationManager applicationManager) + { + var drives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToList(); + + if (drives.Count > 0) + { + IsConnected = true; + Drive = drives.FirstOrDefault(); + } + + applicationManager.ApplicationReady += ApplicationManager_ApplicationReady; + } + + /// + /// Handles the ApplicationReady event of the ApplicationManager. + /// + /// The source of the event. + /// The instance containing the event data. + private void ApplicationManager_ApplicationReady(object sender, EventArgs e) + { + Initialize(); + } + + private void Initialize() + { + _scanThread = new Thread(ScanThreadMethod); + _scanThread.IsBackground = true; + _scanThread.Start(); + } + + private void ScanThreadMethod() + { + while (true) + { + var drives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToList(); + + if (IsConnected && !drives.Exists(x => x.RootDirectory.FullName == Drive.RootDirectory.FullName)) + { + StorageDisconnected?.Invoke(this, Drive); + Drive = null; + IsConnected = false; + } + + if (!IsConnected && drives.Count > 0) + { + Drive = drives.FirstOrDefault(); + IsConnected = true; + StorageConnected?.Invoke(this, Drive); + } + + Thread.Sleep(5000); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs new file mode 100644 index 000000000..164cdfe0a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.Storage +{ + /// + /// Represents a storage provider responsible of notifying about flash drives connection/disconnection. + /// + public interface IStorageProvider + { + /// + /// Occurs when a new storage drive has been inserted. + /// + event EventHandler StorageConnected; + + /// + /// Occurs when a storage drive has been removed. + /// + event EventHandler StorageDisconnected; + + /// + /// Gets a value indicating whether a storage drive is currently inserted. + /// + bool IsConnected { get; } + + /// + /// Gets the inserted storage drive information. + /// + DriveInfo Drive { get; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index fbb0a048b..eb90bfd77 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -153,6 +153,8 @@ + + @@ -314,7 +316,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/flash-drive.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/flash-drive.png new file mode 100644 index 000000000..252e42e38 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/flash-drive.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 5e5d5aac2..466ff0587 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -135,6 +135,7 @@ + @@ -159,6 +160,9 @@ MachineUpdateView.xaml + + StorageView.xaml + Designer MSBuild:Compile @@ -215,6 +219,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + @@ -263,6 +271,10 @@ {b112d89a-a106-41ae-a0c1-4abc84c477f5} Tango.DragAndDrop + + {4399af76-db52-4cfb-8020-6f85bdb29fd5} + Tango.Explorer + {4206ac58-3b57-4699-8835-90bf6db01a61} Tango.Integration @@ -365,6 +377,7 @@ Tango.ColorLib.dll PreserveNewest + @@ -432,7 +445,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 57fae7791..47f4409f5 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -16,6 +16,7 @@ using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Printing; +using Tango.PPC.Common.Storage; using Tango.PPC.Common.Threading; using Tango.PPC.UI.Authentication; using Tango.PPC.UI.Connectivity; @@ -59,6 +60,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); @@ -75,6 +77,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); //TangoIOC.Default.Register(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); @@ -85,6 +88,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.GetInstance().ContentRendered += (_, __) => @@ -158,5 +162,13 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance(); } } + + public static StorageViewVM StorageViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } } } \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 7ac7db47d..76eda9ac0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -89,6 +89,11 @@ namespace Tango.PPC.UI.ViewModels /// Gets or sets the update command. /// public RelayCommand UpdateCommand { get; set; } + + /// + /// Gets or sets the storage command. + /// + public RelayCommand StorageCommand { get; set; } #endregion #region Constructors @@ -109,6 +114,13 @@ namespace Tango.PPC.UI.ViewModels { NavigationManager.NavigateTo(NavigationView.MachineUpdateView); TangoIOC.Default.GetInstance().CheckForUpdates(); + IsMenuOpened = false; + }); + + StorageCommand = new RelayCommand(() => + { + NavigationManager.NavigateTo(NavigationView.StorageView); + IsMenuOpened = false; }); } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/StorageViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/StorageViewVM.cs new file mode 100644 index 000000000..5b5167393 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/StorageViewVM.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Explorer; +using Tango.PPC.Common; + +namespace Tango.PPC.UI.ViewModels +{ + public class StorageViewVM : PPCViewModel + { + private String _currentPath; + public String CurrentPath + { + get { return _currentPath; } + set { _currentPath = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand CloseCommand { get; set; } + + public RelayCommand FileSelectedCommand { get; set; } + + public StorageViewVM() + { + CloseCommand = new RelayCommand(Close); + FileSelectedCommand = new RelayCommand(OnFileSelected); + } + + public override void OnApplicationStarted() + { + + } + + public override void OnApplicationReady() + { + base.OnApplicationReady(); + + StorageProvider.StorageConnected += StorageProvider_StorageConnected; + StorageProvider.StorageDisconnected += StorageProvider_StorageDisconnected; + } + + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + if (StorageProvider.Drive != null) + { + CurrentPath = StorageProvider.Drive.RootDirectory.FullName; + } + } + + private async void Close() + { + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.LayoutView); + } + + /// + /// Handles the storage connected event. + /// + /// The sender. + /// The drive info. + private void StorageProvider_StorageConnected(object sender, System.IO.DriveInfo e) + { + InvokeUI(async () => + { + if (await NotificationProvider.ShowQuestion("Disk Inserted. Do you want to browse?")) + { + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.StorageView); + } + }); + } + + /// + /// Handles the storage disconnected event. + /// + /// The sender. + /// The drive info. + private void StorageProvider_StorageDisconnected(object sender, System.IO.DriveInfo e) + { + InvokeUI(async () => + { + if (IsVisible) + { + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.LayoutView); + } + }); + } + + private async void OnFileSelected(ExplorerFileItem fileItem) + { + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.LayoutView); + await NotificationProvider.ShowInfo($"File Selected: {fileItem.Name}"); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 2db5f12b6..44a66d7f0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -62,12 +62,24 @@ - - - - Update - - + + + + + + Storage + + + + + + + + + Update + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index 4c3d38811..690022e64 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -57,6 +57,18 @@ + + + + + @@ -69,6 +81,7 @@ + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml new file mode 100644 index 000000000..aa7bdcf7d --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml.cs new file mode 100644 index 000000000..d558d08bf --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/StorageView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Views +{ + /// + /// Interaction logic for StorageView.xaml + /// + public partial class StorageView : UserControl + { + public StorageView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs b/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs index 6f276f184..0c713a7db 100644 --- a/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs +++ b/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs @@ -53,6 +53,14 @@ namespace Tango.Explorer public static readonly DependencyProperty BackCommandProperty = DependencyProperty.Register("BackCommand", typeof(RelayCommand), typeof(ExplorerControl), new PropertyMetadata(null)); + public RelayCommand FileSelectedCommand + { + get { return (RelayCommand)GetValue(FileSelectedCommandProperty); } + set { SetValue(FileSelectedCommandProperty, value); } + } + public static readonly DependencyProperty FileSelectedCommandProperty = + DependencyProperty.Register("FileSelectedCommand", typeof(RelayCommand), typeof(ExplorerControl), new PropertyMetadata(null)); + static ExplorerControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ExplorerControl), new FrameworkPropertyMetadata(typeof(ExplorerControl))); @@ -99,16 +107,23 @@ namespace Tango.Explorer CurrentFolder = folder; SelectedItem = null; } + else if (SelectedItem is ExplorerFileItem) + { + FileSelectedCommand?.Execute(SelectedItem); + } } } private void NavigateBack() { - var parentPath = CurrentFolder.GetParentPath(); - - if (parentPath != null) + if (CurrentFolder != null) { - CurrentFolder = ExplorerFolderItem.LoadFromPath(parentPath); + var parentPath = CurrentFolder.GetParentPath(); + + if (parentPath != null) + { + CurrentFolder = ExplorerFolderItem.LoadFromPath(parentPath); + } } } } -- cgit v1.3.1