diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-09 00:29:06 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-09 00:29:06 +0300 |
| commit | 5774f40b650a376e9b622dba9df6c43589b0d398 (patch) | |
| tree | 8d80f23cbb9cc264cc5be1bd82c52402eed612e6 /Software/Visual_Studio/PPC | |
| parent | 42391bb46aa9dda0f56a7909268a2cffdf36f1d8 (diff) | |
| download | Tango-5774f40b650a376e9b622dba9df6c43589b0d398.tar.gz Tango-5774f40b650a376e9b622dba9df6c43589b0d398.zip | |
Logs, Comments & General organization on FSE/PPC.
Several improvements.
Diffstat (limited to 'Software/Visual_Studio/PPC')
22 files changed, 477 insertions, 373 deletions
diff --git a/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/CefInstaller.cs b/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/CefInstaller.cs index b302bd1d4..a4ea5dc4f 100644 --- a/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/CefInstaller.cs +++ b/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/CefInstaller.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Tango.Core; using Tango.Core.Helpers; using Tango.PPC.Common.UpdatePackages; +using Tango.PPC.Shared.Updates; using Tango.Transport.Web; namespace Tango.PPC.Packages.CefInstaller diff --git a/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/Tango.PPC.Packages.CefInstaller.csproj b/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/Tango.PPC.Packages.CefInstaller.csproj index 9ade464ea..8e7ec8253 100644 --- a/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/Tango.PPC.Packages.CefInstaller.csproj +++ b/Software/Visual_Studio/PPC/Packages/Tango.PPC.Packages.CefInstaller/Tango.PPC.Packages.CefInstaller.csproj @@ -67,6 +67,11 @@ <Name>Tango.PPC.Common</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\..\Tango.PPC.Shared\Tango.PPC.Shared.csproj"> + <Project>{208c8bd8-72c6-4e3c-acaa-351091a2acc7}</Project> + <Name>Tango.PPC.Shared</Name> + <Private>False</Private> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/DefaultConsoleEngineService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/DefaultConsoleEngineService.cs index 4a9ee468a..94b677b18 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/DefaultConsoleEngineService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/DefaultConsoleEngineService.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Console; using Tango.Console.Network; +using Tango.Core; using Tango.Core.DI; using Tango.Integration.ExternalBridge; using Tango.PPC.Common.ExternalBridge; @@ -12,19 +13,40 @@ using Tango.Transport; namespace Tango.PPC.Common.Console { + /// <summary> + /// Represents the <see cref="IConsoleEngineService"/> default implementation + /// which listens to incoming console request by registering as a external bridge request handler. + /// </summary> + /// <seealso cref="Tango.PPC.Common.Console.IConsoleEngineService" /> + /// <seealso cref="Tango.Integration.ExternalBridge.IExternalBridgeRequestHandler" /> [TangoCreateWhenRegistered] - public class DefaultConsoleEngineService : IConsoleEngineService, IExternalBridgeRequestHandler + public class DefaultConsoleEngineService : ExtendedObject, IConsoleEngineService, IExternalBridgeRequestHandler { + /// <summary> + /// Gets or sets a value indicating whether this <see cref="IConsoleEngineService" /> is enabled. + /// </summary> public bool Enabled { get; set; } = true; + /// <summary> + /// Initializes a new instance of the <see cref="DefaultConsoleEngineService"/> class. + /// </summary> + /// <param name="externalBridge">The external bridge service instance.</param> public DefaultConsoleEngineService(IPPCExternalBridgeService externalBridge) { externalBridge.RegisterRequestHandler(this); } - [ExternalBridgeRequestHandlerMethod(typeof(GetCurrentDirectoryRequest))] - public async void OnGetCurrentDirectoryRequest(GetCurrentDirectoryRequest request, String token, ITransporter transporter) + /// <summary> + /// Handles <see cref="GetCurrentDirectoryRequest"/> requests. + /// </summary> + /// <param name="request">The request.</param> + /// <param name="token">The token.</param> + /// <param name="transporter">The transporter.</param> + [ExternalBridgeRequestHandlerMethod(typeof(GetCurrentDirectoryRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnGetCurrentDirectoryRequest(GetCurrentDirectoryRequest request, String token, ITransporter transporter) { + this.ThrowIfDisabled(); + await transporter.SendGenericResponse(new GetCurrentDirectoryResponse() { CurrentDirectory = Environment.CurrentDirectory, @@ -32,35 +54,39 @@ namespace Tango.PPC.Common.Console }, token); } - [ExternalBridgeRequestHandlerMethod(typeof(ConsoleCommandRequest))] - public async void OnConsoleCommandRequest(ConsoleCommandRequest request, String token, ITransporter transporter) + /// <summary> + /// Handles <see cref="ConsoleCommandRequest"/> requests. + /// </summary> + /// <param name="request">The request.</param> + /// <param name="token">The token.</param> + /// <param name="transporter">The transporter.</param> + [ExternalBridgeRequestHandlerMethod(typeof(ConsoleCommandRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnConsoleCommandRequest(ConsoleCommandRequest request, String token, ITransporter transporter) { - if (Enabled) + this.ThrowIfDisabled(); + + LogManager.Log($"{nameof(ConsoleCommandRequest)} received with command '{request.Command}'. Executing..."); + + ConsoleExecutionEngine engine = new ConsoleExecutionEngine(); + var result = await engine.Execute(request); + + LogManager.Log("Console command executed successfully."); + + await transporter.SendGenericResponse<ConsoleCommandResponse>(new ConsoleCommandResponse() { - try - { - ConsoleExecutionEngine engine = new ConsoleExecutionEngine(); - var result = await engine.Execute(request); - await transporter.SendGenericResponse<ConsoleCommandResponse>(new ConsoleCommandResponse() - { - Output = result.Output, - Suggestions = result.Suggestions, - WorkingFolder = result.WorkingFolder - }, token, new TransportResponseConfig() - { - Immediate = true, - }); - } - catch (Exception ex) - { - await transporter.SendErrorResponse(ex, token); - } - } + Output = result.Output, + Suggestions = result.Suggestions, + WorkingFolder = result.WorkingFolder + }, token); } + /// <summary> + /// Called when any of the external bridge clients (receivers) has disconnected. + /// </summary> + /// <param name="receiver">The receiver.</param> public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) { - + //Do nothing. } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/IConsoleEngineService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/IConsoleEngineService.cs index 612ff302b..18edb3629 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/IConsoleEngineService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Console/IConsoleEngineService.cs @@ -6,8 +6,11 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.Console { - public interface IConsoleEngineService + /// <summary> + /// Represents a command prompt console service which listens for incoming console requests. + /// </summary> + public interface IConsoleEngineService : IPPCService { - bool Enabled { get; set; } + } } 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 a7f77855a..02975a2b3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/DefaultFileSystemService.cs @@ -18,31 +18,15 @@ using Tango.WebRTC; namespace Tango.PPC.Common.FileSystem { + /// <summary> + /// Represents the <see cref="IFileSystemService"/> default implementation. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="Tango.PPC.Common.FileSystem.IFileSystemService" /> + /// <seealso cref="Tango.Integration.ExternalBridge.IExternalBridgeRequestHandler" /> [TangoCreateWhenRegistered] public class DefaultFileSystemService : ExtendedObject, IFileSystemService, IExternalBridgeRequestHandler { - private enum FileSystemOperationMode - { - Upload, - Download - } - - private class FileSystemOperation - { - public FileSystemOperationMode Mode { get; set; } - public String Id { get; set; } - public String Path { get; set; } - public bool IsPathTempZip { get; set; } - public String UploadPostPath { get; set; } - - public FileSystemOperation(FileSystemOperationMode mode, String path) - { - Mode = mode; - Id = Guid.NewGuid().ToString(); - Path = path; - } - } - private FileSystemManager _manager; private Dictionary<String, FileSystemOperation> _operations; private Dictionary<ExternalBridgeReceiver, BasicTransporter> _webRtcClients; @@ -58,9 +42,11 @@ namespace Tango.PPC.Common.FileSystem externalBridge.RegisterRequestHandler(this); } - [ExternalBridgeRequestHandlerMethod(typeof(InitWebRtcRequest))] - public async void OnInitWebRtcRequest(InitWebRtcRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(InitWebRtcRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnInitWebRtcRequest(InitWebRtcRequest request, String token, ExternalBridgeReceiver receiver) { + this.ThrowIfDisabled(); + try { if (!EnableWebRTC) @@ -69,15 +55,18 @@ namespace Tango.PPC.Common.FileSystem return; } + LogManager.Log("Initializing WebRTC channel for file system service."); + if (_webRtcClients.ContainsKey(receiver)) { _webRtcClients[receiver].Dispose(); } + LogManager.Log("Initializing WebRTC transport adapter on 'Passive' mode."); var webRtcAdapter = new WebRtcTransportAdapter(receiver, WebRtcTransportAdapterMode.Passive, request.DataChannelName); webRtcAdapter.Ready += (x, e) => { - LogManager.Log("File System via WebRTC is ready."); + LogManager.Log("The file system service WebRTC channel is ready."); }; BasicTransporter webRtcTransporter = new BasicTransporter(webRtcAdapter); @@ -87,199 +76,171 @@ namespace Tango.PPC.Common.FileSystem webRtcTransporter.RegisterRequestHandler<ChunkDownloadRequest>(WebRtcChunkDownloadRequestReceived); webRtcTransporter.RegisterRequestHandler<ChunkUploadRequest>(WebRtcChunkUploadRequestReceived); await webRtcTransporter.Connect(); + + LogManager.Log("Sending WebRTC initialization response..."); + await receiver.SendGenericResponse(new InitWebRtcResponse(), token); _webRtcClients[receiver] = webRtcTransporter; } catch (Exception ex) { + LogManager.Log(ex, "Error initializing WebRTC channel for file system service."); await receiver.SendErrorResponse(ex, token); } } - private void WebRtcChunkDownloadRequestReceived(ITransporter transporter, ChunkDownloadRequest request, string token) + private async void WebRtcChunkDownloadRequestReceived(ITransporter transporter, ChunkDownloadRequest request, string token) { - OnChunkDownloadRequest(request, token, transporter); + await OnChunkDownloadRequest(request, token, transporter); } - private void WebRtcChunkUploadRequestReceived(ITransporter transporter, ChunkUploadRequest request, string token) + private async void WebRtcChunkUploadRequestReceived(ITransporter transporter, ChunkUploadRequest request, string token) { - OnChunkUploadRequest(request, token, transporter); + await OnChunkUploadRequest(request, token, transporter); } - [ExternalBridgeRequestHandlerMethod(typeof(GetFileSystemItemRequest))] - public async void OnGetFileSystemItemRequest(GetFileSystemItemRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(GetFileSystemItemRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnGetFileSystemItemRequest(GetFileSystemItemRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - FileSystemItemDTO dto = _manager.GetFolder(request); - await receiver.SendGenericResponse(new GetFileSystemItemResponse() { FileSystemItem = dto }, token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + this.ThrowIfDisabled(); + + FileSystemItemDTO dto = _manager.GetFolder(request); + await receiver.SendGenericResponse(new GetFileSystemItemResponse() { FileSystemItem = dto }, token); } - [ExternalBridgeRequestHandlerMethod(typeof(FileUploadRequest))] - public async void OnFileUploadRequest(FileUploadRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(FileUploadRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnFileUploadRequest(FileUploadRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - var tempFile = TemporaryManager.CreateFile(); - using (var stream = new FileStream(tempFile, FileMode.Create)) { } + this.ThrowIfDisabled(); - FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Upload, tempFile) { UploadPostPath = request.Path }; - _operations.Add(operation.Id, operation); + var tempFile = TemporaryManager.CreateFile(); + using (var stream = new FileStream(tempFile, FileMode.Create)) { } - await receiver.SendGenericResponse(new FileUploadResponse() { OperationId = operation.Id }, token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Upload, tempFile) { UploadPostPath = request.Path }; + _operations.Add(operation.Id, operation); + + await receiver.SendGenericResponse(new FileUploadResponse() { OperationId = operation.Id }, token); } - [ExternalBridgeRequestHandlerMethod(typeof(FolderUploadRequest))] - public async void OnFolderUploadRequest(FolderUploadRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(FolderUploadRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnFolderUploadRequest(FolderUploadRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - var tempFile = TemporaryManager.CreateFile(); - using (var stream = new FileStream(tempFile, FileMode.Create)) { } + this.ThrowIfDisabled(); - FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Upload, tempFile) { UploadPostPath = request.Path, IsPathTempZip = true }; - _operations.Add(operation.Id, operation); + var tempFile = TemporaryManager.CreateFile(); + using (var stream = new FileStream(tempFile, FileMode.Create)) { } - await receiver.SendGenericResponse(new FolderUploadResponse() { OperationId = operation.Id }, token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Upload, tempFile) { UploadPostPath = request.Path, IsPathTempZip = true }; + _operations.Add(operation.Id, operation); + + await receiver.SendGenericResponse(new FolderUploadResponse() { OperationId = operation.Id }, token); } - [ExternalBridgeRequestHandlerMethod(typeof(FileDownloadRequest))] - public async void OnFileDownloadRequest(FileDownloadRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(FileDownloadRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnFileDownloadRequest(FileDownloadRequest request, String token, ExternalBridgeReceiver receiver) { - try + this.ThrowIfDisabled(); + + if (!File.Exists(request.Path)) { - if (!File.Exists(request.Path)) - { - await receiver.SendErrorResponse(new FileNotFoundException("Could not find the specified file."), token); - return; - } + throw new FileNotFoundException("Could not find the specified file."); + } - FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Download, request.Path); + FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Download, request.Path); - _operations.Add(operation.Id, operation); + _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.SendGenericResponse(new FileDownloadResponse() { - await receiver.SendErrorResponse(ex, token); - } + OperationId = operation.Id, + Length = new FileInfo(request.Path).Length + }, token); } - [ExternalBridgeRequestHandlerMethod(typeof(FolderDownloadRequest))] - public async void OnFolderDownloadRequest(FolderDownloadRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(FolderDownloadRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnFolderDownloadRequest(FolderDownloadRequest request, String token, ExternalBridgeReceiver receiver) { - try + this.ThrowIfDisabled(); + + if (!Directory.Exists(request.Path)) { - if (!Directory.Exists(request.Path)) - { - await receiver.SendErrorResponse(new FileNotFoundException("Could not find the specified directory."), token); - return; - } + throw new FileNotFoundException("Could not find the specified directory."); + } - var tempFile = TemporaryManager.CreateImaginaryFile(); + var tempFile = TemporaryManager.CreateImaginaryFile(); - ZipFile.CreateFromDirectory(request.Path, tempFile); + ZipFile.CreateFromDirectory(request.Path, tempFile); - FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Download, tempFile); - operation.IsPathTempZip = true; + FileSystemOperation operation = new FileSystemOperation(FileSystemOperationMode.Download, tempFile); + operation.IsPathTempZip = true; - _operations.Add(operation.Id, operation); + _operations.Add(operation.Id, operation); - await receiver.SendGenericResponse(new FolderDownloadResponse() - { - OperationId = operation.Id, - Length = new FileInfo(tempFile).Length - }, token); - } - catch (Exception ex) + await receiver.SendGenericResponse(new FolderDownloadResponse() { - await receiver.SendErrorResponse(ex, token); - } + OperationId = operation.Id, + Length = new FileInfo(tempFile).Length + }, token); } [ExternalBridgeRequestHandlerMethod(typeof(ChunkUploadRequest))] - public async void OnChunkUploadRequest(ChunkUploadRequest request, String token, ITransporter receiver) + public async Task OnChunkUploadRequest(ChunkUploadRequest request, String token, ITransporter receiver) { - try + this.ThrowIfDisabled(); + + FileSystemOperation operation; + _operations.TryGetValue(request.OperationId, out operation); + + if (operation == null) { - FileSystemOperation operation; - _operations.TryGetValue(request.OperationId, out operation); + throw new ArgumentException("Invalid operation id."); + } - if (operation == null) - { - await receiver.SendErrorResponse(new ArgumentException("Invalid operation id."), token); - return; - } + using (var stream = new FileStream(operation.Path, FileMode.Append)) + { + stream.Write(request.Data, 0, request.Data.Length); + } - using (var stream = new FileStream(operation.Path, FileMode.Append)) + if (request.IsCompleted) + { + if (!operation.IsPathTempZip) { - stream.Write(request.Data, 0, request.Data.Length); + File.Copy(operation.Path, operation.UploadPostPath, true); + try + { + File.Delete(operation.Path); + } + catch { } } - - if (request.IsCompleted) + else { - if (!operation.IsPathTempZip) + using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(operation.Path)) { - File.Copy(operation.Path, operation.UploadPostPath, true); - try - { - File.Delete(operation.Path); - } - catch { } + zip.ExtractAll(operation.UploadPostPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently); } - else - { - using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(operation.Path)) - { - zip.ExtractAll(operation.UploadPostPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently); - } - try - { - File.Delete(operation.Path); - } - catch { } + try + { + File.Delete(operation.Path); } + catch { } } - - await receiver.SendGenericResponse(new ChunkUploadResponse(), token, new TransportResponseConfig() { Priority = QueuePriority.Low }); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); } + + await receiver.SendGenericResponse(new ChunkUploadResponse(), token, new TransportResponseConfig() { Priority = QueuePriority.Low }); } [ExternalBridgeRequestHandlerMethod(typeof(ChunkDownloadRequest))] - public async void OnChunkDownloadRequest(ChunkDownloadRequest request, String token, ITransporter receiver) + public async Task OnChunkDownloadRequest(ChunkDownloadRequest request, String token, ITransporter receiver) { + this.ThrowIfDisabled(); + FileSystemOperation operation; _operations.TryGetValue(request.OperationId, out operation); if (operation == null) { - await receiver.SendErrorResponse(new ArgumentException("Invalid operation id."), token); - return; + throw new ArgumentException("Invalid operation id."); } FileStream stream = null; @@ -307,7 +268,7 @@ namespace Tango.PPC.Common.FileSystem catch (Exception ex) { stream?.Dispose(); - await receiver.SendErrorResponse(ex, token); + throw ex; } finally { @@ -325,111 +286,78 @@ namespace Tango.PPC.Common.FileSystem } } - [ExternalBridgeRequestHandlerMethod(typeof(AbortOperationRequest))] - public async void OnAbortOperationRequest(AbortOperationRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(AbortOperationRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnAbortOperationRequest(AbortOperationRequest request, String token, ExternalBridgeReceiver receiver) { + this.ThrowIfDisabled(); + FileSystemOperation operation; _operations.TryGetValue(request.OperationId, out operation); if (operation == null) { - await receiver.SendErrorResponse(new ArgumentException("Invalid operation id."), token); - return; + throw new ArgumentException("Invalid operation id."); } - try + if (operation.Mode == FileSystemOperationMode.Upload) { - if (operation.Mode == FileSystemOperationMode.Upload) + if (File.Exists(operation.Path)) { - if (File.Exists(operation.Path)) - { - File.Delete(operation.Path); - } + File.Delete(operation.Path); } - else if (operation.IsPathTempZip) - { - if (File.Exists(operation.Path)) - { - File.Delete(operation.Path); - } - } - - await receiver.SendGenericResponse(new AbortOperationResponse(), token); } - catch (Exception ex) + else if (operation.IsPathTempZip) { - await receiver.SendErrorResponse(ex, token); + if (File.Exists(operation.Path)) + { + File.Delete(operation.Path); + } } + + await receiver.SendGenericResponse(new AbortOperationResponse(), token); } - [ExternalBridgeRequestHandlerMethod(typeof(MoveRequest))] - public async void OnMoveRequest(MoveRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(MoveRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnMoveRequest(MoveRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - _manager.Move(request); - await receiver.SendGenericResponse(new MoveResponse(), token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + this.ThrowIfDisabled(); + + _manager.Move(request); + await receiver.SendGenericResponse(new MoveResponse(), token); } - [ExternalBridgeRequestHandlerMethod(typeof(CopyRequest))] - public async void OnCopyRequest(CopyRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(CopyRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnCopyRequest(CopyRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - _manager.Copy(request); - await receiver.SendGenericResponse(new CopyResponse(), token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + this.ThrowIfDisabled(); + + _manager.Copy(request); + await receiver.SendGenericResponse(new CopyResponse(), token); } - [ExternalBridgeRequestHandlerMethod(typeof(DeleteRequest))] - public async void OnDeleteRequest(DeleteRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(DeleteRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnDeleteRequest(DeleteRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - _manager.Delete(request.Path); - await receiver.SendGenericResponse(new DeleteResponse(), token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + this.ThrowIfDisabled(); + + _manager.Delete(request.Path); + await receiver.SendGenericResponse(new DeleteResponse(), token); } - [ExternalBridgeRequestHandlerMethod(typeof(CreateFolderRequest))] - public async void OnCreateFolderRequest(CreateFolderRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(CreateFolderRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnCreateFolderRequest(CreateFolderRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - var dto = _manager.CreateFolder(request.Path, request.FolderName); - await receiver.SendGenericResponse(new CreateFolderResponse() { FolderItem = dto }, token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + this.ThrowIfDisabled(); + + var dto = _manager.CreateFolder(request.Path, request.FolderName); + await receiver.SendGenericResponse(new CreateFolderResponse() { FolderItem = dto }, token); } - [ExternalBridgeRequestHandlerMethod(typeof(PerformDiskSpaceOptimizationRequest))] - public async void OnPerformDiskSpaceOptimizationRequest(PerformDiskSpaceOptimizationRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(PerformDiskSpaceOptimizationRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnPerformDiskSpaceOptimizationRequest(PerformDiskSpaceOptimizationRequest request, String token, ExternalBridgeReceiver receiver) { - try - { - var deletedBytes = _manager.PerformDiskSpaceOptimization(); - await receiver.SendGenericResponse(new PerformDiskSpaceOptimizationResponse() { DeletedBytes = deletedBytes }, token); - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); - } + var deletedBytes = _manager.PerformDiskSpaceOptimization(); + await receiver.SendGenericResponse(new PerformDiskSpaceOptimizationResponse() { DeletedBytes = deletedBytes }, token); } public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) @@ -438,13 +366,14 @@ namespace Tango.PPC.Common.FileSystem { try { + LogManager.Log("External bridge receiver disconnected. Disposing file system service WebRTC channel..."); var webRtcTransporter = _webRtcClients[receiver]; _webRtcClients.Remove(receiver); webRtcTransporter.Dispose(); } catch (Exception ex) { - LogManager.Log(ex, "Error disposing the WebRTC transporter."); + LogManager.Log(ex, "Error disposing the WebRTC channel."); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/FileSystemOperation.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/FileSystemOperation.cs new file mode 100644 index 000000000..9fba7a874 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/FileSystemOperation.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.FileSystem +{ + /// <summary> + /// Represents an active file system file/folder download/upload operation + /// </summary> + public class FileSystemOperation + { + /// <summary> + /// Gets or sets the operation mode. + /// </summary> + public FileSystemOperationMode Mode { get; set; } + + /// <summary> + /// Gets or sets the operation identifier. + /// </summary> + public String Id { get; set; } + + /// <summary> + /// Gets or sets the path for the operation. + /// </summary> + public String Path { get; set; } + + /// <summary> + /// Should be set to true when the <see cref="Path"/> is a temporary zip file when performing download of a folder. + /// </summary> + public bool IsPathTempZip { get; set; } + + /// <summary> + /// Gets or sets the actual path to extract the zip file when uploading folder. + /// </summary> + public String UploadPostPath { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="FileSystemOperation"/> class. + /// </summary> + /// <param name="mode">The mode.</param> + /// <param name="path">The path.</param> + public FileSystemOperation(FileSystemOperationMode mode, String path) + { + Mode = mode; + Id = Guid.NewGuid().ToString(); + Path = path; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/FileSystemOperationMode.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/FileSystemOperationMode.cs new file mode 100644 index 000000000..e28843bce --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/FileSystemOperationMode.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.FileSystem +{ + public enum FileSystemOperationMode + { + Upload, + Download + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/IFileSystemService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/IFileSystemService.cs index 6cf3321a3..7a80db9c7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/IFileSystemService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FileSystem/IFileSystemService.cs @@ -6,9 +6,15 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.FileSystem { - public interface IFileSystemService + /// <summary> + /// Represents a PPC file system remote service. + /// </summary> + /// <seealso cref="Tango.PPC.Common.IPPCService" /> + public interface IFileSystemService : IPPCService { - bool Enabled { get; set; } + /// <summary> + /// Gets or sets a value indicating whether to enable the WebRTC transport channel. + /// </summary> bool EnableWebRTC { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCService.cs new file mode 100644 index 000000000..5dfe5335c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCService.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; + +namespace Tango.PPC.Common +{ + /// <summary> + /// Represents a PPC remoting service. + /// </summary> + public interface IPPCService + { + /// <summary> + /// Gets or sets a value indicating whether this <see cref="IPPCService"/> is enabled. + /// </summary> + bool Enabled { get; set; } + } +} + +public static class ExtensionMethods +{ + /// <summary> + /// Throws an exception is the service is disabled. + /// </summary> + /// <param name="service">The service.</param> + /// <exception cref="System.InvalidOperationException"></exception> + public static void ThrowIfDisabled(this IPPCService service) + { + if (!service.Enabled) + { + throw new NotSupportedException($"The {service.GetType().Name} is currently disabled. Could not perform the requested action."); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 733574f72..9a12552bc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -1687,30 +1687,23 @@ namespace Tango.PPC.Common.MachineUpdate public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) { - + //Do nothing. } - [ExternalBridgeRequestHandlerMethod(typeof(GetUpdatesAndPackagesRequest))] - public async void OnGetUpdatesAndPackagesRequest(GetUpdatesAndPackagesRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(GetUpdatesAndPackagesRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnGetUpdatesAndPackagesRequest(GetUpdatesAndPackagesRequest request, String token, ExternalBridgeReceiver receiver) { - try + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - using (ObservablesContext db = ObservablesContext.CreateDefault()) - { - var updates = await db.TangoUpdates.OrderByDescending(x => x.StartDate).ToListAsync(); - var updatesDTO = updates.Select(x => TangoUpdateDTO.FromObservable(x)).ToList(); - var packages = (await _packageRunner.GetPackagesFile()).PackageInstallations; + var updates = await db.TangoUpdates.OrderByDescending(x => x.StartDate).ToListAsync(); + var updatesDTO = updates.Select(x => TangoUpdateDTO.FromObservable(x)).ToList(); + var packages = (await _packageRunner.GetPackagesFile()).PackageInstallations; - var response = new GetUpdatesAndPackagesResponse(); - response.Updates.AddRange(updatesDTO); - response.Packages.AddRange(packages); + var response = new GetUpdatesAndPackagesResponse(); + response.Updates.AddRange(updatesDTO); + response.Packages.AddRange(packages); - await receiver.SendGenericResponse(response, token); - } - } - catch (Exception ex) - { - await receiver.SendErrorResponse(ex, token); + await receiver.SendGenericResponse(response, token); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/DefaultPerformanceService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/DefaultPerformanceService.cs index d327f6b00..59236f667 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/DefaultPerformanceService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/DefaultPerformanceService.cs @@ -96,26 +96,18 @@ namespace Tango.PPC.Common.Performance externalBridge.RegisterRequestHandler(this); } - [ExternalBridgeRequestHandlerMethod(typeof(StartPerformanceUpdatesRequest))] - public async void OnStartPerformanceUpdatesRequest(StartPerformanceUpdatesRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(StartPerformanceUpdatesRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)] + public async Task OnStartPerformanceUpdatesRequest(StartPerformanceUpdatesRequest request, String token, ExternalBridgeReceiver receiver) { - if (Enabled) - { - try - { - if (!_clients.Exists(x => x.Receiver == receiver)) - { - _clients.Add(new PerformanceClient() { Receiver = receiver, Token = token }); - OnReceiversChanged(); - } + this.ThrowIfDisabled(); - await receiver.SendGenericResponse(new StartPerformanceUpdatesResponse() { Package = _package }, token); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error sending performance package."); - } + if (!_clients.Exists(x => x.Receiver == receiver)) + { + _clients.Add(new PerformanceClient() { Receiver = receiver, Token = token }); + OnReceiversChanged(); } + + await receiver.SendGenericResponse(new StartPerformanceUpdatesResponse() { Package = _package }, token); } public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/IPerformanceService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/IPerformanceService.cs index c3bfd1543..29e69aee2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/IPerformanceService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Performance/IPerformanceService.cs @@ -7,8 +7,8 @@ using Tango.Integration.ExternalBridge; namespace Tango.PPC.Common.Performance { - public interface IPerformanceService : IExternalBridgeRequestHandler + public interface IPerformanceService : IPPCService, IExternalBridgeRequestHandler { - bool Enabled { get; set; } + } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs index 849befc27..7ba020174 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs @@ -10,6 +10,7 @@ using System.Windows.Input; using Tango.Core; using Tango.Core.DI; using Tango.Integration.ExternalBridge; +using Tango.Logging; using Tango.PPC.Common.Application; using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.OS; @@ -30,15 +31,6 @@ namespace Tango.PPC.Common.RemoteDesktop [TangoCreateWhenRegistered] public class DefaultRemoteDesktopService : ExtendedObject, IRemoteDesktopService, IExternalBridgeRequestHandler { - private class RemoteDesktopClient - { - public String Token { get; set; } - public ExternalBridgeReceiver Receiver { get; set; } - public bool InitialPacketSent { get; set; } - public WebRtcClient WebRtcClient { get; set; } - public bool IsWebRtcReady { get; set; } - } - private RemoteDesktopPacket _initialPacket; private RasterScreenCaptureEngine _engine; private PPCSettings _settings; @@ -47,14 +39,24 @@ namespace Tango.PPC.Common.RemoteDesktop private IOperationSystemManager _osManager; private IPPCApplicationManager _appManager; + /// <summary> + /// Gets or sets a value indicating whether this <see cref="IPPCService" /> is enabled. + /// </summary> + public bool Enabled { get; set; } = true; private bool _isStarted; + /// <summary> + /// Gets a value indicating whether the remote desktop service has started. + /// </summary> public bool IsStarted { get { return _isStarted; } private set { _isStarted = value; RaisePropertyChangedAuto(); } } + /// <summary> + /// Gets a value indicating whether there is any active remote desktop session with a remote peer. + /// </summary> public bool InSession { get @@ -63,6 +65,12 @@ namespace Tango.PPC.Common.RemoteDesktop } } + /// <summary> + /// Initializes a new instance of the <see cref="DefaultRemoteDesktopService"/> class. + /// </summary> + /// <param name="applicationManager">The application manager.</param> + /// <param name="externalBridge">The external bridge.</param> + /// <param name="osManager">The os manager.</param> public DefaultRemoteDesktopService(IPPCApplicationManager applicationManager, IPPCExternalBridgeService externalBridge, IOperationSystemManager osManager) { _osManager = osManager; @@ -74,6 +82,8 @@ namespace Tango.PPC.Common.RemoteDesktop }; _settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + Enabled = _settings.EnableRemoteDesktop; + applicationManager.ApplicationReady += ApplicationManager_ApplicationReady; externalBridge.RegisterRequestHandler(this); @@ -118,14 +128,10 @@ namespace Tango.PPC.Common.RemoteDesktop _engine.Comparer.MaxDifferencesThrow = _engine.CaptureRegion.Width * _engine.CaptureRegion.Height / 2; } - [ExternalBridgeRequestHandlerMethod(typeof(StartRemoteDesktopSessionRequest))] - public async void OnStartRemoteDesktopSessionRequestReceived(StartRemoteDesktopSessionRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(StartRemoteDesktopSessionRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnStartRemoteDesktopSessionRequestReceived(StartRemoteDesktopSessionRequest request, String token, ExternalBridgeReceiver receiver) { - if (!_settings.EnableRemoteDesktop) - { - await receiver.SendErrorResponse(new AuthenticationException("Remote desktop is disabled on this machine."), token); - return; - } + this.ThrowIfDisabled(); var client = _clients.SingleOrDefault(x => x.Receiver == receiver); @@ -146,19 +152,17 @@ namespace Tango.PPC.Common.RemoteDesktop FrameRate = _engine.FrameRate }, token); - if (_settings.EnableRemoteDesktop) + + if (!_engine.IsStarted) { - if (!_engine.IsStarted) - { - _engine.Start(); - } + _engine.Start(); } RaisePropertyChanged(nameof(InSession)); } - [ExternalBridgeRequestHandlerMethod(typeof(WebRtcIceCandidateRequest))] - public async void OnWebRtcIceCandidateRequestReceived(WebRtcIceCandidateRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(WebRtcIceCandidateRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnWebRtcIceCandidateRequestReceived(WebRtcIceCandidateRequest request, String token, ExternalBridgeReceiver receiver) { var client = _clients.SingleOrDefault(x => x.Receiver == receiver); @@ -171,13 +175,13 @@ namespace Tango.PPC.Common.RemoteDesktop } catch (Exception ex) { - LogManager.Log($"Error adding WebRTC ice candidate received from the remote connection.\n{ex.FlattenMessage()}"); + LogManager.Log(ex, "Error adding WebRTC ice candidate received from the remote connection."); } } } - [ExternalBridgeRequestHandlerMethod(typeof(WebRtcOfferRequest))] - public async void OnWebRtcOfferRequestReceived(WebRtcOfferRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(WebRtcOfferRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnWebRtcOfferRequestReceived(WebRtcOfferRequest request, String token, ExternalBridgeReceiver receiver) { var client = _clients.SingleOrDefault(x => x.Receiver == receiver); @@ -196,7 +200,7 @@ namespace Tango.PPC.Common.RemoteDesktop } catch (Exception ex) { - LogManager.Log(ex, $"Error sending ice candidate to remote peer.\n{ex.FlattenMessage()}"); + LogManager.Log(ex, "Error sending ice candidate to remote peer."); } }; client.WebRtcClient.Ready += (x, e) => @@ -219,18 +223,18 @@ namespace Tango.PPC.Common.RemoteDesktop } catch (Exception ex) { - LogManager.Log($"Error initializing the web RTC client.\n{ex.FlattenMessage()}"); + throw LogManager.Log(ex, "Error initializing the WebRTC client."); } } catch (Exception ex) { - LogManager.Log($"Error responding to WebRTC offer request.\n{ex.FlattenMessage()}"); + throw LogManager.Log(ex, "Error responding to WebRTC offer request."); } } } - [ExternalBridgeRequestHandlerMethod(typeof(StopRemoteDesktopSessionRequest))] - public async void OnStopRemoteDesktopSessionRequestReceived(StopRemoteDesktopSessionRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(StopRemoteDesktopSessionRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnStopRemoteDesktopSessionRequestReceived(StopRemoteDesktopSessionRequest request, String token, ExternalBridgeReceiver receiver) { var client = _clients.SingleOrDefault(x => x.Receiver == receiver); @@ -260,7 +264,7 @@ namespace Tango.PPC.Common.RemoteDesktop } [ExternalBridgeRequestHandlerMethod(typeof(MouseStateRequest))] - public async void OnMouseStateRequestReceived(MouseStateRequest request, String token, ExternalBridgeReceiver receiver) + public async Task OnMouseStateRequestReceived(MouseStateRequest request, String token, ExternalBridgeReceiver receiver) { MouseController.SetCursorPosition((int)request.Location.X, (int)request.Location.Y); @@ -292,7 +296,7 @@ namespace Tango.PPC.Common.RemoteDesktop } [ExternalBridgeRequestHandlerMethod(typeof(KeyboardStateRequest))] - public async void OnKeyboardStateRequestReceived(KeyboardStateRequest request, String token, ExternalBridgeReceiver receiver) + public async Task OnKeyboardStateRequestReceived(KeyboardStateRequest request, String token, ExternalBridgeReceiver receiver) { if (request.EventType == KeyboardEventType.Down) { @@ -309,8 +313,8 @@ namespace Tango.PPC.Common.RemoteDesktop } } - [ExternalBridgeRequestHandlerMethod(typeof(RemoteDesktopCommandRequest))] - public async void OnRemoteDesktopCommandRequest(RemoteDesktopCommandRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(RemoteDesktopCommandRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnRemoteDesktopCommandRequest(RemoteDesktopCommandRequest request, String token, ExternalBridgeReceiver receiver) { switch (request.Command) { @@ -346,7 +350,7 @@ namespace Tango.PPC.Common.RemoteDesktop } catch (Exception ex) { - Debug.WriteLine(ex); + LogManager.Log(ex, LogCategory.Debug, "Error pushing remote desktop frame via WebRTC channel."); } } @@ -382,7 +386,6 @@ namespace Tango.PPC.Common.RemoteDesktop if (!e.Frame.DifferenceAvailable) { - Debug.WriteLine("Using Jpeg..."); packet = new RemoteDesktopPacket() { Bitmap = e.Frame.ToEncoder<TurboJpegEncoder>().ToArray(30) @@ -403,7 +406,7 @@ namespace Tango.PPC.Common.RemoteDesktop diffFrame.Dispose(); } - Debug.WriteLine($"Bitmap Size: {packet.Bitmap.Length / 1000} kb"); + Debug.WriteLine($"Remote Desktop Bitmap Size: {packet.Bitmap.Length / 1000} kb"); foreach (var client in _clients.ToList().Where(x => x.InitialPacketSent)) { @@ -429,7 +432,7 @@ namespace Tango.PPC.Common.RemoteDesktop e.Frame.Dispose(); } - private void WebRtcClient_TextMessageReceived(object sender, DataMessageReceivedEventArgs<string> e) + private async void WebRtcClient_TextMessageReceived(object sender, DataMessageReceivedEventArgs<string> e) { try { @@ -437,16 +440,16 @@ namespace Tango.PPC.Common.RemoteDesktop if (request.GetType() == typeof(MouseStateRequest)) { - OnMouseStateRequestReceived(request as MouseStateRequest, null, null); + await OnMouseStateRequestReceived(request as MouseStateRequest, null, null); } else if (request.GetType() == typeof(KeyboardStateRequest)) { - OnKeyboardStateRequestReceived(request as KeyboardStateRequest, null, null); + await OnKeyboardStateRequestReceived(request as KeyboardStateRequest, null, null); } } catch (Exception ex) { - LogManager.Log(ex, "Error deserializing incoming from message on the WebRTC data Channel."); + LogManager.Log(ex, "Error deserializing incoming message on the WebRTC data Channel."); } } @@ -456,6 +459,8 @@ namespace Tango.PPC.Common.RemoteDesktop if (client != null) { + LogManager.Log("Remote desktop client disconnected. Disposing WebRTC channel..."); + _clients.Remove(client); try @@ -467,7 +472,7 @@ namespace Tango.PPC.Common.RemoteDesktop } catch (Exception ex) { - LogManager.Log($"Error disposing the WebRTC client.\n{ex.FlattenMessage()}"); + LogManager.Log(ex, "Error disposing the WebRTC channel."); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/IRemoteDesktopService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/IRemoteDesktopService.cs index 5760b94dc..5e4a801d7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/IRemoteDesktopService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/IRemoteDesktopService.cs @@ -6,9 +6,19 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.RemoteDesktop { - public interface IRemoteDesktopService + /// <summary> + /// Represents a PPC remote desktop service. + /// </summary> + public interface IRemoteDesktopService : IPPCService { + /// <summary> + /// Gets a value indicating whether the remote desktop service has started. + /// </summary> bool IsStarted { get; } + + /// <summary> + /// Gets a value indicating whether there is any active remote desktop session with a remote peer. + /// </summary> bool InSession { get; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/RemoteDesktopClient.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/RemoteDesktopClient.cs new file mode 100644 index 000000000..f0f0a87de --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/RemoteDesktopClient.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.ExternalBridge; +using Tango.WebRTC; + +namespace Tango.PPC.Common.RemoteDesktop +{ + public class RemoteDesktopClient + { + public String Token { get; set; } + public ExternalBridgeReceiver Receiver { get; set; } + public bool InitialPacketSent { get; set; } + public WebRtcClient WebRtcClient { get; set; } + public bool IsWebRtcReady { get; set; } + } + +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/DefaultSystemInfoService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/DefaultSystemInfoService.cs index ef8e31bce..f80a8be1e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/DefaultSystemInfoService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/DefaultSystemInfoService.cs @@ -33,30 +33,28 @@ namespace Tango.PPC.Common.SystemInfo externalBridge.RegisterRequestHandler(this); } - [ExternalBridgeRequestHandlerMethod(typeof(GetMachineInformationRequest))] - public async void OnGetMachineInformationRequest(GetMachineInformationRequest request, String token, ExternalBridgeReceiver receiver) + [ExternalBridgeRequestHandlerMethod(typeof(GetMachineInformationRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnGetMachineInformationRequest(GetMachineInformationRequest request, String token, ExternalBridgeReceiver receiver) { - try + if (response == null) { - if (response == null) - { - //Get the networks that are currently connected to - var connectedNetwork = NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected).FirstOrDefault(); + //Get the networks that are currently connected to + var connectedNetwork = NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected).FirstOrDefault(); - var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); - List<SystemObjectsCollection> system = new List<SystemObjectsCollection>(); + List<SystemObjectsCollection> system = new List<SystemObjectsCollection>(); - if (!Debugger.IsAttached) - { - system = SystemObjectsCollection.Create(); - } + if (!Debugger.IsAttached) + { + system = SystemObjectsCollection.Create(); + } - //Add custom information.. - system.Insert(0, new SystemObjectsCollection() - { - Name = "Application", - Objects = new List<SystemObject>() + //Add custom information.. + system.Insert(0, new SystemObjectsCollection() + { + Name = "Application", + Objects = new List<SystemObject>() { new SystemObject() { @@ -112,23 +110,18 @@ namespace Tango.PPC.Common.SystemInfo }.OrderBy(x => x.Name).ToList(), }, }, - }); + }); - response = new GetMachineInformationResponse() + response = new GetMachineInformationResponse() + { + Package = new InformationPackage() { - Package = new InformationPackage() - { - System = system, - } - }; - } - - await receiver.SendGenericResponse(response, token); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error sending system information."); + System = system, + } + }; } + + await receiver.SendGenericResponse(response, token); } public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/ISystemInfoService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/ISystemInfoService.cs index 0cc493891..47ea7bd4b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/ISystemInfoService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/SystemInfo/ISystemInfoService.cs @@ -6,8 +6,12 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.SystemInfo { - public interface ISystemInfoService + /// <summary> + /// Represents a PPC system information service. + /// </summary> + /// <seealso cref="Tango.PPC.Common.IPPCService" /> + public interface ISystemInfoService : IPPCService { - bool Enabled { get; set; } + } } 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 9575b7137..e97fd9d32 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 @@ -156,11 +156,14 @@ <Compile Include="ExternalBridge\IPPCExternalBridgeService.cs" /> <Compile Include="ExternalBridge\PPCExternalBridgeService.cs" /> <Compile Include="FileSystem\DefaultFileSystemService.cs" /> + <Compile Include="FileSystem\FileSystemOperation.cs" /> + <Compile Include="FileSystem\FileSystemOperationMode.cs" /> <Compile Include="FileSystem\IFileSystemService.cs" /> <Compile Include="Helpers\KeyboardHelper.cs" /> <Compile Include="HotSpot\DefaultHotSpotProvider.cs" /> <Compile Include="HotSpot\IHotSpotProvider.cs" /> <Compile Include="IPPCView.cs" /> + <Compile Include="IPPCService.cs" /> <Compile Include="MachineSetup\IMachineSetupManager.cs" /> <Compile Include="MachineSetup\MachineSetupManager.cs" /> <Compile Include="MachineSetup\MachineSetupProgress.cs" /> @@ -169,6 +172,7 @@ <Compile Include="Performance\IPerformanceService.cs" /> <Compile Include="RemoteDesktop\DefaultRemoteDesktopService.cs" /> <Compile Include="RemoteDesktop\IRemoteDesktopService.cs" /> + <Compile Include="RemoteDesktop\RemoteDesktopClient.cs" /> <Compile Include="Synchronization\DefaultMachineDataSynchronizer.cs" /> <Compile Include="Synchronization\IMachineDataSynchronizer.cs" /> <Compile Include="Synchronization\SynchronizationEndedEventArgs.cs" /> @@ -456,7 +460,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs index 53af736c9..f6fb2c935 100644 --- a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs +++ b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.PPC.Common.UpdatePackages; +using Tango.PPC.Shared.Updates; namespace Tango.PPC.Packages.SamplePostPackage { diff --git a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/Tango.PPC.Packages.SamplePostPackage.csproj b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/Tango.PPC.Packages.SamplePostPackage.csproj index f06fdd5cf..d528c5c14 100644 --- a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/Tango.PPC.Packages.SamplePostPackage.csproj +++ b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/Tango.PPC.Packages.SamplePostPackage.csproj @@ -60,6 +60,11 @@ <Name>Tango.PPC.Common</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\..\Tango.PPC.Shared\Tango.PPC.Shared.csproj"> + <Project>{208c8bd8-72c6-4e3c-acaa-351091a2acc7}</Project> + <Name>Tango.PPC.Shared</Name> + <Private>False</Private> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs index 5aa811e85..1913d3f28 100644 --- a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs +++ b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.PPC.Common.UpdatePackages; +using Tango.PPC.Shared.Updates; namespace Tango.PPC.Packages.SamplePrePackage { diff --git a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/Tango.PPC.Packages.SamplePrePackage.csproj b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/Tango.PPC.Packages.SamplePrePackage.csproj index b4397d253..4437a05c4 100644 --- a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/Tango.PPC.Packages.SamplePrePackage.csproj +++ b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/Tango.PPC.Packages.SamplePrePackage.csproj @@ -60,6 +60,11 @@ <Name>Tango.PPC.Common</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\..\Tango.PPC.Shared\Tango.PPC.Shared.csproj"> + <Project>{208c8bd8-72c6-4e3c-acaa-351091a2acc7}</Project> + <Name>Tango.PPC.Shared</Name> + <Private>False</Private> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file |
