From d0dba9752d0a8e787d9ae1d4d25542bd4b386df6 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 20 Mar 2020 04:03:05 +0200 Subject: Implemented priority queues for Transport Layer. Working on file/folder download. --- .../FileSystem/DefaultFileSystemService.cs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs index ffbba2e7a..804ad0036 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.DI; +using Tango.Core.IO; using Tango.FileSystem; using Tango.FileSystem.Network; using Tango.Integration.ExternalBridge; @@ -29,6 +30,7 @@ namespace Tango.PPC.Common.FileSystem public FileSystemOperationMode Mode { get; set; } public String Id { get; set; } public String Path { get; set; } + public bool IsPathTempZip { get; set; } public FileSystemOperation(FileSystemOperationMode mode, String path) { @@ -109,6 +111,38 @@ namespace Tango.PPC.Common.FileSystem } } + [ExternalBridgeRequestHandlerMethod(typeof(FolderDownloadRequest))] + public async void OnFolderDownloadRequest(FolderDownloadRequest request, String token, ExternalBridgeReceiver receiver) + { + try + { + if (!Directory.Exists(request.Path)) + { + await receiver.SendErrorResponse(new FileNotFoundException("Could not find the specified directory."), token); + return; + } + + var tempFile = TemporaryManager.CreateImaginaryFile(); + + ZipFile.CreateFromDirectory(request.Path, tempFile); + + FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Download, tempFile); + operation.IsPathTempZip = true; + + _operations.Add(operation.Id, operation); + + await receiver.SendGenericResponse(new FileDownloadResponse() + { + OperationId = operation.Id, + Length = new FileInfo(request.Path).Length + }, token); + } + catch (Exception ex) + { + await receiver.SendErrorResponse(ex, token); + } + } + [ExternalBridgeRequestHandlerMethod(typeof(ChunkUploadRequest))] public async void OnChunkUploadRequest(ChunkUploadRequest request, String token, ExternalBridgeReceiver receiver) { @@ -185,6 +219,13 @@ namespace Tango.PPC.Common.FileSystem Directory.Delete(operation.Path, true); } } + else if (operation.IsPathTempZip) + { + if (File.Exists(operation.Path)) + { + File.Delete(operation.Path); + } + } await receiver.SendGenericResponse(new AbortOperationResponse(), token); } -- cgit v1.3.1