Prechádzať zdrojové kódy

Fixed Serialization Issues in Pipe Transports

frogsoftware 1 týždeň pred
rodič
commit
c52ad474e0

+ 1 - 1
InABox.Client.RPC/InABox.Client.RPC.csproj

@@ -7,7 +7,7 @@
     </PropertyGroup>
 
     <ItemGroup>
-      <ProjectReference Include="..\InABox.Formatters.MemoryPack\InABox.Formatters.MemoryPack.csproj" />
+      <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
       <ProjectReference Include="..\InABox.RPC.Shared\InABox.RPC.Shared.csproj" />
     </ItemGroup>
 

+ 2 - 3
InABox.Client.RPC/Transports/Pipe/RPCClientPipeTransport.cs

@@ -1,9 +1,8 @@
 using System;
 using System.Threading;
-using H.Formatters;
+using InABox.Formatters;
 using H.Pipes;
 using InABox.Core;
-using InABox.Formatters;
 
 namespace InABox.Rpc
 {
@@ -15,7 +14,7 @@ namespace InABox.Rpc
         public RpcClientPipeTransport(string name)
         {
             _name = name;
-            _pipe = new PipeClient<RpcMessage>(_name, new MemoryPackFormatter<RpcMessage>());
+            _pipe = new PipeClient<RpcMessage>(_name, new CoreFormatter<RpcMessage>());
             _pipe.Connected += PipeConnected;
             _pipe.Disconnected += PipeDisconnected;
             _pipe.MessageReceived += PipeMessageReceived;

+ 32 - 0
InABox.Formatters.Core/CoreFormattableString.cs

@@ -0,0 +1,32 @@
+using System.IO;
+
+namespace InABox.Formatters
+{
+
+    public class CoreFormattableString : ICoreFormattable
+    {
+        public string Content { get; set; }
+
+        public CoreFormattableString()
+        {
+            
+        }
+
+        public CoreFormattableString(string content)
+        {
+            Content = content;
+        }
+
+        public void Write(BinaryWriter writer)
+        {
+            writer.Write(Content);
+        }
+
+        public void Read(BinaryReader reader)
+        {
+            Content = reader.ReadString();
+        }
+    }
+
+
+}

+ 47 - 0
InABox.Formatters.Core/CoreFormatter.cs

@@ -0,0 +1,47 @@
+using System;
+using System.IO;
+using System.Linq;
+using H.Formatters;
+
+
+public interface ICoreFormattable
+{
+    void Write(BinaryWriter writer);
+    void Read(BinaryReader reader);
+}
+
+namespace InABox.Formatters
+{
+    public class CoreFormatter<T1> : FormatterBase where T1 : ICoreFormattable
+    {
+        
+        protected override byte[] SerializeInternal(object obj)
+        {
+
+            if (obj is ICoreFormattable _formattable)
+            {
+                using (var ms = new MemoryStream())
+                {
+                    using (var writer = new BinaryWriter(ms))
+                        _formattable.Write(writer);
+                    return ms.ToArray();
+                }
+            }
+            return new byte[] { };
+        }
+
+        protected override T DeserializeInternal<T>(byte[] bytes)
+        {
+            if (bytes.Any() && Activator.CreateInstance<T>() is ICoreFormattable result)
+            {
+                using (var ms = new MemoryStream(bytes))
+                {
+                    using (var reader = new BinaryReader(ms))
+                        result.Read(reader);
+                    return (T)result;
+                }
+            }
+            return default;
+        }
+    }
+}

+ 2 - 3
InABox.Formatters.MemoryPack/InABox.Formatters.MemoryPack.csproj → InABox.Formatters.Core/InABox.Formatters.Core.csproj

@@ -1,13 +1,12 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <Nullable>enable</Nullable>
-        <TargetFrameworks>netstandard2.1;net8.0</TargetFrameworks>
+        <RootNamespace>InABox.Formatters.MessagePack</RootNamespace>
+        <TargetFramework>netstandard2.0</TargetFramework>
     </PropertyGroup>
 
     <ItemGroup>
       <PackageReference Include="H.Formatters" Version="15.0.0" />
-      <PackageReference Include="MemoryPack" Version="1.21.4" />
     </ItemGroup>
 
 </Project>

+ 0 - 19
InABox.Formatters.MemoryPack/MemoryPackFormatter.cs

@@ -1,19 +0,0 @@
-using H.Formatters;
-using MemoryPack;
-
-namespace InABox.Formatters
-{
-
-    public class MemoryPackFormatter<T1> : FormatterBase
-    {
-        protected override byte[] SerializeInternal(object obj)
-        {
-            return MemoryPackSerializer.Serialize<T1>((T1)obj);
-        }
-
-        protected override T DeserializeInternal<T>(byte[] bytes)
-        {
-            return MemoryPackSerializer.Deserialize<T>(bytes);
-        }
-    }
-}

+ 1 - 0
InABox.Integration.Logikal/InABox.Integration.Logikal.csproj

@@ -12,6 +12,7 @@
     </ItemGroup>
 
     <ItemGroup>
+      <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
       <ProjectReference Include="..\InABox.Integration\InABox.Integration.csproj" />
     </ItemGroup>
 

+ 16 - 1
InABox.Integration.Logikal/LogikalMessage.cs

@@ -1,9 +1,11 @@
 using System;
+using System.IO;
+using InABox.Formatters;
 using Newtonsoft.Json;
 
 namespace InABox.Integration.Logikal
 {
-    public class LogikalMessage
+    public class LogikalMessage : ICoreFormattable
     {
         public Guid ID { get; set; }
         public LogikalMethod Method { get; set; }
@@ -23,5 +25,18 @@ namespace InABox.Integration.Logikal
             };
         }
 
+        public void Write(BinaryWriter writer)
+        {
+            writer.Write(ID.ToByteArray());
+            writer.Write((Int32)Method);
+            writer.Write(Payload);
+        }
+
+        public void Read(BinaryReader reader)
+        {
+            ID = new Guid(reader.ReadBytes(16));
+            Method = (LogikalMethod)reader.ReadInt32();
+            Payload = reader.ReadString();
+        }
     }
 }

+ 16 - 0
InABox.Logging/ConsoleLogger.cs

@@ -0,0 +1,16 @@
+using InABox.Core;
+
+namespace InABox.Logging;
+
+public class ConsoleLogger : LoggerBase
+{
+    public ConsoleLogger()
+    {
+        LogTypes = new LogType[] { LogType.Information, LogType.Error };
+    }
+
+    protected override void DoSend(string message)
+    {
+        Console.WriteLine(message);
+    }
+}

+ 16 - 0
InABox.Logging/EventLogger.cs

@@ -0,0 +1,16 @@
+namespace InABox.Logging;
+
+public class EventLogger : LoggerBase
+{
+    public Action<string>? OnLog;
+
+    public EventLogger(Action<string>? onLog = null)
+    {
+        OnLog = onLog;
+    }
+
+    protected override void DoSend(string message)
+    {
+        OnLog?.Invoke(message);
+    }
+}

+ 1 - 1
InABox.Logging/InABox.Logging.csproj

@@ -26,7 +26,7 @@
     </ItemGroup>
 
     <ItemGroup>
-        <ProjectReference Include="..\InABox.Formatters.MemoryPack\InABox.Formatters.MemoryPack.csproj" />
+        <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
         <ProjectReference Include="..\inabox.logging.shared\InABox.Logging.Shared.csproj" />
     </ItemGroup>
 

+ 94 - 0
InABox.Logging/LogFileLogger.cs

@@ -0,0 +1,94 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Text;
+using InABox.Core;
+
+namespace InABox.Logging;
+
+public class LogFileLogger : LoggerBase
+{
+    private static readonly object logfileLock = new();
+    private string TmpFolder;
+
+    private string _folder;
+    public string Folder
+    {
+        get => _folder;
+        [MemberNotNull(nameof(_folder), nameof(TmpFolder))]
+        set
+        {
+            _folder = value;
+            TmpFolder = Path.Combine(Folder, "Temp");
+            if (Directory.Exists(TmpFolder))
+            {
+                Directory.CreateDirectory(TmpFolder);
+                var files = Directory.GetFiles(TmpFolder);
+                foreach (var file in files)
+                    File.Delete(file);
+            }
+        }
+    }
+
+    public LogFileLogger(string folder)
+    {
+        Folder = folder;
+    }
+
+    public override void Send(LogType logtype, string user, string message, Guid transaction)
+    {
+        if (logtype == LogType.Update)
+            UpdateJournal(message);
+        else
+            base.Send(logtype, user, message, transaction);
+    }
+
+    protected override void DoSend(string message)
+    {
+        if (!string.IsNullOrEmpty(Folder))
+        {
+            UpdateLogFile(message);
+        }
+    }
+    private void UpdateLogFile(string msg)
+    {
+        if (!Directory.Exists(Folder)) Directory.CreateDirectory(Folder);
+        var filename = Path.Combine(Folder, string.Format("{0:yyyy-MM-dd}.log", DateTime.Today));
+        try
+        {
+            lock (logfileLock)
+            {
+                using (var sw = new StreamWriter(filename, true, Encoding.UTF8, 65536))
+                {
+                    sw.WriteLine(msg);
+                    sw.Close();
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine("*** Failed to Update Log: " + e.Message);
+            Console.WriteLine("*** Message: " + msg);
+        }
+    }
+
+    private void UpdateJournal(string sql)
+    {
+        var filename = Path.Combine(Folder, string.Format("{0:yyyy-MM-dd}.sql", DateTime.Today));
+        try
+        {
+            lock (logfileLock)
+            {
+                using (var sw = new StreamWriter(filename, true, Encoding.UTF8, 65536))
+                {
+                    sw.WriteLine(sql);
+                    sw.Close();
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine("*** Failed to Update SQL Journal: " + e.Message);
+            Console.WriteLine("*** Message: " + sql);
+        }
+    }
+
+}

+ 36 - 0
InABox.Logging/LoggerBase.cs

@@ -0,0 +1,36 @@
+using InABox.Core;
+
+namespace InABox.Logging;
+
+public abstract class LoggerBase
+{
+    public LogType[] LogTypes = { LogType.Information, LogType.Query, LogType.Update, LogType.Error, LogType.Important };
+
+    protected abstract void DoSend(string message);
+
+    public virtual void Send(LogType logType, string user, string message, Guid transaction)
+    {
+        if (!LogTypes.Any(x => x == logType))
+            return;
+        var type = logType switch
+        {
+            LogType.Information => "INFO",
+            LogType.Query => "READ",
+            LogType.Update => "UPDATE",
+            LogType.Error => "ERROR",
+            LogType.Important => "IMPTNT",
+            _ => "ERROR"
+        };
+        var msg = string.Format("{0:HH:mm:ss.fff} {1} {2} {3} {4}",
+            DateTime.Now,
+            transaction,
+            type?.PadRight(6),
+            (user ?? "").PadRight(12),
+            message
+        );
+
+        DoSend(msg);
+    }
+
+    public virtual void Stop() { }
+}

+ 42 - 0
InABox.Logging/MainLogger.cs

@@ -0,0 +1,42 @@
+using InABox.Core;
+
+namespace InABox.Logging;
+
+public static class MainLogger
+{
+    private static List<LoggerBase> Loggers = new();
+
+    public static void AddLogger(LoggerBase logger)
+    {
+        Loggers.Add(logger);
+    }
+    public static void RemoveLogger(LoggerBase logger)
+    {
+        Loggers.Remove(logger);
+    }
+
+    public static void Send(LogType logType, string user, string message, Guid transaction)
+    {
+        foreach(var logger in Loggers)
+        {
+            try
+            {
+                logger.Send(logType, user, message, transaction);
+            }
+            catch (Exception e)
+            {
+                Logger.Send(LogType.Error, "LOGERROR",
+                    $"Exception in Logger.Send ({e.Message}) Message=[{message}]");
+            }
+                
+        }
+    }
+
+    public static void Stop()
+    {
+        foreach (var logger in Loggers)
+        {
+            logger.Stop();
+        }
+    }
+}

+ 7 - 200
InABox.Logging/NamedPipeLogger.cs

@@ -1,179 +1,25 @@
 using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Text;
-using H.Formatters;
-using H.Pipes;
-using InABox.Core;
 using InABox.Formatters;
+using H.Pipes;
 
 namespace InABox.Logging
 {
-    public abstract class LoggerBase
-    {
-        public LogType[] LogTypes = { LogType.Information, LogType.Query, LogType.Update, LogType.Error, LogType.Important };
-
-        protected abstract void DoSend(string message);
-
-        public virtual void Send(LogType logType, string user, string message, Guid transaction)
-        {
-            if (!LogTypes.Any(x => x == logType))
-                return;
-            var type = logType switch
-            {
-                LogType.Information => "INFO",
-                LogType.Query => "READ",
-                LogType.Update => "UPDATE",
-                LogType.Error => "ERROR",
-                LogType.Important => "IMPTNT",
-                _ => "ERROR"
-            };
-            var msg = string.Format("{0:HH:mm:ss.fff} {1} {2} {3} {4}",
-                DateTime.Now,
-                transaction,
-                type?.PadRight(6),
-                (user ?? "").PadRight(12),
-                message
-            );
-
-            DoSend(msg);
-        }
-
-        public virtual void Stop() { }
-    }
-
-    public class EventLogger : LoggerBase
-    {
-        public Action<string>? OnLog;
-
-        public EventLogger(Action<string>? onLog = null)
-        {
-            OnLog = onLog;
-        }
-
-        protected override void DoSend(string message)
-        {
-            OnLog?.Invoke(message);
-        }
-    }
-
-    public class ConsoleLogger : LoggerBase
-    {
-        public ConsoleLogger()
-        {
-            LogTypes = new LogType[] { LogType.Information, LogType.Error };
-        }
-
-        protected override void DoSend(string message)
-        {
-            Console.WriteLine(message);
-        }
-    }
-
-    public class LogFileLogger : LoggerBase
-    {
-        private static readonly object logfileLock = new();
-        private string TmpFolder;
-
-        private string _folder;
-        public string Folder
-        {
-            get => _folder;
-            [MemberNotNull(nameof(_folder), nameof(TmpFolder))]
-            set
-            {
-                _folder = value;
-                TmpFolder = Path.Combine(Folder, "Temp");
-                if (Directory.Exists(TmpFolder))
-                {
-                    Directory.CreateDirectory(TmpFolder);
-                    var files = Directory.GetFiles(TmpFolder);
-                    foreach (var file in files)
-                        File.Delete(file);
-                }
-            }
-        }
-
-        public LogFileLogger(string folder)
-        {
-            Folder = folder;
-        }
-
-        public override void Send(LogType logtype, string user, string message, Guid transaction)
-        {
-            if (logtype == LogType.Update)
-                UpdateJournal(message);
-            else
-                base.Send(logtype, user, message, transaction);
-        }
-
-        protected override void DoSend(string message)
-        {
-            if (!string.IsNullOrEmpty(Folder))
-            {
-                UpdateLogFile(message);
-            }
-        }
-        private void UpdateLogFile(string msg)
-        {
-            if (!Directory.Exists(Folder)) Directory.CreateDirectory(Folder);
-            var filename = Path.Combine(Folder, string.Format("{0:yyyy-MM-dd}.log", DateTime.Today));
-            try
-            {
-                lock (logfileLock)
-                {
-                    using (var sw = new StreamWriter(filename, true, Encoding.UTF8, 65536))
-                    {
-                        sw.WriteLine(msg);
-                        sw.Close();
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-                Console.WriteLine("*** Failed to Update Log: " + e.Message);
-                Console.WriteLine("*** Message: " + msg);
-            }
-        }
-
-        private void UpdateJournal(string sql)
-        {
-            var filename = Path.Combine(Folder, string.Format("{0:yyyy-MM-dd}.sql", DateTime.Today));
-            try
-            {
-                lock (logfileLock)
-                {
-                    using (var sw = new StreamWriter(filename, true, Encoding.UTF8, 65536))
-                    {
-                        sw.WriteLine(sql);
-                        sw.Close();
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-                Console.WriteLine("*** Failed to Update SQL Journal: " + e.Message);
-                Console.WriteLine("*** Message: " + sql);
-            }
-        }
-
-    }
-
     public class NamedPipeLogger : LoggerBase
     {
-        private PipeServer<string> _pipe;
+        private PipeServer<CoreFormattableString> _pipe;
         private string _name = "";
 
         public NamedPipeLogger(string name = "")
         {
             _name = string.IsNullOrWhiteSpace(name) ? Process.GetCurrentProcess().ProcessName : name;
-            _pipe = new PipeServer<string>(_name, new MemoryPackFormatter<string>());
+            _pipe = new PipeServer<CoreFormattableString>(_name, new CoreFormatter<CoreFormattableString>());
             _pipe.ClientConnected += _pipe_ClientConnected;
             _pipe.StartAsync();
         }
 
-        private void _pipe_ClientConnected(object? sender, H.Pipes.Args.ConnectionEventArgs<string> e)
+        private void _pipe_ClientConnected(object? sender, H.Pipes.Args.ConnectionEventArgs<CoreFormattableString> e)
         {
-            _pipe.WriteAsync("Connected to " + _name);
+            _pipe.WriteAsync(new CoreFormattableString($"Connected to {_name}"));
         }
         public override void Stop()
         {
@@ -182,47 +28,8 @@ namespace InABox.Logging
 
         protected override void DoSend(string message)
         {
-            if (_pipe != null)
-                _pipe.WriteAsync(message);
-        }
-    }
-
-    public static class MainLogger
-    {
-        private static List<LoggerBase> Loggers = new();
-
-        public static void AddLogger(LoggerBase logger)
-        {
-            Loggers.Add(logger);
-        }
-        public static void RemoveLogger(LoggerBase logger)
-        {
-            Loggers.Remove(logger);
-        }
-
-        public static void Send(LogType logType, string user, string message, Guid transaction)
-        {
-            foreach(var logger in Loggers)
-            {
-                try
-                {
-                    logger.Send(logType, user, message, transaction);
-                }
-                catch (Exception e)
-                {
-                    Logger.Send(LogType.Error, "LOGERROR",
-                        $"Exception in Logger.Send ({e.Message}) Message=[{message}]");
-                }
-                
-            }
-        }
-
-        public static void Stop()
-        {
-            foreach (var logger in Loggers)
-            {
-                logger.Stop();
-            }
+            if (_pipe.ConnectedClients.Any())
+                _pipe.WriteAsync(new CoreFormattableString(message));
         }
     }
 }

+ 1 - 1
InABox.RPC.Shared/InABox.RPC.Shared.csproj

@@ -7,12 +7,12 @@
     </PropertyGroup>
 
     <ItemGroup>
-      <PackageReference Include="MemoryPack" Version="1.21.4" />
       <PackageReference Include="MessagePack.Annotations" Version="2.5.192" />
     </ItemGroup>
 
     <ItemGroup>
       <ProjectReference Include="..\InABox.Core\InABox.Core.csproj" />
+      <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
     </ItemGroup>
 
 </Project>

+ 21 - 6
InABox.RPC.Shared/RPCMessage.cs

@@ -1,14 +1,12 @@
 using System;
+using System.IO;
 using InABox.Core;
 using MessagePack;
-using MemoryPack;
 
 namespace InABox.Rpc
 {
     [Serializable]
-    [MessagePackObject(keyAsPropertyName: true)]
-    [MemoryPackable]
-    public partial class RpcMessage : ISerializeBinary
+    public partial class RpcMessage : ISerializeBinary, ICoreFormattable
     {
         public Guid Id { get; set; }
         public String Command { get; set; }
@@ -16,8 +14,7 @@ namespace InABox.Rpc
         public RpcError Error { get; set; }
 
         public override string ToString() => $"{Command} [{Error}]";
-
-        [MemoryPackConstructor]
+        
         public RpcMessage()
         {
             Id = Guid.NewGuid();
@@ -52,5 +49,23 @@ namespace InABox.Rpc
             if (Enum.TryParse<RpcError>(reader.ReadString(), out var error))
                 Error = error;
         }
+        
+        public void Write(BinaryWriter writer)
+        {
+            writer.Write(Id);
+            writer.Write(Command);
+            writer.Write(Payload.Length);
+            writer.Write(Payload);
+            writer.Write((Int32)Error);
+        }
+
+        public void Read(BinaryReader reader)
+        {
+            Id = reader.ReadGuid();
+            Command = reader.ReadString();
+            var _length = reader.ReadInt32();
+            Payload = reader.ReadBytes(_length);
+            Error = (RpcError)reader.ReadInt32();
+        }
     }
 }

+ 9 - 5
InABox.Server/IPC/IPCServer.cs

@@ -8,7 +8,6 @@ using InABox.Server;
 using System.IO.Pipes;
 using System.Reflection;
 using System.Security.Principal;
-using H.Formatters;
 using InABox.Formatters;
 
 namespace InABox.IPC
@@ -22,7 +21,7 @@ namespace InABox.IPC
         public IPCServer(string name)
         {
 
-            Server = new PipeServer<IPCMessage>(name, new MemoryPackFormatter<IPCMessage>());
+            Server = new PipeServer<IPCMessage>(name, new CoreFormatter<IPCMessage>());
             
             #if WINDOWS
             SetPipeSecurity();
@@ -75,7 +74,7 @@ namespace InABox.IPC
 
         private static Type? GetResponseType(Method method, string? entityName)
         {
-            if(entityName != null)
+            if(!string.IsNullOrWhiteSpace(entityName))
             {
                 var entityType = GetEntity(entityName);
                 if(entityType != null)
@@ -125,7 +124,12 @@ namespace InABox.IPC
             return request.Respond(response);
         }
 
-        private IPCMessage Ping(IPCMessage request, RequestData data) => request.Respond(new PingResponse().Status(StatusCode.OK));
+        private IPCMessage Ping(IPCMessage request, RequestData data)
+        {
+            var response = new PingResponse().Status(StatusCode.OK);
+            var result = request.Respond(response);
+            return result;
+        }
 
         private IPCMessage Info(IPCMessage request, RequestData data)
         {
@@ -219,7 +223,7 @@ namespace InABox.IPC
                         Method.None or _ => throw new Exception($"Invalid method '{e.Message.Method}'")
                     };
 
-                    if (e.Message.Type != null)
+                    if (!string.IsNullOrWhiteSpace(e.Message.Type))
                     {
                         var entityType = GetEntity(e.Message.Type) ?? throw new Exception($"No entity '{e.Message.Type}'");
                         method = method.MakeGenericMethod(entityType);

+ 1 - 1
InABox.Server/InABox.Server.csproj

@@ -17,7 +17,7 @@
 
     <ItemGroup>
         <ProjectReference Include="..\InABox.Database\InABox.Database.csproj" />
-        <ProjectReference Include="..\InABox.Formatters.MemoryPack\InABox.Formatters.MemoryPack.csproj" />
+        <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
         <ProjectReference Include="..\InABox.IPC.Shared\InABox.IPC.Shared.csproj" />
         <ProjectReference Include="..\InABox.Logging.Shared\InABox.Logging.Shared.csproj" />
         <ProjectReference Include="..\InABox.Mailer.Exchange\InABox.Mailer.Exchange.csproj" />

+ 3 - 4
InABox.Server/RPC/Transports/Pipe/RPCServerPipeTransport.cs

@@ -1,15 +1,14 @@
 using System.IO.Pipes;
 using System.Security.Principal;
-using H.Formatters;
+using InABox.Formatters;
 using H.Pipes;
 using H.Pipes.AccessControl;
-using InABox.Formatters;
 
 namespace InABox.Rpc
 {
     public class RpcServerPipeTransport : RpcServerTransport<PipeConnection<RpcMessage?>>, IDisposable
     {
-        private PipeServer<RpcMessage?> _transport;
+        private PipeServer<RpcMessage> _transport;
 
         public override bool IsSecure() => false;
         
@@ -33,7 +32,7 @@ namespace InABox.Rpc
         public RpcServerPipeTransport(string name)
         {
 
-            _transport = new PipeServer<RpcMessage?>(name, new MemoryPackFormatter<RpcMessage>());
+            _transport = new PipeServer<RpcMessage>(name, new CoreFormatter<RpcMessage>());
 
 
             #if WINDOWS

+ 2 - 1
inabox.client.ipc/IPCClient.cs

@@ -97,7 +97,8 @@ namespace InABox.IPC
 
                 PrepareRequest(request);
 
-                var response = Send(IPCMessage.Ping(request), 10_000)?.GetResponse<PingResponse>();
+                var message = Send(IPCMessage.Ping(request), 100_000);
+                var response = message?.GetResponse<PingResponse>();
                 if (response != null)
                 {
                     return response.Status switch

+ 3 - 4
inabox.client.ipc/IPCClientTransport.cs

@@ -2,7 +2,6 @@
 using InABox.Core;
 using InABox.IPC;
 using System.Collections.Concurrent;
-using H.Formatters;
 using InABox.Formatters;
 
 namespace InABox.Client.IPC
@@ -32,12 +31,11 @@ namespace InABox.Client.IPC
 
         public IPCClientTransport(string pipeName)
         {
-            Client = new PipeClient<IPCMessage>(pipeName, new MemoryPackFormatter<IPCMessage>());
+            Client = new PipeClient<IPCMessage>(pipeName, new CoreFormatter<IPCMessage>());
             Client.Connected += Client_Connected;
             Client.Disconnected += Client_Disconnected;
             Client.MessageReceived += Client_MessageReceived;
             Client.ExceptionOccurred += Client_ExceptionOccurred;
-
             Client.ConnectAsync();
         }
 
@@ -50,7 +48,8 @@ namespace InABox.Client.IPC
         {
             var ev = Queue(request.RequestID);
             Client.WriteAsync(request);
-            return GetResult(request.RequestID, ev, timeout);
+            var result =  GetResult(request.RequestID, ev, timeout);
+            return result;
         }
 
         public ManualResetEventSlim Queue(Guid id)

+ 1 - 1
inabox.client.ipc/InABox.Client.IPC.csproj

@@ -13,7 +13,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\InABox.Formatters.MemoryPack\InABox.Formatters.MemoryPack.csproj" />
+    <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
     <ProjectReference Include="..\InABox.IPC.Shared\InABox.IPC.Shared.csproj" />
   </ItemGroup>
 

+ 50 - 23
inabox.ipc.shared/IPCMessage.cs

@@ -1,11 +1,6 @@
 using InABox.Clients;
 using InABox.Core;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.NetworkInformation;
-using System.Text;
-using System.Threading.Tasks;
-using MemoryPack;
+using InABox.Formatters;
 
 namespace InABox.IPC
 {
@@ -35,42 +30,47 @@ namespace InABox.IPC
         ReleaseNotes,
         Installer
     }
-
-    [Serializable]
-    [MemoryPackable]
-    public partial class IPCMessage
+    
+    public class IPCMessage :  ISerializeBinary, ICoreFormattable
     {
-        public Guid RequestID;
-        public Method Method;
-        public string? Type;
-        private string? Data;
-        private byte[]? BinaryData;
-
-        [NonSerialized]
+        public Guid RequestID { get; set; }
+        
+        public Method Method { get; set; }
+        
+        public string? Type { get; set; }
+        
+        public string? Data { get; set; }
+        
+        public byte[]? BinaryData { get; set; }
+        
         public RequestError ErrorCode;
 
-        [MemoryPackConstructor]
         public IPCMessage()
         {
-            
+            RequestID = Guid.Empty;
+            Method = Method.None;
+            Type = "";
+            Data = "";
+            BinaryData = [];
+            ErrorCode = RequestError.UNKNOWN;
         }
         
-        private IPCMessage(Guid requestID, Method method, string? type, string data, RequestError error = RequestError.NONE) : this()
+        private IPCMessage(Guid requestID, Method method, string type, string data, RequestError error = RequestError.NONE) : this()
         {
             RequestID = requestID;
             Method = method;
             Type = type;
             Data = data;
-            BinaryData = null;
+            BinaryData = [];
             ErrorCode = error;
         }
-        private IPCMessage(Guid requestID, Method method, string? type, byte[] data, RequestError error = RequestError.NONE) : this()
+        private IPCMessage(Guid requestID, Method method, string type, byte[] data, RequestError error = RequestError.NONE) : this()
         {
             RequestID = requestID;
             Method = method;
             Type = type;
             BinaryData = data;
-            Data = null;
+            Data = "";
             ErrorCode = error;
         }
 
@@ -124,6 +124,7 @@ namespace InABox.IPC
             switch (ErrorCode)
             {
                 case RequestError.NONE:
+                    response.Status = StatusCode.OK;
                     break;
                 case RequestError.DISCONNECTED:
                     response.Status = StatusCode.Error;
@@ -217,5 +218,31 @@ namespace InABox.IPC
         {
             return CreateRequest(Guid.NewGuid(), Method.Push, TPush.EntityName(), push);
         }
+
+        public void SerializeBinary(CoreBinaryWriter writer) => Write(writer);
+        public void DeserializeBinary(CoreBinaryReader reader) => Read(reader);
+
+        public void Write(BinaryWriter writer)
+        {
+            writer.Write(RequestID);
+            writer.Write((Int32)Method);
+            writer.Write(Type ?? "");
+            writer.Write(Data ?? "");
+            writer.Write(BinaryData?.Length ?? 0);
+            if (BinaryData != null)
+                writer.Write(BinaryData);
+            writer.Write((Int32)ErrorCode);
+        }
+
+        public void Read(BinaryReader reader)
+        {
+            RequestID = reader.ReadGuid();
+            Method = (Method)reader.ReadInt32();
+            Type = reader.ReadString();
+            Data = reader.ReadString();
+            var _length = reader.ReadInt32();
+            BinaryData = reader.ReadBytes(_length);
+            ErrorCode = (RequestError)reader.ReadInt32();
+        }
     }
 }

+ 2 - 1
inabox.ipc.shared/InABox.IPC.Shared.csproj

@@ -8,11 +8,12 @@
 
   <ItemGroup>
     <ProjectReference Include="..\InABox.Database\InABox.Database.csproj" />
+    <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />
   </ItemGroup>
 
   <ItemGroup>
     <PackageReference Include="H.Pipes" Version="15.0.0" />
-    <PackageReference Include="MemoryPack" Version="1.21.4" />
+    <PackageReference Include="MessagePack.Annotations" Version="2.5.192" />
     <PackageReference Include="System.Collections.Immutable" Version="9.0.6" />
   </ItemGroup>