diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-11-25 08:51:51 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-11-25 08:51:51 +0200 |
| commit | c02a988bda6724dcbd1d689be2010ce55de59368 (patch) | |
| tree | f0e9bcc67c0db00fe04517b6bccbacb63a5214ac /Software/Visual_Studio/PPC/Tango.PPC.Common/Storage | |
| parent | 88a0169f624c77b77b21a871ace9e51a9245807d (diff) | |
| download | Tango-c02a988bda6724dcbd1d689be2010ce55de59368.tar.gz Tango-c02a988bda6724dcbd1d689be2010ce55de59368.zip | |
Storage Module!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Storage')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs | 48 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs | 20 |
2 files changed, 67 insertions, 1 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs index 5714f5dfb..46315e4b8 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Tango.Core; using Tango.Core.DI; +using Tango.Explorer; using Tango.PPC.Common.Application; using Tango.PPC.Common.Threading; @@ -20,6 +21,7 @@ namespace Tango.PPC.Common.Storage public class DefaultStorageProvider : ExtendedObject, IStorageProvider { private Thread _scanThread; + private Dictionary<String, Action<ExplorerFileItem>> _fileHandlers; /// <summary> /// Occurs when a new storage drive has been inserted. @@ -56,8 +58,9 @@ namespace Tango.PPC.Common.Storage /// </summary> public DefaultStorageProvider(IPPCApplicationManager applicationManager) { + _fileHandlers = new Dictionary<string, Action<ExplorerFileItem>>(); var drives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToList(); - + if (drives.Count > 0) { IsConnected = true; @@ -77,6 +80,49 @@ namespace Tango.PPC.Common.Storage Initialize(); } + /// <summary> + /// Registers a method for handling a file selection. + /// </summary> + /// <param name="extension">The file extension.</param> + /// <param name="handler">The handler.</param> + /// <exception cref="System.InvalidOperationException">Cannot register multiple file handlers for the same extension.</exception> + public void RegisterFileHandler(string extension, Action<ExplorerFileItem> handler) + { + if (_fileHandlers.ContainsKey(extension)) + { + throw new InvalidOperationException("Cannot register multiple file handlers for the same extension."); + } + _fileHandlers.Add(extension, handler); + } + + /// <summary> + /// Unregisters the file handler. + /// </summary> + /// <param name="handler">The handler.</param> + public void UnregisterFileHandler(Action<ExplorerFileItem> handler) + { + var h = _fileHandlers.SingleOrDefault(x => x.Value == handler); + + if (h.Key != null) + { + _fileHandlers.Remove(h.Key); + } + } + + /// <summary> + /// Submits a file selection. + /// </summary> + /// <param name="fileItem">The file item.</param> + public void SubmitFileSelection(ExplorerFileItem fileItem) + { + String extension = Path.GetExtension(fileItem.Path); + + if (_fileHandlers.ContainsKey(extension)) + { + _fileHandlers[extension].Invoke(fileItem); + } + } + private void Initialize() { _scanThread = new Thread(ScanThreadMethod); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs index 164cdfe0a..902021002 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Explorer; namespace Tango.PPC.Common.Storage { @@ -31,5 +32,24 @@ namespace Tango.PPC.Common.Storage /// Gets the inserted storage drive information. /// </summary> DriveInfo Drive { get; } + + /// <summary> + /// Registers a method for handling a file selection. + /// </summary> + /// <param name="extension">The file extension.</param> + /// <param name="handler">The handler.</param> + void RegisterFileHandler(String extension, Action<ExplorerFileItem> handler); + + /// <summary> + /// Unregisters the file handler. + /// </summary> + /// <param name="handler">The handler.</param> + void UnregisterFileHandler(Action<ExplorerFileItem> handler); + + /// <summary> + /// Submits a file selection. + /// </summary> + /// <param name="fileItem">The file item.</param> + void SubmitFileSelection(ExplorerFileItem fileItem); } } |
