Browse Source

Prototype Rpc Client System

Frank van den Bos 2 years ago
parent
commit
4c0e4ffe64

+ 1 - 2
prs.desktop/Forms/LoginScreen.xaml.cs

@@ -7,7 +7,6 @@ using System.Windows.Input;
 using InABox.Clients;
 using InABox.Wpf;
 using InABox.WPF;
-using ValidationResult = InABox.Clients.ValidationResult;
 
 namespace PRSDesktop
 {
@@ -44,7 +43,7 @@ namespace PRSDesktop
             {
                 var valid = ClientFactory.Validate(editUser.Text, editPassword.Password);
                 Progress.Close();
-                if (valid == ValidationResult.VALID)
+                if (valid == ValidationStatus.VALID)
                 {
                     DialogResult = true;
                     Close();

+ 12 - 13
prs.desktop/Forms/PinLogin.xaml.cs

@@ -15,7 +15,6 @@ using InABox.Core;
 using InABox.Wpf;
 using InABox.WPF;
 using PRSDesktop.Forms;
-using ValidationResult = InABox.Clients.ValidationResult;
 
 namespace PRSDesktop;
 
@@ -40,7 +39,7 @@ public partial class PinLogin : ThemableWindow
 
     private List<TextBox> codeInputs = new();
 
-    public PinLogin(string version, ValidationResult status)
+    public PinLogin(string version, ValidationStatus status)
     {
         InitializeComponent();
 
@@ -60,13 +59,13 @@ public partial class PinLogin : ThemableWindow
         UserID.Text = App.DatabaseSettings.UserID;
         Password.Password = App.DatabaseSettings.Password;
 
-        if (status == ValidationResult.PASSWORD_EXPIRED)
+        if (status == ValidationStatus.PASSWORD_EXPIRED)
         {
             status = TryValidation("", status);
         }
 
         PINPage = App.DatabaseSettings.LoginType == LoginType.PIN;
-        if (status == ValidationResult.REQUIRE_2FA)
+        if (status == ValidationStatus.REQUIRE_2FA)
             Show2FAPage();
         else if (PINPage)
             ShowPINPage();
@@ -243,7 +242,7 @@ public partial class PinLogin : ThemableWindow
 
     private void OK_Click(object sender, RoutedEventArgs e)
     {
-        ValidationResult? result;
+        ValidationStatus? result;
         using (new WaitCursor())
         {
             try
@@ -258,13 +257,13 @@ public partial class PinLogin : ThemableWindow
             }
         }
 
-        if (result == ValidationResult.REQUIRE_2FA)
+        if (result == ValidationStatus.REQUIRE_2FA)
         {
             Show2FAPage();
             return;
         }
 
-        var bOK = result == ValidationResult.VALID;
+        var bOK = result == ValidationStatus.VALID;
         if (bOK)
         {
             App.DatabaseSettings.LoginType = LoginType.PIN;
@@ -298,7 +297,7 @@ public partial class PinLogin : ThemableWindow
     {
     }
 
-    private ValidationResult TryValidation(string password, ValidationResult? result = null)
+    private ValidationStatus TryValidation(string password, ValidationStatus? result = null)
     {
         while (true)
         {
@@ -317,7 +316,7 @@ public partial class PinLogin : ThemableWindow
                     }
                 }
             }
-            if (result == ValidationResult.PASSWORD_EXPIRED)
+            if (result == ValidationStatus.PASSWORD_EXPIRED)
             {
                 MessageBox.Show("Your password has expired!");
                 var newPassword = ShowChangePassword(UserID.Text);
@@ -337,20 +336,20 @@ public partial class PinLogin : ThemableWindow
             }
             result = null;
         }
-        return result ?? ValidationResult.INVALID;
+        return result ?? ValidationStatus.INVALID;
     }
 
     private void Login_Click(object sender, RoutedEventArgs e)
     {
-        ValidationResult result = TryValidation(Password.Password);
+        ValidationStatus status = TryValidation(Password.Password);
 
-        if (result == ValidationResult.REQUIRE_2FA)
+        if (status == ValidationStatus.REQUIRE_2FA)
         {
             Show2FAPage();
             return;
         }
 
-        var bOK = result == ValidationResult.VALID;
+        var bOK = status == ValidationStatus.VALID;
 
         if (bOK)
         {

+ 87 - 32
prs.desktop/MainWindow.xaml.cs

@@ -32,6 +32,7 @@ using InABox.DynamicGrid;
 using InABox.Mail;
 using InABox.Core.Reports;
 using InABox.IPC;
+using InABox.Rpc;
 using InABox.Scripting;
 using InABox.WPF;
 using NAudio.Wave;
@@ -58,7 +59,6 @@ using Pen = System.Drawing.Pen;
 using PixelFormat = System.Drawing.Imaging.PixelFormat;
 using Role = Comal.Classes.Role;
 using SortDirection = InABox.Core.SortDirection;
-using ValidationResult = InABox.Clients.ValidationResult;
 using PRSDesktop.Components.Spreadsheet;
 using InABox.Wpf.Reports;
 
@@ -75,6 +75,8 @@ namespace PRSDesktop
 
         private static PipeServer<string>? _client;
 
+        private IRpcClientTransport? _transport;
+
         private WaveIn? _audio;
         private bool _audioMuted;
         private MemoryStream? _audioStream;
@@ -143,7 +145,7 @@ namespace PRSDesktop
             ClientFactory.Notifications.AddHandler<Notification>(ReceiveNotification);
             ClientFactory.RegisterMailer(EmailType.IMAP, typeof(IMAPMailer));
             ClientFactory.RegisterMailer(EmailType.Exchange, typeof(ExchangeMailer));
-            ClientFactory.OnLog += (_, message) => { Logger.Send(LogType.Information, ClientFactory.UserID, message); };
+            ClientFactory.OnLog += (type, userid, message, parameters) =>  Logger.Send(LogType.Information, ClientFactory.UserID, message, parameters);
             ClientFactory.OnRequestError += ClientFactory_OnRequestError;
 
             HotKeyManager.Initialize();
@@ -163,20 +165,24 @@ namespace PRSDesktop
                 
                 case DatabaseType.Networked:
                     
-                    //var url = App.DatabaseSettings.URLs.FirstOrDefault() ?? "localhost:8000";
-                    //ClientFactory.SetClientType(typeof(RPCClient<>), Platform.Wpf, CoreUtils.GetVersion(), () => new RPCClientSocketTransport(url));
+                    var url = App.DatabaseSettings.URLs.FirstOrDefault() ?? "localhost:8000";
+                    _transport = new RpcClientSocketTransport(url);
+                    _transport.OnClose += TransportConnectionLost;
+                    ClientFactory.SetClientType(typeof(RpcClient<>), Platform.Wpf, CoreUtils.GetVersion(), _transport );
                     
-                    var url = RestClient<User>.Ping(App.DatabaseSettings.URLs, out DatabaseInfo info);
-                    ClientFactory.SetClientType(typeof(RestClient<>), Platform.Wpf, CoreUtils.GetVersion(), 
-                        url, true);
+                    //var url = RestClient<User>.Ping(App.DatabaseSettings.URLs, out DatabaseInfo info);
+                    //ClientFactory.SetClientType(typeof(RestClient<>), Platform.Wpf, CoreUtils.GetVersion(), 
+                    //    url, true);
                     break;
                 
                 case DatabaseType.Local:
-                    //var pipe = DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName);
-                    //ClientFactory.SetClientType(typeof(RPCClient<>), Platform.Wpf, CoreUtils.GetVersion(),
-                    //    () => new RPCClientPipeTransport(pipe));
-                     ClientFactory.SetClientType(typeof(IPCClient<>), Platform.Wpf, CoreUtils.GetVersion(), 
-                          DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName));
+                    var pipename = DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName);
+                    _transport = new RpcClientPipeTransport(pipename);
+                    _transport.OnClose += TransportConnectionLost;
+                    ClientFactory.SetClientType(typeof(RpcClient<>), Platform.Wpf, CoreUtils.GetVersion(),
+                        _transport );
+                     // ClientFactory.SetClientType(typeof(IPCClient<>), Platform.Wpf, CoreUtils.GetVersion(), 
+                     //      DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName));
                     break;
             }
 
@@ -207,8 +213,8 @@ namespace PRSDesktop
             CheckForUpdates();
 
             Exception? startupException = null;
-            Exception? loginException = null;
-            ValidationResult? loginStatus = null;
+            //Exception? loginException = null;
+            ValidationStatus? loginStatus = null;
 
             Progress.ShowModal("Loading PRS", progress =>
             {
@@ -304,10 +310,10 @@ namespace PRSDesktop
 
             if (startupException != null)
                 MessageBox.Show(startupException.Message);
-            else if (loginException != null)
-                MessageBox.Show(loginException.Message);
+            //else if (loginException != null)
+            //    MessageBox.Show(loginException.Message);
 
-            if (DoLogin(App.DatabaseSettings.Autologin) == ValidationResult.VALID)
+            if (DoLogin(App.DatabaseSettings.Autologin) == ValidationStatus.VALID)
             {
                 AfterLogin();
             }
@@ -323,7 +329,7 @@ namespace PRSDesktop
 
             Progress.ShowModal("Starting Up", progress =>
             {
-                if (loginStatus == ValidationResult.VALID && DatabaseType == DatabaseType.Standalone)
+                if (loginStatus == ValidationStatus.VALID && DatabaseType == DatabaseType.Standalone)
                 {
                     progress.Report("Starting Scheduler");
                     scheduler.Start();
@@ -331,6 +337,34 @@ namespace PRSDesktop
             });
         }
 
+        private void TransportConnectionLost(IRpcTransport transport, RpcTransportCloseArgs e)
+        {
+            if ((transport is IRpcClientTransport client))
+            {
+                Dispatcher.Invoke(() => {
+                    Progress.ShowModal("Reconnecting", (progress) =>
+                    {
+                        DateTime lost = DateTime.Now;
+                        while (!client.IsConnected())
+                        {
+                            progress.Report($"Connection lost - ({(DateTime.Now - lost):hh\\:mm})");
+                            try
+                            {
+                                Logger.Send(LogType.Error,ClientFactory.UserID,"Reconnecting - ({0:hh\\:mm})",DateTime.Now - lost);
+                                client.Connect();
+                                if (client.IsConnected())
+                                    ClientFactory.Validate(ClientFactory.SessionID);
+                            }
+                            catch (System.Exception e1)
+                            {
+                                Logger.Send(LogType.Error,ClientFactory.UserID,$"Reconnect Failed: {e1.Message}");
+                            }
+                        }
+                    });
+                });
+            }
+        }
+        
         private bool _loggingOut = false;
 
         private void ClientFactory_OnRequestError(RequestException e)
@@ -1420,9 +1454,9 @@ namespace PRSDesktop
 
         #region Login Management
 
-        private ValidationResult? DoLogin(bool autoLogin)
+        private ValidationStatus? DoLogin(bool autoLogin)
         {
-            ValidationResult? result = null;
+            ValidationStatus? result = null;
             if (autoLogin)
             {
                 if (App.DatabaseSettings.LoginType == LoginType.UserID)
@@ -1437,22 +1471,22 @@ namespace PRSDesktop
                         MessageBox.Show("Error connecting to server.\nPlease check the server URL and port number.");
                         result = null;
                     }
-                    if (result == ValidationResult.INVALID)
+                    if (result == ValidationStatus.INVALID)
                     {
                         MessageBox.Show("Unable to Login with User ID: " + App.DatabaseSettings.UserID);
                     }
                 }
             }
-            if (result != ValidationResult.VALID)
+            if (result != ValidationStatus.VALID)
             {
-                var login = new PinLogin(CoreUtils.GetVersion(), result ?? ValidationResult.INVALID);
+                var login = new PinLogin(CoreUtils.GetVersion(), result ?? ValidationStatus.INVALID);
                 if (login.ShowDialog() == true)
                 {
-                    result = ValidationResult.VALID;
+                    result = ValidationStatus.VALID;
                 }
             }
 
-            return result ?? ValidationResult.INVALID;
+            return result ?? ValidationStatus.INVALID;
         }
 
         /// <summary>
@@ -1519,6 +1553,7 @@ namespace PRSDesktop
 
         private void LoadCurrentEmployee()
         {
+            
             var me = new Client<Employee>().Query(
                 new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid),
                 new Columns<Employee>(x => x.ID).Add(x => x.Email).Add(x=>x.Name)
@@ -1590,7 +1625,7 @@ namespace PRSDesktop
                 MessageBox.Show(message);
             }
 
-            if (DoLogin(false) == ValidationResult.VALID)
+            if (DoLogin(false) == ValidationStatus.VALID)
             {
                 AfterLogin();
             }
@@ -2734,8 +2769,30 @@ namespace PRSDesktop
             return _timesheets.Rows.Any(r => r.Get<TimeSheet, DateTime>(c => c.Date).Date < DateTime.Today);
         }
 
+        private void ShutDownTransport()
+        {
+            if (_transport != null)
+            {
+                _transport.OnClose -= TransportConnectionLost;
+                if (_transport.IsConnected())
+                    _transport.Disconnect();
+                _transport = null;
+            }
+        }
+        
         private void Window_Unloaded(object sender, RoutedEventArgs e)
         {
+            ShutDownTransport();
+        }
+        
+        
+        private void RibbonWindow_Closed(object sender, EventArgs e)
+        {
+            
+            ShutDownTransport();
+            
+            DisconnectRecorderNotes();
+            Application.Current.Shutdown();
         }
 
         //private bool _closingFromSystemMenu = false;
@@ -2764,6 +2821,9 @@ namespace PRSDesktop
             if (!CoreUtils.GetVersion().Equals("???"))
                 if (station.ID != Guid.Empty)
                     ExecuteLogout();
+
+            ShutDownTransport();
+
         }
 
         private void FinalizeAutoTimesheet()
@@ -2791,11 +2851,6 @@ namespace PRSDesktop
         }
 
 
-        private void RibbonWindow_Closed(object sender, EventArgs e)
-        {
-            DisconnectRecorderNotes();
-            Application.Current.Shutdown();
-        }
 
         #region Notifications + Heartbeat
 
@@ -4086,7 +4141,7 @@ namespace PRSDesktop
 
         private void LoginButton_OnClick(object sender, RoutedEventArgs e)
         {
-            if (DoLogin(false) == ValidationResult.VALID)
+            if (DoLogin(false) == ValidationStatus.VALID)
                 AfterLogin();
         }
 

+ 1 - 0
prs.desktop/PRSDesktop.csproj

@@ -776,6 +776,7 @@
       <ProjectReference Include="..\..\InABox\InABox.Client.IPC\InABox.Client.IPC.csproj" />
       <ProjectReference Include="..\..\InABox\InABox.Client.Local\InABox.Client.Local.csproj" />
       <ProjectReference Include="..\..\inabox\inabox.client.rest\InABox.Client.Rest\InABox.Client.Rest.csproj" />
+      <ProjectReference Include="..\..\inabox\InABox.Client.RPC\InABox.Client.RPC.csproj" />
       <ProjectReference Include="..\..\InABox\InABox.Configuration\InABox.Configuration.csproj" />
       <ProjectReference Include="..\..\InABox\InABox.Core\InABox.Core.csproj" />
       <ProjectReference Include="..\..\InABox\InABox.Database.SQLite\InABox.Database.SQLite.csproj" />

+ 21 - 10
prs.desktop/Utils/SelectDatabase.xaml.cs

@@ -13,6 +13,7 @@ using InABox.Clients;
 using InABox.Configuration;
 using InABox.Core;
 using InABox.IPC;
+using InABox.Rpc;
 using InABox.Wpf;
 using InABox.WPF;
 using PRSServer;
@@ -130,12 +131,19 @@ namespace PRSDesktop
 
                     Task.Run(() =>
                     {
-                        DatabaseInfo info = new DatabaseInfo(db.ColorScheme, db.Logo, CoreUtils.GetVersion(), true);
+                        DatabaseInfo? info = new DatabaseInfo(db.ColorScheme, db.Logo, CoreUtils.GetVersion(), true);
                         
                         if (db.DatabaseType == DatabaseType.Local)
-                            info = new IPCClient<User>(DatabaseServerProperties.GetPipeName(db.LocalServerName)).Info();
+                            info = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(db.LocalServerName)).Info();
                         else if (db.DatabaseType == DatabaseType.Networked)
-                            RestClient<User>.Ping(db.URLs, out info);
+                        {
+                            List<Task<DatabaseInfo?>> infos = new List<Task<DatabaseInfo?>>();
+                            foreach (var url in db.URLs)
+                                infos.Add(Task.Run<DatabaseInfo?>(() => new RpcClientSocketTransport(url).Info()));
+                            var index = Task.WaitAny(infos.ToArray<Task>());
+                            info = infos[index].Result;
+                        }
+
                         UpdateInfo(key, db, info, border, image, dbver);
                     });
 
@@ -152,11 +160,14 @@ namespace PRSDesktop
             return first.SequenceEqual(second);
         }
 
-        private void UpdateInfo(String key, DatabaseSettings db, DatabaseInfo info, Border border, Image image, Label version)
+        private void UpdateInfo(String key, DatabaseSettings db, DatabaseInfo? info, Border border, Image image, Label version)
         {
+            if (info == null)
+                return;
+            
             Dispatcher.Invoke(() =>
             {
-                if(info.ColorScheme is not null)
+                if(info?.ColorScheme is not null)
                 {
                     try
                     {
@@ -172,7 +183,7 @@ namespace PRSDesktop
                 Bitmap? bitmap = null; //PRSDesktop.Resources.splash_small;
                 try
                 {
-                    if (info.Logo != null && info.Logo.Any())
+                    if (info?.Logo != null && info.Logo.Any())
                         using (var ms = new MemoryStream(info.Logo))
                             bitmap = new Bitmap(ms);
                 }
@@ -188,16 +199,16 @@ namespace PRSDesktop
 
                 try
                 {
-                    version.Content = String.Equals(info.Version,"???") ? "" : info.Version;
+                    version.Content = String.Equals(info?.Version,"???") ? "" : info?.Version;
                 }
                 catch
                 {
                 }
 
-                if (!string.Equals(db.ColorScheme, info.ColorScheme) || !LogoEqual(db.Logo, info.Logo))
+                if (!string.Equals(db.ColorScheme, info?.ColorScheme) || !LogoEqual(db.Logo, info?.Logo))
                 {
-                    db.ColorScheme = info.ColorScheme ?? DatabaseSettings.DefaultColorScheme;
-                    db.Logo = info.Logo;
+                    db.ColorScheme = info?.ColorScheme ?? DatabaseSettings.DefaultColorScheme;
+                    db.Logo = info?.Logo;
                     new LocalConfiguration<DatabaseSettings>(key).Save(db);
                 }
             });

+ 44 - 27
prs.server/Engines/Database/DatabaseEngine.cs

@@ -12,6 +12,7 @@ using InABox.Core;
 using InABox.Database;
 using InABox.Database.SQLite;
 using InABox.IPC;
+using InABox.Rpc;
 using InABox.Server;
 using InABox.Wpf.Reports;
 using PRS.Shared;
@@ -24,10 +25,10 @@ namespace PRSServer
         private Timer? CertificateRefreshTimer;
         private Timer? CertificateHaltTimer;
         private string PipeName;
-        private IPCServer? PipeServer;
+        //private IPCServer? PipeServer;
 
-        //private IRPCServer? _pipeserver;
-        //private IRPCServer? _socketserver;
+        private IRpcServer? _pipeserver;
+        private IRpcServer? _socketserver;
         
         public override void Configure(Server server)
         {
@@ -175,7 +176,7 @@ namespace PRSServer
             DbFactory.Logo = Properties.Logo;
 
             DbFactory.Start();
-
+            
             UserStore.PasswordExpirationTime = TimeSpan.FromDays(Properties.PasswordExpiryTime);
             RestService.CheckPasswordExpiration = Properties.PasswordExpiryTime > 0;
 
@@ -202,32 +203,45 @@ namespace PRSServer
             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();
-            // _socketserver = new RPCServer<RPCServerSocketTransport>(() => new RPCServerSocketTransport(Properties.Port));
-            // _socketserver.OnLog += (type, userid, message) => Logger.Send(type, userid, $"[S] {message}");
-            // _socketserver.Start();
+            
+            // 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());
+            _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 RPCServer<RPCServerPipeTransport>(() => new RPCServerPipeTransport(PipeName));
-            // _pipeserver.OnLog += (type, userid, message) => Logger.Send(type, userid, $"[P] {message}");
-            // _pipeserver.Start();
-            PipeServer = new IPCServer(PipeName);
-            PipeServer.Start();
+            
+            // PipeServer = new IPCServer(PipeName);
+            // PipeServer.Start();
 
+            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();
+            
             Logger.Send(LogType.Information, "", "Pipe Listener started");
-
+            
             ConfigureNotifier();
+
+
+            
+
+            
+
+
+
         }
 
         #region Certificate Management
@@ -411,9 +425,12 @@ namespace PRSServer
         {
             Logger.Send(LogType.Information, "", "Stopping..");
 
-            //_pipeserver?.Stop();
-            //_pipeserver = null;
-            PipeServer?.Dispose();
+            _socketserver?.Stop();
+            _socketserver = null;
+            
+            _pipeserver?.Stop();
+            _pipeserver = null;
+            //PipeServer?.Dispose();
 
             RestListener.Stop();
             CredentialsCache.SaveSessionCache();

+ 4 - 3
prs.server/Engines/Engine.cs

@@ -4,6 +4,7 @@ using System.Reflection;
 using InABox.Core;
 using InABox.IPC;
 using InABox.Logging;
+using InABox.Rpc;
 
 namespace PRSServer
 {
@@ -23,7 +24,7 @@ namespace PRSServer
     public abstract class Engine<TProperties> : IEngine where TProperties : ServerProperties
     {
         
-        private RPCServerPipeTransport _enginemanager;
+        private RpcServerPipeTransport _enginemanager;
 
         public TProperties Properties { get; private set; }
         public abstract void Run();
@@ -48,8 +49,8 @@ namespace PRSServer
             MainLogger.AddLogger(new LogFileLogger(AppDataFolder));
             MainLogger.AddLogger(new NamedPipeLogger(server.Key));
             
-            _enginemanager = new RPCServerPipeTransport($"{ServiceName}$");
-            _enginemanager.AddHandler<IEngine, PortStatusCommand, PortStatusParameters, PortStatus[]>(new PortStatusHandler(this));
+            _enginemanager = new RpcServerPipeTransport($"{ServiceName}$");
+            _enginemanager.AddHandler<IEngine, PortStatusCommand, PortStatusParameters, PortStatusResult>(new PortStatusHandler(this));
             _enginemanager.AfterMessage += (transport, args) => MainLogger.Send(LogType.Information,"",$"Engine Manager Message: {args.Message?.Command}");
             _enginemanager.Start();
         }

+ 39 - 7
prs.server/Engines/PortStatus.cs

@@ -1,5 +1,5 @@
-using System.Collections.Generic;
-using InABox.IPC;
+using InABox.Core;
+using InABox.Rpc;
 
 namespace PRSServer
 {
@@ -45,13 +45,45 @@ namespace PRSServer
     
     //public class PortStatus[] : List<PortStatus> { }
     
-    public class PortStatusCommand : IRPCCommand<PortStatusParameters,PortStatus[]> { }
-    
-    public class PortStatusParameters { }
+    public class PortStatusCommand : IRpcCommand<PortStatusParameters,PortStatusResult> { }
+
+    public class PortStatusParameters : ISerializeBinary
+    {
+        public void SerializeBinary(CoreBinaryWriter writer)
+        {throw new System.NotImplementedException();
+            
+        }
+
+        public void DeserializeBinary(CoreBinaryReader reader)
+        {
+            throw new System.NotImplementedException();
+        }
+    }
+
+    public class PortStatusResult : ISerializeBinary
+    {
+        
+        public PortStatus[] Ports { get; set; }
+
+        public PortStatusResult()
+        {
+            Ports = new PortStatus[] { };
+        }
+        public void SerializeBinary(CoreBinaryWriter writer)
+        {
+            writer.WriteBinaryValue(Ports);
+        }
+
+        public void DeserializeBinary(CoreBinaryReader reader)
+        {
+            Ports = reader.ReadBinaryValue<PortStatus[]>();
+        }
+    }
     
-    public class PortStatusHandler : RPCCommandHandler<IEngine,PortStatusParameters,PortStatus[]> 
+    public class PortStatusHandler : RpcCommandHandler<IEngine,PortStatusParameters,PortStatusResult> 
     {
-        public override PortStatus[]? Execute(PortStatusParameters? parameters) => Sender.PortStatusList();
+        protected override PortStatusResult Execute(IRpcSession session, PortStatusParameters? parameters) 
+            => new PortStatusResult() { Ports = Sender.PortStatusList() };
 
         public PortStatusHandler(IEngine sender) : base(sender)
         {

+ 3 - 3
prs.server/Engines/WebEngine/WebListener.cs

@@ -358,15 +358,15 @@ namespace PRSServer
             var validation = Client.Validate(username, password);
             switch (validation.Status)
             {
-                case ValidationResult.INVALID:
+                case ValidationStatus.INVALID:
                     Logger.Send(LogType.Information, "", "User name or password is incorrect");
                     return request.Respond().Status(ResponseStatus.Unauthorized);
-                case ValidationResult.PASSWORD_EXPIRED:
+                case ValidationStatus.PASSWORD_EXPIRED:
                     Logger.Send(LogType.Information, "", "Password has expired");
                     return request.Respond().Status(ResponseStatus.Unauthorized);
             }
 
-            var require2FA = validation.Status == ValidationResult.REQUIRE_2FA;
+            var require2FA = validation.Status == ValidationStatus.REQUIRE_2FA;
 
             var newSessionID = Guid.NewGuid();
             var user = new User

+ 8 - 11
prs.server/Forms/ServiceStatus.xaml.cs

@@ -4,15 +4,12 @@ using System.ComponentModel;
 using System.Linq;
 using System.Net;
 using System.Net.Sockets;
-using System.Threading;
 using System.Threading.Tasks;
 using System.Windows;
-using H.Pipes;
 using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
-using InABox.IPC;
-using Microsoft.Exchange.WebServices.Autodiscover;
+using InABox.Rpc;
 
 namespace PRSServer
 {
@@ -63,7 +60,7 @@ namespace PRSServer
     public partial class ServiceStatus : Window
     {
 
-        private List<RPCClientPipeTransport> _pipes = new List<RPCClientPipeTransport>();
+        private List<RpcClientPipeTransport> _pipes = new List<RpcClientPipeTransport>();
         
         private String[] _domains;
         private Server[] _servers;
@@ -121,7 +118,7 @@ namespace PRSServer
         {
             foreach (var server in servers)
             {
-                var manager = new RPCClientPipeTransport($"{server.Key}$");
+                var manager = new RpcClientPipeTransport($"{server.Key}$");
                 manager.OnOpen += (o,e) => Task.Run(() =>
                 {
                     Dispatcher.Invoke(() => { Messages.Items.Add("Connected to Server"); });
@@ -129,17 +126,17 @@ namespace PRSServer
                     //{
                         try
                         {
-                            var statuses = manager.Send<PortStatusCommand, PortStatusParameters, PortStatus[]>(new PortStatusParameters());
-                            foreach (var status in statuses)
+                            var result = manager.Send<PortStatusCommand, PortStatusParameters, PortStatusResult>(new PortStatusParameters());
+                            foreach (var port in result.Ports)
                             {
                                 Dispatcher.Invoke(() =>
                                 {
-                                    Messages.Items.Add($"{server.Key}: {status.Type}({status.Port}) -> {status.State}");
+                                    Messages.Items.Add($"{server.Key}: {port.Type}({port.Port}) -> {port.State}");
                                     
                                     foreach (var domain in _domains)
                                     {
-                                        if (status.Type == PortType.Database)
-                                            Messages.Items.Add($"Database {domain}:{status.Port} -> {CheckDatabase(domain,status.Port)}");
+                                        if (port.Type == PortType.Database)
+                                            Messages.Items.Add($"Database {domain}:{port.Port} -> {CheckDatabase(domain,port.Port)}");
                                     }
                                 });
                             }