From 9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 29 Nov 2018 13:15:09 +0200 Subject: Working on machine studio storage module. --- .../Tango.Integration/Storage/StorageDrive.cs | 4 ++-- .../Tango.Integration/Storage/StorageFile.cs | 2 +- .../Storage/StorageFileHandler.cs | 23 ++++++++++++++++++++-- .../Storage/StorageFileHandlerStatus.cs | 17 ++++++++++++++++ .../Tango.Integration/Storage/StorageItem.cs | 15 +++++++++++++- .../Tango.Integration/Storage/StorageManager.cs | 23 +++++++++++----------- 6 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandlerStatus.cs (limited to 'Software/Visual_Studio/Tango.Integration/Storage') diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageDrive.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageDrive.cs index c313ac0cb..28f390bc9 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageDrive.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageDrive.cs @@ -9,8 +9,8 @@ namespace Tango.Integration.Storage { public class StorageDrive : ExtendedObject { - public int Capacity { get; set; } - public int FreeSpace { get; set; } + public long Capacity { get; set; } + public long FreeSpace { get; set; } public String Root { get; set; } } } diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageFile.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageFile.cs index 069b1743d..06c966649 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageFile.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageFile.cs @@ -9,6 +9,6 @@ namespace Tango.Integration.Storage { public class StorageFile : StorageItem { - public int Length { get; set; } + public long Length { get; set; } } } diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandler.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandler.cs index 72a4b2c87..6a9c5cae4 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandler.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandler.cs @@ -21,9 +21,19 @@ namespace Tango.Integration.Storage } - internal StorageFileHandler(Action cancelAction) + internal StorageFileHandler(StorageFile storageFile, Action cancelAction) { _cancelAction = cancelAction; + StorageFile = storageFile; + } + + public StorageFile StorageFile { get; set; } + + private StorageFileHandlerStatus _status; + public StorageFileHandlerStatus Status + { + get { return _status; } + private set { _status = value; RaisePropertyChangedAuto(); } } private long _current; @@ -38,6 +48,11 @@ namespace Tango.Integration.Storage Current = _current, Total = _total, }); + + if (Status != StorageFileHandlerStatus.Active) + { + Status = StorageFileHandlerStatus.Active; + } } } @@ -53,21 +68,25 @@ namespace Tango.Integration.Storage return Task.Factory.StartNew(() => { _cancelAction.Invoke(); - }); + Status = StorageFileHandlerStatus.Canceled; + }); } internal void RaiseCompleted() { + Status = StorageFileHandlerStatus.Completed; Completed?.Invoke(this, new EventArgs()); } internal void RaiseCanceled() { + Status = StorageFileHandlerStatus.Canceled; Canceled?.Invoke(this, new EventArgs()); } internal void RaiseFailed(Exception ex) { + Status = StorageFileHandlerStatus.Failed; Failed?.Invoke(this, ex); } } diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandlerStatus.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandlerStatus.cs new file mode 100644 index 000000000..7fb30dd16 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageFileHandlerStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Storage +{ + public enum StorageFileHandlerStatus + { + Pending, + Active, + Canceled, + Failed, + Completed, + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageItem.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageItem.cs index e8a725277..3881dd528 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageItem.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageItem.cs @@ -26,8 +26,21 @@ namespace Tango.Integration.Storage { get { + String root = System.IO.Path.GetPathRoot(Path); var parent = Directory.GetParent(Path); - return parent.FullName.Replace(parent.Root.FullName, "/").Replace("\\", "/"); + + if (root == "\\") + { + return parent.FullName.Replace(parent.Root.FullName, "/").Replace("\\", "/"); + } + else if (parent != null) + { + return parent.FullName; + } + else + { + return null; + } } } diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs index bb880f1bd..d640ba0c6 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs @@ -213,10 +213,14 @@ namespace Tango.Integration.Storage long max_length = fileUploadResponse.Message.MaxChunkLength; bool canceled = false; - StorageFileHandler handler = new StorageFileHandler(() => + StorageFileHandler handler = new StorageFileHandler(new StorageFile() { - canceled = true; - }); + Path = path, + Length = (int)stream.Length, + }, () => + { + canceled = true; + }); handler.Total = stream.Length; @@ -284,10 +288,10 @@ namespace Tango.Integration.Storage long max_length = fileDownloadResponse.Message.MaxChunkLength; bool canceled = false; - StorageFileHandler handler = new StorageFileHandler(() => - { - canceled = true; - }); + StorageFileHandler handler = new StorageFileHandler(file, () => + { + canceled = true; + }); handler.Total = file.Length; @@ -320,11 +324,6 @@ namespace Tango.Integration.Storage } else { - var a = _transporter.SendRequest(new FileChunkDownloadRequest() - { - IsCanceled = true, - }).Result; - handler.RaiseCanceled(); return; } -- cgit v1.3.1