aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Console
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-04-21 14:21:19 +0300
committerAvi Levkovich <avi@twine-s.com>2020-04-21 14:21:19 +0300
commitcd728bf3a7d1db76747cb18bcfe396c83d690e86 (patch)
tree99347262eef3f175a7ff1441b6c5a031be74d26f /Software/Visual_Studio/PPC/Tango.PPC.Common/Console
parent7fe23e68512e2462de107e76ae3a92ddd381ac77 (diff)
parent97a784b6ce43960bdb92465b08f26d3562a4f202 (diff)
downloadTango-cd728bf3a7d1db76747cb18bcfe396c83d690e86.tar.gz
Tango-cd728bf3a7d1db76747cb18bcfe396c83d690e86.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Console')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Console/DefaultConsoleEngineService.cs78
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Console/IConsoleEngineService.cs7
2 files changed, 57 insertions, 28 deletions
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; }
+
}
}