diff options
Diffstat (limited to 'Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs index f9f08c6a4..6eb05b70d 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/FileSystem/DefaultFileSystemProvider.cs @@ -4,6 +4,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Threading; @@ -63,46 +64,26 @@ namespace Tango.FSE.UI.FileSystem return FileSystemItem.FromDTO(response.FileSystemItem) as IFileSystemContainer; } - public async Task<FileSystemHandler> Download(FileSystemItem item, string localTargetFolder) + public Task<FileSystemHandler> Download(FileSystemItem item, string localTargetFolder) { String operationId = String.Empty; String destination = String.Empty; long downloadLength = 0; + bool aborted = false; + + FileSystemHandler handler = null; if (item.Type == FileSystemItemType.File) { destination = Path.Combine(localTargetFolder, item.Name); - - var response = await _machineProvider.MachineOperator.SendGenericRequest<FileDownloadRequest, FileDownloadResponse>( - new FileDownloadRequest() - { - Path = item.Path - }, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(20) }); - - operationId = response.OperationId; - downloadLength = response.Length; } - else if (item.Type == FileSystemItemType.Folder) + else if (item.Type == FileSystemItemType.File) { destination = Path.Combine(localTargetFolder, item.Name); - - var response = await _machineProvider.MachineOperator.SendGenericRequest<FolderDownloadRequest, FolderDownloadResponse>( - new FolderDownloadRequest() - { - Path = item.Path - }, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(20) }); - - operationId = response.OperationId; - downloadLength = response.Length; - } - else - { - throw new NotSupportedException("The requested file system item is not supported for downloading."); } - bool aborted = false; - FileSystemHandler handler = new FileSystemHandler(item.Name, destination, async () => + handler = new FileSystemHandler(item, destination, async () => { if (!aborted) { @@ -119,25 +100,73 @@ namespace Tango.FSE.UI.FileSystem { LogManager.Log(ex, "Error aborting the download operation."); } + finally + { + handler.RaiseAborted(); + } } }); - long position = 0; - ThreadFactory.StartNew(async () => { + try + { + if (item.Type == FileSystemItemType.File) + { + var response = await _machineProvider.MachineOperator.SendGenericRequest<FileDownloadRequest, FileDownloadResponse>( + new FileDownloadRequest() + { + Path = item.Path + }, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(20) }); + + operationId = response.OperationId; + downloadLength = response.Length; + handler.OperationId = operationId; + } + else if (item.Type == FileSystemItemType.Folder) + { + var response = await _machineProvider.MachineOperator.SendGenericRequest<FolderDownloadRequest, FolderDownloadResponse>( + new FolderDownloadRequest() + { + Path = item.Path + }, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(60) }); + + operationId = response.OperationId; + downloadLength = response.Length; + handler.OperationId = operationId; + } + else + { + throw new NotSupportedException("The requested file system item is not supported for downloading."); + } + } + catch (Exception ex) + { + handler.RaiseFailed(ex); + return; + } + + long position = 0; + var tempFile = TemporaryManager.CreateFile(); while (position < downloadLength && !aborted) { + if (handler.IsPaused) + { + Thread.Sleep(1000); + continue; + } + try { var response = await _machineProvider.MachineOperator.SendGenericRequest<ChunkDownloadRequest, ChunkDownloadResponse>( new ChunkDownloadRequest() { + MaxChunkSize = 1024 * 10, OperationId = operationId, Position = position, - }); + }, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(30), Priority = QueuePriority.Low }); using (FileStream fs = new FileStream(tempFile, FileMode.Append)) { @@ -176,7 +205,7 @@ namespace Tango.FSE.UI.FileSystem handler.RaiseCompleted(); }); - return handler; + return Task.FromResult(handler); } public Task<FileSystemHandler> Upload(string sourcePath, string remoteTargetFolder) |
