Browse Source

Work on RPC

Kenric Nugteren 2 years ago
parent
commit
2b8cea096e
2 changed files with 37 additions and 36 deletions
  1. 23 31
      prs.server/Engines/Database/DatabaseEngine.cs
  2. 14 5
      prs.server/Engines/PortStatus.cs

+ 23 - 31
prs.server/Engines/Database/DatabaseEngine.cs

@@ -25,7 +25,7 @@ namespace PRSServer
         private Timer? CertificateRefreshTimer;
         private Timer? CertificateHaltTimer;
         private string PipeName;
-        //private IPCServer? PipeServer;
+        private IPCServer? PipeServer;
 
         private IRpcServer? _pipeserver;
         private IRpcServer? _socketserver;
@@ -202,46 +202,38 @@ namespace PRSServer
             CredentialsCache.LoadSessionCache();
             CredentialsCache.SetSessionExpiryTime(TimeSpan.FromMinutes(Properties.SessionExpiryTime));
 
-            Logger.Send(LogType.Information, "", string.Format("Starting Rest Listener: Port={0}", Properties.Port));
-            
-            // if (Properties.WebSocketPort != 0)
-            // {
-            //     // Put a log saying to start the web socket listener.
-            //     Logger.Send(LogType.Information, "", string.Format("Starting Web Socket Listener: Port={0}", Properties.WebSocketPort));
-            // }
-            // // This should be out of the if-statement, since the listener needs to be initialised, even if the web socket port is 0.
-            // RestListener.Init(Properties.WebSocketPort);
-            // InitialisePort();
-            // RestListener.Start();
-
-            var sockettransport = new RpcServerSocketTransport(Properties.Port, CertificateFileName());
+            if (Properties.WebSocketPort != 0)
+            {
+                // Put a log saying to start the web socket listener.
+                Logger.Send(LogType.Information, "", string.Format("Starting Web Socket Listener: Port={0}", Properties.WebSocketPort));
+            }
+            // This should be out of the if-statement, since the listener needs to be initialised, even if the web socket port is 0.
+            RestListener.Init(Properties.WebSocketPort);
+            InitialisePort();
+            RestListener.Start();
+
+            Logger.Send(LogType.Information, "", string.Format("Starting Web Listener: Port={0}", Properties.Port));
+
+            /*var sockettransport = new RpcServerSocketTransport(Properties.Port, CertificateFileName());
             _socketserver = new RpcServer<RpcServerSocketTransport>(() => sockettransport);
             _socketserver.OnLog += (type, userid, message, parameters) => Logger.Send(type, userid, $"[S] {message}", parameters);
-            _socketserver.Start();        
-            
-            Logger.Send(LogType.Information, "", string.Format("Rest Server Started listening on port {0}", Properties.Port));
-            
-            Logger.Send(LogType.Information, "", $"Starting Pipe Listener with pipe name {PipeName}");
-            
-            // PipeServer = new IPCServer(PipeName);
-            // PipeServer.Start();
+            _socketserver.Start();
+            */
+            Logger.Send(LogType.Information, "", string.Format("Server started listening on port {0}", Properties.Port));
+
+             PipeServer = new IPCServer(PipeName);
+             PipeServer.Start();
 
-            var pipetransport = new RpcServerPipeTransport(PipeName);
+            Logger.Send(LogType.Information, "", $"Starting Pipe Listener with pipe name {PipeName}");
+            /*var pipetransport = new RpcServerPipeTransport(PipeName);
             _pipeserver = new RpcServer<RpcServerPipeTransport>(() => pipetransport);
             _pipeserver.OnLog += (type, userid, message, parameters) => Logger.Send(type, userid, $"[P] {message}", parameters);
-            _pipeserver.Start();
+            _pipeserver.Start();*/
             
             Logger.Send(LogType.Information, "", "Pipe Listener started");
             
             ConfigureNotifier();
 
-
-            
-
-            
-
-
-
         }
 
         #region Certificate Management

+ 14 - 5
prs.server/Engines/PortStatus.cs

@@ -45,9 +45,12 @@ namespace PRSServer
     
     //public class PortStatus[] : List<PortStatus> { }
     
-    public class PortStatusCommand : IRpcCommand<PortStatusParameters,PortStatusResult> { }
+    public class PortStatusCommand : IRpcCommand<PortStatusParameters, PortStatusResult>
+    {
+        public bool Log => false;
+    }
 
-    public class PortStatusParameters : ISerializeBinary
+    public class PortStatusParameters : IRpcCommandParameters
     {
         public void SerializeBinary(CoreBinaryWriter writer)
         {throw new System.NotImplementedException();
@@ -58,9 +61,13 @@ namespace PRSServer
         {
             throw new System.NotImplementedException();
         }
+
+        public string? FullDescription() => null;
+
+        public string? ShortDescription() => null;
     }
 
-    public class PortStatusResult : ISerializeBinary
+    public class PortStatusResult : IRpcCommandResult
     {
         
         public PortStatus[] Ports { get; set; }
@@ -78,12 +85,14 @@ namespace PRSServer
         {
             Ports = reader.ReadBinaryValue<PortStatus[]>();
         }
+
+        public string? FullDescription() => null;
     }
     
-    public class PortStatusHandler : RpcCommandHandler<IEngine,PortStatusParameters,PortStatusResult> 
+    public class PortStatusHandler : RpcCommandHandler<IEngine, PortStatusParameters, PortStatusResult> 
     {
         protected override PortStatusResult Execute(IRpcSession session, PortStatusParameters? parameters) 
-            => new PortStatusResult() { Ports = Sender.PortStatusList() };
+            => new() { Ports = Sender.PortStatusList() };
 
         public PortStatusHandler(IEngine sender) : base(sender)
         {