Bladeren bron

Fixing Code Conflicts

Frank van den Bos 2 jaren geleden
bovenliggende
commit
376c5345a8

+ 4 - 2
InABox.Client.RPC/Transports/RPCClientTransport.cs

@@ -77,7 +77,7 @@ namespace InABox.Rpc
             where TResult : IRpcCommandResult, ISerializeBinary, new()
         {
             
-            CheckConnection<TCommand>();
+            CheckConnection<TCommand, TParameters, TResult>();
             
             var request = new RpcMessage()
             {
@@ -102,7 +102,9 @@ namespace InABox.Rpc
             return result;
         }
 
-        private void CheckConnection<TCommand>() where TCommand : IRpcCommand
+        private void CheckConnection<TCommand, TParameters, TResult>() where TCommand : IRpcCommand<TParameters, TResult>
+            where TParameters : IRpcCommandParameters
+            where TResult : IRpcCommandResult
         {
             if (!IsConnected())
                 throw new RpcException($"Transport Disconnected: {typeof(TCommand).Name}()", RpcError.DISCONNECTED);

+ 7 - 8
InABox.RPC.Shared/IRPCCommand.cs

@@ -3,15 +3,14 @@ using InABox.Core;
 
 namespace InABox.Rpc
 {
-    public interface IRpcCommand
-    {
-        /// <summary>
-        /// Set to <see langword="true"/> if this command should be logged.
-        /// </summary>
-        bool Log { get; }
-    }
+    /// <summary>
+    /// Flag an <see cref="IRpcCommand{TProperties, TResult}"/> with <see cref="IRpcLogCommand"/> if its execution should be logged.
+    /// </summary>
+    public interface IRpcLogCommand { }
 
-    public interface IRpcCommand<TProperties, TResult> : IRpcCommand
+    public interface IRpcCommand<TProperties, TResult>
+        where TProperties : IRpcCommandParameters, ISerializeBinary
+        where TResult : IRpcCommandResult
     {
     }
     

+ 15 - 8
InABox.Server/RPC/Handlers/RPCCommandHandler.cs

@@ -6,12 +6,15 @@ using NPOI.SS.Formula.Functions;
 
 namespace InABox.Rpc
 {
-    public abstract class RpcCommandHandler<TSender, TParameters, TResult> : IRpcCommandHandler 
+    public abstract class RpcCommandHandler<TSender, TCommand, TParameters, TResult> : IRpcCommandHandler 
         where TSender : class
+        where TCommand : IRpcCommand<TParameters, TResult>
         where TParameters : IRpcCommandParameters, new()
         where TResult : IRpcCommandResult
     {
         public TSender Sender { get; }
+        
+        private static bool IsLogCommand = typeof(TCommand).IsAssignableTo(typeof(IRpcLogCommand));
 
         public RpcCommandHandler(TSender sender)
         {
@@ -24,17 +27,21 @@ namespace InABox.Rpc
         {
             var start = DateTime.Now;
             var parameters = Serialization.ReadBinary<TParameters>(payload, BinarySerializationSettings.Latest);
-            //Logger.Send(LogType.Information, session.UserID, $"[{session.Platform} {session.Version}] {parameters.FullDescription()}");
-
+            if (IsLogCommand)
+                Logger.Send(LogType.Information, session.UserID, $"[{session.Platform} {session.Version}] {parameters.FullDescription()}");
+            
             try
             {
                 var result = Execute(session, parameters);
 
-                var description = result.FullDescription();
-                // Logger.Send(LogType.Information, session.UserID, string.Format("[{0} {1}] [{2:D8}] {3} Complete{4}",
-                //     session.Platform, session.Version,
-                //     (int)DateTime.Now.Subtract(start).TotalMilliseconds, parameters.ShortDescription(),
-                //     string.IsNullOrWhiteSpace(description) ? "" : $" {description}"));
+                if (IsLogCommand)
+                {
+                    var description = result.FullDescription();
+                    Logger.Send(LogType.Information, session.UserID, string.Format("[{0} {1}] [{2:D8}] {3} Complete{4}",
+                        session.Platform, session.Version,
+                        (int)DateTime.Now.Subtract(start).TotalMilliseconds, parameters.ShortDescription(),
+                        string.IsNullOrWhiteSpace(description) ? "" : $" {description}"));
+                }
 
                 return Serialization.WriteBinary(result, BinarySerializationSettings.Latest);
             }