Browse Source

Renamed notificatiosn to pushes

Kenric Nugteren 2 years ago
parent
commit
72f302f12e

+ 10 - 10
InABox.Client.Local/LocalClient.cs

@@ -4,7 +4,7 @@ using InABox.WebSocket.Shared;
 
 namespace InABox.Clients
 {
-    class LocalNotifier : INotifier
+    class LocalPusher : IPusher
     {
         public IEnumerable<Guid> GetUserSessions(Guid userID)
         {
@@ -24,19 +24,19 @@ namespace InABox.Clients
             return Array.Empty<Guid>();
         }
 
-        public void NotifyAll<TNotification>(TNotification notification) where TNotification : BaseObject
+        public void PushToAll<TPush>(TPush push) where TPush : BaseObject
         {
-            ClientFactory.Notifications.Notify(typeof(TNotification), notification);
+            ClientFactory.PushHandlers.Push(typeof(TPush), push);
         }
 
-        public void NotifySession<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject
-            => NotifySession(session, typeof(TNotification), notification);
+        public void PushToSession<TPush>(Guid session, TPush push) where TPush : BaseObject
+            => PushToSession(session, typeof(TPush), push);
 
-        public void NotifySession(Guid session, Type TNotification, BaseObject notification)
+        public void PushToSession(Guid session, Type TPush, BaseObject push)
         {
             if (session == ClientFactory.SessionID)
             {
-                ClientFactory.Notifications.Notify(TNotification, notification);
+                ClientFactory.PushHandlers.Push(TPush, push);
             }
         }
     }
@@ -45,9 +45,9 @@ namespace InABox.Clients
     {
         public LocalClient()
         {
-            var notifier = new LocalNotifier();
-            Notify.AddNotifier(notifier);
-            Notify.Poll(ClientFactory.SessionID);
+            var pusher = new LocalPusher();
+            PushManager.AddPusher(pusher);
+            PushManager.Poll(ClientFactory.SessionID);
         }
         
         public override bool IsConnected() => true;

+ 1 - 2
InABox.Core/Client/ClientFactory.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using InABox.Core;
-using InABox.Core.Notifications;
 using InABox.Mail;
 
 namespace InABox.Clients
@@ -55,7 +54,7 @@ namespace InABox.Clients
 
         public static int PINLength { get; } = 4;
         
-        public static Notifications Notifications { get; set; } = new Notifications();
+        public static PushHandlers PushHandlers { get; set; } = new PushHandlers();
 
         public delegate void RequestErrorHandler(RequestException e);
 

+ 1 - 1
InABox.Core/Client/Request.cs

@@ -88,7 +88,7 @@ namespace InABox.Clients
         Save,
         MultiSave,
         Query,
-        Notify
+        Push
     }
 
     public abstract class Response

+ 1 - 2
InABox.Core/DigitalForms/DFUtils.cs

@@ -1,5 +1,4 @@
-using InABox.Core.Notifications;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

+ 0 - 42
InABox.Core/Notifications/NotificationHandler.cs

@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace InABox.Core
-{
-    public interface INotificationHandler
-    {
-        /// <summary>
-        /// Receives a new notification from the server, called when a notification is pushed.
-        /// </summary>
-        /// <param name="o">The notification object</param>
-        void Receive(object? o);
-    }
-
-    public class NotificationHandler<TNotification> : INotificationHandler
-    {
-        public delegate void ReceiveEvent(TNotification notification);
-
-        public event ReceiveEvent? OnReceive;
-
-        public NotificationHandler() { }
-
-        public NotificationHandler(ReceiveEvent receive)
-        {
-            OnReceive += receive;
-        }
-
-        public void Receive(object? notification) => Receive((TNotification)notification);
-
-        /// <summary>
-        /// Receives a new notification from the server, called when a notification is pushed.
-        /// </summary>
-        /// <param name="notification">The notification received</param>
-        public void Receive(TNotification notification)
-        {
-            OnReceive?.Invoke(notification);
-        }
-    }
-}

+ 0 - 28
InABox.Core/Notifications/Notifications.cs

@@ -1,28 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace InABox.Core.Notifications
-{
-    public class Notifications
-    {
-        private Dictionary<Type, INotificationHandler> Handlers = new Dictionary<Type, INotificationHandler>();
-
-        public void AddHandler<TNotification>(NotificationHandler<TNotification> handler)
-        {
-            Handlers[typeof(TNotification)] = handler;
-        }
-        public void AddHandler<TNotification>(NotificationHandler<TNotification>.ReceiveEvent receive)
-        {
-            Handlers[typeof(TNotification)] = new NotificationHandler<TNotification>(receive);
-        }
-
-        public void Notify(Type type, object? notification)
-        {
-            if (Handlers.TryGetValue(type, out var handler))
-            {
-                handler.Receive(notification);
-            }
-        }
-    }
-}

+ 0 - 81
InABox.Core/Notifications/Notifier.cs

@@ -1,81 +0,0 @@
-using InABox.Core;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-
-namespace InABox.Core
-{
-    public interface IPollHandler
-    {
-        Type Type { get; }
-
-        /// <summary>
-        /// Polls for notifications, called on client connection.
-        /// </summary>
-        /// <returns>New notifications</returns>
-        IEnumerable<BaseObject> Poll(Guid session);
-    }
-    public class PollHandler<TNotification> : IPollHandler
-        where TNotification : BaseObject
-    {
-        public delegate IEnumerable<TNotification> PollEvent(Guid session);
-
-        public event PollEvent? OnPoll;
-
-        public Type Type => typeof(TNotification);
-
-        public PollHandler() { }
-
-        public PollHandler(PollEvent poll)
-        {
-            OnPoll += poll;
-        }
-
-        public IEnumerable<BaseObject> Poll(Guid session) => OnPoll?.Invoke(session) ?? Array.Empty<TNotification>();
-    }
-
-
-    public interface INotifier
-    {
-        void NotifyAll<TNotification>(TNotification notification) where TNotification : BaseObject;
-        void NotifySession<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject;
-        void NotifySession(Guid session, Type TNotification, BaseObject notification);
-        IEnumerable<Guid> GetUserSessions(Guid user);
-        IEnumerable<Guid> GetSessions(Platform platform);
-
-        public void Push<TNotification>(TNotification notification)
-            where TNotification : BaseObject
-        {
-            NotifyAll(notification);
-        }
-
-        public void Push(Guid session, Type TNotification, BaseObject notification)
-        {
-            NotifySession(session, TNotification, notification);
-        }
-
-        public void Push<TNotification>(Guid session, TNotification notification)
-            where TNotification : BaseObject
-        {
-            NotifySession(session, notification);
-        }
-        public void PushUser<TNotification>(Guid user, TNotification notification)
-            where TNotification : BaseObject
-        {
-            foreach (var session in GetUserSessions(user))
-            {
-                NotifySession(session, notification);
-            }
-        }
-        public void Push<TNotification>(Platform platform, TNotification notification)
-            where TNotification : BaseObject
-        {
-            foreach (var session in GetSessions(platform))
-            {
-                NotifySession(session, notification);
-            }
-        }
-
-    }
-}

+ 0 - 52
InABox.Core/Notifications/Notify.cs

@@ -1,52 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace InABox.Core
-{
-    public class Notify
-    {
-        private static List<IPollHandler> Handlers = new List<IPollHandler>();
-
-        private static List<INotifier> Notifiers { get; set; } = new List<INotifier>();
-
-        private Notify() { }
-
-        public static void AddNotifier(INotifier notifier) =>
-            Notifiers.Add(notifier);
-
-        public static void Push<TNotification>(TNotification notification) where TNotification : BaseObject => 
-            Notifiers.ForEach(x => x.Push(notification));
-
-        public static void Push<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject =>
-            Notifiers.ForEach(x => x.Push(session, notification));
-
-        public static void PushUser<TNotification>(Guid userID, TNotification notification) where TNotification : BaseObject =>
-            Notifiers.ForEach(x => x.PushUser(userID, notification));
-
-        public static void Push<TNotification>(Platform platform, TNotification notification) where TNotification : BaseObject => 
-            Notifiers.ForEach(x => x.Push(platform, notification));
-
-        public static void Poll(Guid session)
-        {
-            foreach (var handler in Handlers)
-            {
-                foreach (var notification in handler.Poll(session))
-                {
-                    Notifiers.ForEach(x => x.Push(session, handler.Type, notification));
-                }
-            }
-        }
-
-        public static void AddPollHandler<TNotification>(PollHandler<TNotification> handler)
-            where TNotification : BaseObject
-        {
-            Handlers.Add(handler);
-        }
-        public static void AddPollHandler<TNotification>(PollHandler<TNotification>.PollEvent poll)
-            where TNotification : BaseObject
-        {
-            Handlers.Add(new PollHandler<TNotification>(poll));
-        }
-    }
-}

+ 0 - 0
InABox.Core/Notifications/Platform.cs → InABox.Core/Pushes/Platform.cs


+ 42 - 0
InABox.Core/Pushes/PushHandler.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InABox.Core
+{
+    public interface IPushHandler
+    {
+        /// <summary>
+        /// Receives a new push from the server, called when a push is pushed.
+        /// </summary>
+        /// <param name="o">The push object</param>
+        void Receive(object? o);
+    }
+
+    public class PushHandler<TPush> : IPushHandler
+    {
+        public delegate void ReceiveEvent(TPush push);
+
+        public event ReceiveEvent? OnReceive;
+
+        public PushHandler() { }
+
+        public PushHandler(ReceiveEvent receive)
+        {
+            OnReceive += receive;
+        }
+
+        public void Receive(object? push) => Receive((TPush)push);
+
+        /// <summary>
+        /// Receives a new push message from the server, called when it is pushed.
+        /// </summary>
+        /// <param name="push">The push message received</param>
+        public void Receive(TPush push)
+        {
+            OnReceive?.Invoke(push);
+        }
+    }
+}

+ 55 - 0
InABox.Core/Pushes/PushManager.cs

@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core
+{
+    /// <summary>
+    /// Static class through which the server registers <see cref="IPusher"/>s and <see cref="IPollHandler"/>s, as well as actually pushing messages.
+    /// </summary>
+    public class PushManager
+    {
+        private static List<IPollHandler> Handlers = new List<IPollHandler>();
+
+        private static List<IPusher> Pushers { get; set; } = new List<IPusher>();
+
+        private PushManager() { }
+
+        public static void AddPusher(IPusher pusher) =>
+            Pushers.Add(pusher);
+
+        public static void Push<TPush>(TPush push) where TPush : BaseObject => 
+            Pushers.ForEach(x => x.Push(push));
+
+        public static void Push<TPush>(Guid session, TPush push) where TPush : BaseObject =>
+            Pushers.ForEach(x => x.Push(session, push));
+
+        public static void PushUser<TPush>(Guid userID, TPush push) where TPush : BaseObject =>
+            Pushers.ForEach(x => x.PushUser(userID, push));
+
+        public static void Push<TPush>(Platform platform, TPush push) where TPush : BaseObject => 
+            Pushers.ForEach(x => x.Push(platform, push));
+
+        public static void Poll(Guid session)
+        {
+            foreach (var handler in Handlers)
+            {
+                foreach (var push in handler.Poll(session))
+                {
+                    Pushers.ForEach(x => x.Push(session, handler.Type, push));
+                }
+            }
+        }
+
+        public static void AddPollHandler<TPush>(PollHandler<TPush> handler)
+            where TPush : BaseObject
+        {
+            Handlers.Add(handler);
+        }
+        public static void AddPollHandler<TPush>(PollHandler<TPush>.PollEvent poll)
+            where TPush : BaseObject
+        {
+            Handlers.Add(new PollHandler<TPush>(poll));
+        }
+    }
+}

+ 88 - 0
InABox.Core/Pushes/Pusher.cs

@@ -0,0 +1,88 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+
+namespace InABox.Core
+{
+    public interface IPollHandler
+    {
+        Type Type { get; }
+
+        /// <summary>
+        /// Polls for pushes, called on client connection.
+        /// </summary>
+        /// <returns>New pushes</returns>
+        IEnumerable<BaseObject> Poll(Guid session);
+    }
+    public class PollHandler<TPush> : IPollHandler
+        where TPush : BaseObject
+    {
+        public delegate IEnumerable<TPush> PollEvent(Guid session);
+
+        public event PollEvent? OnPoll;
+
+        public Type Type => typeof(TPush);
+
+        public PollHandler() { }
+
+        public PollHandler(PollEvent poll)
+        {
+            OnPoll += poll;
+        }
+
+        public IEnumerable<BaseObject> Poll(Guid session) => OnPoll?.Invoke(session) ?? Array.Empty<TPush>();
+    }
+
+    /// <summary>
+    /// Classes that implement this interface implement the manner by which the server actually gets messages pushed to the client.
+    /// The implementation will manage the transport layer.
+    /// </summary>
+    /// <remarks>
+    /// If one wishes to implement <see cref="IPusher"/>, it is likely one should also register it with <see cref="PushManager.AddPusher(IPusher)"/>;
+    /// this way, when the server wishes to push a message, it will go through this pusher (as well as any other registered ones).
+    /// </remarks>
+    public interface IPusher
+    {
+        void PushToAll<TPush>(TPush push) where TPush : BaseObject;
+        void PushToSession<TPush>(Guid session, TPush push) where TPush : BaseObject;
+        void PushToSession(Guid session, Type TPush, BaseObject push);
+        IEnumerable<Guid> GetUserSessions(Guid user);
+        IEnumerable<Guid> GetSessions(Platform platform);
+
+        public void Push<TPush>(TPush push)
+            where TPush : BaseObject
+        {
+            PushToAll(push);
+        }
+
+        public void Push(Guid session, Type TPush, BaseObject push)
+        {
+            PushToSession(session, TPush, push);
+        }
+
+        public void Push<TPush>(Guid session, TPush push)
+            where TPush : BaseObject
+        {
+            PushToSession(session, push);
+        }
+        public void PushUser<TPush>(Guid user, TPush push)
+            where TPush : BaseObject
+        {
+            foreach (var session in GetUserSessions(user))
+            {
+                PushToSession(session, push);
+            }
+        }
+        public void Push<TPush>(Platform platform, TPush push)
+            where TPush : BaseObject
+        {
+            foreach (var session in GetSessions(platform))
+            {
+                PushToSession(session, push);
+            }
+        }
+
+    }
+}

+ 31 - 0
InABox.Core/Pushes/Pushes.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core
+{
+    /// <summary>
+    /// Client-side push manager.
+    /// </summary>
+    public class PushHandlers
+    {
+        private Dictionary<Type, IPushHandler> Handlers = new Dictionary<Type, IPushHandler>();
+
+        public void AddHandler<TPush>(PushHandler<TPush> handler)
+        {
+            Handlers[typeof(TPush)] = handler;
+        }
+        public void AddHandler<TPush>(PushHandler<TPush>.ReceiveEvent receive)
+        {
+            Handlers[typeof(TPush)] = new PushHandler<TPush>(receive);
+        }
+
+        public void Push(Type type, object? push)
+        {
+            if (Handlers.TryGetValue(type, out var handler))
+            {
+                handler.Receive(push);
+            }
+        }
+    }
+}

+ 6 - 6
InABox.RPC.Shared/RpcNotification.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 namespace InABox.Rpc
 {
-    public class RpcNotification : ISerializeBinary
+    public class RpcPush : ISerializeBinary
     {
         public Type Type { get; set; }
 
@@ -25,13 +25,13 @@ namespace InABox.Rpc
             Object = reader.ReadObject<BaseObject>(Type);
         }
 
-        public static RpcNotification Create<TNotification>(TNotification notification)
-            where TNotification : BaseObject
+        public static RpcPush Create<TPush>(TPush push)
+            where TPush : BaseObject
         {
-            return new RpcNotification
+            return new RpcPush
             {
-                Type = typeof(TNotification),
-                Object = notification
+                Type = typeof(TPush),
+                Object = push
             };
         }
     }

+ 20 - 20
InABox.Server/IPC/IPCNotifier.cs

@@ -3,24 +3,24 @@ using InABox.Core;
 
 namespace InABox.IPC
 {
-    public class IPCNotifier : INotifier
+    public class IPCPusher : IPusher
     {
-        IPCNotifyState NotifyState { get; set; }
+        IPCPushState PushState { get; set; }
 
-        public IPCNotifier(IPCNotifyState notifyState)
+        public IPCPusher(IPCPushState pushState)
         {
-            NotifyState = notifyState;
-            NotifyState.OnPoll += NotifyState_OnPoll;
+            PushState = pushState;
+            PushState.OnPoll += PushState_OnPoll;
         }
 
-        private void NotifyState_OnPoll(IPCNotifyState.Session session)
+        private void PushState_OnPoll(IPCPushState.Session session)
         {
-            Notify.Poll(session.SessionID);
+            PushManager.Poll(session.SessionID);
         }
 
         public IEnumerable<Guid> GetSessions(Platform platform)
         {
-            return NotifyState.SessionMap.Where(x => x.Value.Platform == platform).Select(x => x.Key);
+            return PushState.SessionMap.Where(x => x.Value.Platform == platform).Select(x => x.Key);
         }
 
         public IEnumerable<Guid> GetUserSessions(Guid userID)
@@ -28,43 +28,43 @@ namespace InABox.IPC
             return CredentialsCache.GetUserSessions(userID);
         }
 
-        public void NotifyAll<TNotification>(TNotification notification) where TNotification : BaseObject
+        public void PushToAll<TPush>(TPush push) where TPush : BaseObject
         {
-            foreach(var session in NotifyState.SessionMap.Values)
+            foreach(var session in PushState.SessionMap.Values)
             {
-                session.Connection.WriteAsync(IPCMessage.Notification(notification)).ContinueWith(task =>
+                session.Connection.WriteAsync(IPCMessage.Push(push)).ContinueWith(task =>
                 {
                     if(task.Exception != null)
                     {
-                        Logger.Send(LogType.Error, "", $"Error in notification: {CoreUtils.FormatException(task.Exception)}");
+                        Logger.Send(LogType.Error, "", $"Error in push: {CoreUtils.FormatException(task.Exception)}");
                     }
                 });
             }
         }
 
-        public void NotifySession<TNotification>(Guid sessionID, TNotification notification) where TNotification : BaseObject
+        public void PushToSession<TPush>(Guid sessionID, TPush push) where TPush : BaseObject
         {
-            if(NotifyState.SessionMap.TryGetValue(sessionID, out var session))
+            if(PushState.SessionMap.TryGetValue(sessionID, out var session))
             {
-                session.Connection.WriteAsync(IPCMessage.Notification(notification)).ContinueWith(task =>
+                session.Connection.WriteAsync(IPCMessage.Push(push)).ContinueWith(task =>
                 {
                     if(task.Exception != null)
                     {
-                        Logger.Send(LogType.Error, "", $"Error in notification: {CoreUtils.FormatException(task.Exception)}");
+                        Logger.Send(LogType.Error, "", $"Error in push: {CoreUtils.FormatException(task.Exception)}");
                     }
                 });
             }
         }
 
-        public void NotifySession(Guid sessionID, Type TNotification, BaseObject notification)
+        public void PushToSession(Guid sessionID, Type TPush, BaseObject push)
         {
-            if(NotifyState.SessionMap.TryGetValue(sessionID, out var session))
+            if(PushState.SessionMap.TryGetValue(sessionID, out var session))
             {
-                session.Connection.WriteAsync(IPCMessage.Notification(TNotification, notification)).ContinueWith(task =>
+                session.Connection.WriteAsync(IPCMessage.Push(TPush, push)).ContinueWith(task =>
                 {
                     if(task.Exception != null)
                     {
-                        Logger.Send(LogType.Error, "", $"Error in notification: {CoreUtils.FormatException(task.Exception)}");
+                        Logger.Send(LogType.Error, "", $"Error in push: {CoreUtils.FormatException(task.Exception)}");
                     }
                 });
             }

+ 1 - 1
InABox.Server/IPC/IPCNotifyState.cs

@@ -4,7 +4,7 @@ using InABox.Core;
 
 namespace InABox.IPC
 {
-    public class IPCNotifyState
+    public class IPCPushState
     {
         public class Session
         {

+ 1 - 1
InABox.Server/IPC/IPCPollEvent.cs

@@ -1,4 +1,4 @@
 namespace InABox.IPC
 {
-    public delegate void IPCPollEvent(IPCNotifyState.Session session);
+    public delegate void IPCPollEvent(IPCPushState.Session session);
 }

+ 3 - 3
InABox.Server/IPC/IPCServer.cs

@@ -14,7 +14,7 @@ namespace InABox.IPC
     {
         PipeServer<IPCMessage> Server;
 
-        IPCNotifyState NotifyState = new();
+        IPCPushState PushState = new();
 
         public IPCServer(string name)
         {
@@ -242,8 +242,8 @@ namespace InABox.IPC
         {
             Logger.Send(LogType.Information, "", "Client Disconnected");
 
-            var sessionID = NotifyState.SessionMap.Where(x => x.Value.Connection == e.Connection).FirstOrDefault().Key;
-            NotifyState.SessionMap.TryRemove(sessionID, out var session);
+            var sessionID = PushState.SessionMap.Where(x => x.Value.Connection == e.Connection).FirstOrDefault().Key;
+            PushState.SessionMap.TryRemove(sessionID, out var session);
 
             e.Connection.DisposeAsync();
         }

+ 13 - 9
InABox.Server/RPC/Transports/RPCServerTransport.cs

@@ -3,7 +3,7 @@ using InABox.Core;
 namespace InABox.Rpc
 {
 
-    public abstract class RpcServerTransport<TConnection> : INotifier, IRpcServerTransport where TConnection : notnull
+    public abstract class RpcServerTransport<TConnection> : IPusher, IRpcServerTransport where TConnection : notnull
     {
         public abstract bool IsSecure();
         
@@ -133,18 +133,20 @@ namespace InABox.Rpc
         /// <param name="message">The message to send.</param>
         public abstract void Send(TConnection connection, RpcMessage message);
 
-        public void NotifyAll<TNotification>(TNotification notification) where TNotification : BaseObject
+        #region Notifier Stuff
+
+        public void PushToAll<TPush>(TPush push) where TPush : BaseObject
         {
-            var message = new RpcMessage(Guid.NewGuid(), "Notification", RpcNotification.Create(notification).WriteBinary(BinarySerializationSettings.Latest));
+            var message = new RpcMessage(Guid.NewGuid(), "Push", RpcPush.Create(push).WriteBinary(BinarySerializationSettings.Latest));
             foreach (var connection in _sessions.Keys)
             {
                 Send(connection, message);
             }
         }
 
-        public void NotifySession<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject
+        public void PushToSession<TPush>(Guid session, TPush push) where TPush : BaseObject
         {
-            var message = new RpcMessage(Guid.NewGuid(), "Notification", RpcNotification.Create(notification).WriteBinary(BinarySerializationSettings.Latest));
+            var message = new RpcMessage(Guid.NewGuid(), "Push", RpcPush.Create(push).WriteBinary(BinarySerializationSettings.Latest));
 
             var sessionConnection = _sessions.FirstOrDefault(x => x.Value.ID == session).Key;
             if(sessionConnection is not null)
@@ -153,12 +155,12 @@ namespace InABox.Rpc
             }
         }
 
-        public void NotifySession(Guid session, Type TNotification, BaseObject notification)
+        public void PushToSession(Guid session, Type TPush, BaseObject push)
         {
-            var message = new RpcMessage(Guid.NewGuid(), "Notification", new RpcNotification
+            var message = new RpcMessage(Guid.NewGuid(), "Push", new RpcPush
             {
-                Object = notification,
-                Type = TNotification
+                Object = push,
+                Type = TPush
             }.WriteBinary(BinarySerializationSettings.Latest));
 
             var sessionConnection = _sessions.FirstOrDefault(x => x.Value.ID == session).Key;
@@ -173,5 +175,7 @@ namespace InABox.Rpc
 
         public IEnumerable<Guid> GetSessions(Platform platform) =>
             _sessions.Values.Where(x => x.Platform == platform).Select(x => x.ID);
+
+        #endregion
     }
 }

+ 22 - 22
InABox.Server/Rest/RestListener.cs

@@ -125,7 +125,7 @@ namespace InABox.API
                             {
                                 "validate" => new ValueTask<IResponse?>(Validate(request, data).Build()),
                                 "check_2fa" => new ValueTask<IResponse?>(Check2FA(request, data).Build()),
-                                "notify" => new ValueTask<IResponse?>(GetNotify(request, data).Build()),
+                                "notify" or "push" => new ValueTask<IResponse?>(GetPush(request, data).Build()),
                                 _ => HandleDatabaseRequest(request, data),
                             };
                         }
@@ -184,14 +184,14 @@ namespace InABox.API
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        private IResponseBuilder GetNotify(IRequest request, RequestData data)
+        private IResponseBuilder GetPush(IRequest request, RequestData data)
         {
-            var requestObj = Deserialize<NotifyRequest>(request.Content, data.RequestFormat, data.BinarySerializationSettings, true);
+            var requestObj = Deserialize<PushRequest>(request.Content, data.RequestFormat, data.BinarySerializationSettings, true);
             if (!CredentialsCache.SessionExists(requestObj.Credentials.Session))
             {
                 return request.Respond().Status(ResponseStatus.NotFound);
             }
-            var response = new NotifyResponse
+            var response = new PushResponse
             {
                 Status = StatusCode.OK,
                 SocketPort = WebSocketPort
@@ -447,21 +447,21 @@ namespace InABox.API
         }
     }
 
-    class RestNotifier : INotifier
+    class RestPusher : IPusher
     {
         private WebSocketServer SocketServer;
 
         public int Port => SocketServer.Port;
 
-        public RestNotifier(int port)
+        public RestPusher(int port)
         {
             SocketServer = new WebSocketServer(port);
             SocketServer.Poll += SocketServer_Poll;
         }
 
-        private void SocketServer_Poll(NotifyState.Session session)
+        private void SocketServer_Poll(PushState.Session session)
         {
-            Notify.Poll(session.SessionID);
+            PushManager.Poll(session.SessionID);
         }
 
         public void Start()
@@ -474,19 +474,19 @@ namespace InABox.API
             SocketServer.Stop();
         }
 
-        public void NotifyAll<TNotification>(TNotification notification) where TNotification : BaseObject
+        public void PushToAll<TPush>(TPush push) where TPush : BaseObject
         {
-            SocketServer.Push(notification);
+            SocketServer.Push(push);
         }
 
-        public void NotifySession(Guid session, Type TNotification, BaseObject notification)
+        public void PushToSession(Guid session, Type TPush, BaseObject push)
         {
-            SocketServer.Push(session, TNotification, notification);
+            SocketServer.Push(session, TPush, push);
         }
 
-        public void NotifySession<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject
+        public void PushToSession<TPush>(Guid session, TPush push) where TPush : BaseObject
         {
-            SocketServer.Push(session, notification);
+            SocketServer.Push(session, push);
         }
 
         public IEnumerable<Guid> GetUserSessions(Guid userID)
@@ -504,20 +504,20 @@ namespace InABox.API
     {
         private static IServerHost? host;
         private static X509Certificate2? certificate;
-        private static RestNotifier? notifier;
+        private static RestPusher? pusher;
 
         public static X509Certificate2? Certificate { get => certificate; }
 
         public static void Start()
         {
             host?.Start();
-            notifier?.Start();
+            pusher?.Start();
         }
 
         public static void Stop()
         {
             host?.Stop();
-            notifier?.Stop();
+            pusher?.Stop();
         }
 
         public static void InitCertificate(ushort port, X509Certificate2 certificate)
@@ -545,8 +545,8 @@ namespace InABox.API
             host?.Stop();
             host = null;
 
-            notifier?.Stop();
-            notifier = null;
+            pusher?.Stop();
+            pusher = null;
 
             certificate = null;
         }
@@ -559,13 +559,13 @@ namespace InABox.API
         {
             if(webSocketPort != 0)
             {
-                notifier = new RestNotifier(webSocketPort);
-                Notify.AddNotifier(notifier);
+                pusher = new RestPusher(webSocketPort);
+                PushManager.AddPusher(pusher);
             }
 
             host = Host.Create();
 
-            host.Handler(new RestHandlerBuilder(notifier?.Port))
+            host.Handler(new RestHandlerBuilder(pusher?.Port))
                 .Defaults().Backlog(1024);
         }
     }

+ 2 - 2
inabox.client.ipc/IPCClientFactory.cs

@@ -26,11 +26,11 @@ namespace InABox.Client.IPC
 
         private static void Client_OnPush(IPCMessage request)
         {
-            if(request.Method == Method.Notification)
+            if(request.Method == Method.Push)
             {
                 if(request.Type is not null && CoreUtils.TryGetEntity(request.Type, out var entity))
                 {
-                    ClientFactory.Notifications.Notify(entity, request.GetRequest(entity));
+                    ClientFactory.PushHandlers.Push(entity, request.GetRequest(entity));
                 }
             }
         }

+ 7 - 7
inabox.client.rest/InABox.Client.Rest/RestClient.cs

@@ -138,17 +138,17 @@ namespace InABox.Clients
                 {
                     if(response.Session != Guid.Empty)
                     {
-                        var notifyRequest = new NotifyRequest();
-                        PrepareRequest(notifyRequest);
+                        var pushRequest = new PushRequest();
+                        PrepareRequest(pushRequest);
 
                         // Session is required so that the server can exclude any requests from bad actors
-                        notifyRequest.Credentials.Session = response.Session;
-                        var notifyResponse = SendRequest<NotifyRequest, NotifyResponse>(notifyRequest, "notify", SerializationFormat.Binary, SerializationFormat.Binary, false);
-                        if(notifyResponse != null && notifyResponse.Status.Equals(StatusCode.OK))
+                        pushRequest.Credentials.Session = response.Session;
+                        var pushResponse = SendRequest<PushRequest, PushResponse>(pushRequest, "push", SerializationFormat.Binary, SerializationFormat.Binary, false);
+                        if(pushResponse != null && pushResponse.Status.Equals(StatusCode.OK))
                         {
-                            if (notifyResponse.SocketPort.HasValue)
+                            if (pushResponse.SocketPort.HasValue)
                             {
-                                SocketClientCache.StartWebSocket(_server, notifyResponse.SocketPort.Value, response.Session);
+                                SocketClientCache.StartWebSocket(_server, pushResponse.SocketPort.Value, response.Session);
                             }
                         }
                     }

+ 5 - 5
inabox.client.websocket/WebSocketClient.cs

@@ -19,7 +19,7 @@ namespace InABox.Client.WebSocket
         {
             Session = session;
             Uri uri = new Uri("http://" + url);
-            Socket = new Socket($"ws://{uri.Host}:{port}/notify");
+            Socket = new Socket($"ws://{uri.Host}:{port}/push");
             Socket.OnOpen += Socket_OnOpen;
             Socket.OnError += Socket_OnError;
             Socket.OnClose += Socket_OnClose;
@@ -33,11 +33,11 @@ namespace InABox.Client.WebSocket
         private void Socket_OnMessage(object? sender, MessageEventArgs e)
         {
             var message = SocketMessage.ReadMessage(e.RawData);
-            if(message is NotifyMessage notify)
+            if(message is PushMessage pushMessage)
             {
-                var notifyType = CoreUtils.GetEntity(notify.EntityType);
-                var notification = Serialization.Deserialize(notifyType, notify.EntityData);
-                ClientFactory.Notifications.Notify(notifyType, notification);
+                var pushType = CoreUtils.GetEntity(pushMessage.EntityType);
+                var pushObject = Serialization.Deserialize(pushType, pushMessage.EntityData);
+                ClientFactory.PushHandlers.Push(pushType, pushObject);
             }
             else if(message is InitialMessage)
             {

+ 5 - 5
inabox.ipc.shared/IPCMessage.cs

@@ -30,7 +30,7 @@ namespace InABox.IPC
         Check2FA,
         Ping,
         Info,
-        Notification
+        Push
     }
 
     [Serializable]
@@ -185,11 +185,11 @@ namespace InABox.IPC
         {
             return CreateRequest(Guid.NewGuid(), Method.Info, null, request);
         }
-        public static IPCMessage Notification<TNotification>(TNotification notification) where TNotification : BaseObject
-            => Notification(typeof(TNotification), notification);
-        public static IPCMessage Notification(Type TNotification, BaseObject notification)
+        public static IPCMessage Push<TPush>(TPush push) where TPush : BaseObject
+            => Push(typeof(TPush), push);
+        public static IPCMessage Push(Type TPush, BaseObject push)
         {
-            return CreateRequest(Guid.NewGuid(), Method.Notification, TNotification.EntityName(), notification);
+            return CreateRequest(Guid.NewGuid(), Method.Push, TPush.EntityName(), push);
         }
     }
 }

+ 33 - 33
inabox.server.websocket/WebSocketServer.cs

@@ -10,7 +10,7 @@ using System.Text;
 using System.Threading.Tasks;
 using WebSocketSharp;
 using WebSocketSharp.Server;
-using static InABox.Server.WebSocket.NotifyState;
+using static InABox.Server.WebSocket.PushState;
 using InternalServer = WebSocketSharp.Server.WebSocketServer;
 using Logger = InABox.Core.Logger;
 
@@ -18,7 +18,7 @@ namespace InABox.Server.WebSocket
 {
     public delegate void PollEvent(Session session);
 
-    public class NotifyState
+    public class PushState
     {
         public class Session
         {
@@ -46,13 +46,13 @@ namespace InABox.Server.WebSocket
         }
     }
 
-    public class NotifyHandler : WebSocketBehavior
+    public class PushHandler : WebSocketBehavior
     {
-        private NotifyState NotifyState;
+        private PushState PushState;
 
-        public NotifyHandler(NotifyState state)
+        public PushHandler(PushState state)
         {
-            NotifyState = state;
+            PushState = state;
         }
 
         protected override void OnOpen()
@@ -64,8 +64,8 @@ namespace InABox.Server.WebSocket
         {
             Logger.Send(LogType.Information, "", $"WebSocket client disconnected");
 
-            var sessionID = NotifyState.SessionMap.Where(x => x.Value.ID == ID).FirstOrDefault().Key;
-            NotifyState.SessionMap.TryRemove(sessionID, out var session);
+            var sessionID = PushState.SessionMap.Where(x => x.Value.ID == ID).FirstOrDefault().Key;
+            PushState.SessionMap.TryRemove(sessionID, out var session);
         }
 
         protected override void OnError(WebSocketSharp.ErrorEventArgs e)
@@ -76,8 +76,8 @@ namespace InABox.Server.WebSocket
         private void DoInitial(InitialMessage initial)
         {
             var newSession = new Session(ID, initial.SessionID, initial.Platform);
-            NotifyState.SessionMap[initial.SessionID] = newSession;
-            NotifyState.Poll(newSession);
+            PushState.SessionMap[initial.SessionID] = newSession;
+            PushState.Poll(newSession);
         }
 
         protected override void OnMessage(MessageEventArgs e)
@@ -94,7 +94,7 @@ namespace InABox.Server.WebSocket
     public class WebSocketServer
     {
         private InternalServer Server;
-        private NotifyState NotifyState = new();
+        private PushState PushState = new();
 
         public event PollEvent? Poll;
 
@@ -103,70 +103,70 @@ namespace InABox.Server.WebSocket
         public WebSocketServer(int port)
         {
             Server = new InternalServer(IPAddress.Any, port);
-            Server.AddWebSocketService("/notify", NewNotify);
+            Server.AddWebSocketService("/push", NewPush);
 
-            NotifyState.OnPoll += NotifyState_Poll;
+            PushState.OnPoll += PushState_Poll;
         }
 
-        private void NotifyState_Poll(Session session)
+        private void PushState_Poll(Session session)
         {
             Poll?.Invoke(session);
         }
 
-        public NotifyHandler NewNotify()
+        public PushHandler NewPush()
         {
-            return new NotifyHandler(NotifyState);
+            return new PushHandler(PushState);
         }
 
         public IEnumerable<Guid> GetSessions(Platform platform)
         {
-            return NotifyState.SessionMap.Where(x => x.Value.Platform == platform).Select(x => x.Key);
+            return PushState.SessionMap.Where(x => x.Value.Platform == platform).Select(x => x.Key);
         }
 
         public void Push(Guid sessionID, SocketMessage message)
         {
-            if(NotifyState.SessionMap.TryGetValue(sessionID, out var session))
+            if(PushState.SessionMap.TryGetValue(sessionID, out var session))
             {
                 using(var stream = new MemoryStream())
                 {
                     message.Write(stream);
-                    Server.WebSocketServices["/notify"].Sessions.SendToAsync(stream, (int)stream.Length, session.ID, (succ) => { });
+                    Server.WebSocketServices["/push"].Sessions.SendToAsync(stream, (int)stream.Length, session.ID, (succ) => { });
                 }
             }
         }
 
         private void PushMessage(SocketMessage message)
         {
-            Server.WebSocketServices["/notify"].Sessions.Broadcast(message.WriteToBytes());
+            Server.WebSocketServices["/push"].Sessions.Broadcast(message.WriteToBytes());
         }
         private void PushMessage(SocketMessage message, string session)
         {
-            Server.WebSocketServices["/notify"].Sessions.SendTo(message.WriteToBytes(), session);
+            Server.WebSocketServices["/push"].Sessions.SendTo(message.WriteToBytes(), session);
         }
 
-        public void Push(Type TNotification, object notification)
+        public void Push(Type TPush, object push)
         {
-            PushMessage(NotifyMessage.Notify(TNotification, notification));
+            PushMessage(InABox.WebSocket.Shared.PushMessage.Push(TPush, push));
         }
-        public void Push<TNotification>(TNotification notification)
-            where TNotification : BaseObject
+        public void Push<TPush>(TPush push)
+            where TPush : BaseObject
         {
-            PushMessage(NotifyMessage.Notify(notification));
+            PushMessage(InABox.WebSocket.Shared.PushMessage.Push(push));
         }
 
-        public void Push(Guid sessionID, Type TNotification, object notification)
+        public void Push(Guid sessionID, Type TPush, object push)
         {
-            if(NotifyState.SessionMap.TryGetValue(sessionID, out var session))
+            if(PushState.SessionMap.TryGetValue(sessionID, out var session))
             {
-                PushMessage(NotifyMessage.Notify(TNotification, notification), session.ID);
+                PushMessage(InABox.WebSocket.Shared.PushMessage.Push(TPush, push), session.ID);
             }
         }
-        public void Push<TNotification>(Guid sessionID, TNotification notification)
-            where TNotification : BaseObject
+        public void Push<TPush>(Guid sessionID, TPush push)
+            where TPush : BaseObject
         {
-            if(NotifyState.SessionMap.TryGetValue(sessionID, out var session))
+            if(PushState.SessionMap.TryGetValue(sessionID, out var session))
             {
-                PushMessage(NotifyMessage.Notify(notification), session.ID);
+                PushMessage(InABox.WebSocket.Shared.PushMessage.Push(push), session.ID);
             }
         }
 

+ 3 - 3
inabox.websocket.shared/NotifyResponse.cs

@@ -8,12 +8,12 @@ using System.Threading.Tasks;
 
 namespace InABox.WebSocket.Shared
 {
-    public class NotifyRequest : Request, ISerializeBinary
+    public class PushRequest : Request, ISerializeBinary
     {
-        public override RequestMethod GetMethod() => RequestMethod.Notify;
+        public override RequestMethod GetMethod() => RequestMethod.Push;
     }
 
-    public class NotifyResponse : Response, ISerializeBinary
+    public class PushResponse : Response, ISerializeBinary
     {
         public int? SocketPort { get; set; }
 

+ 13 - 13
inabox.websocket.shared/SocketMessage.cs

@@ -88,7 +88,7 @@ namespace InABox.WebSocket.Shared
         public enum MessageType
         {
             Initial = 0x00,
-            Notify = 0x01
+            Push = 0x01
         }
 
         public abstract MessageType Type { get; }
@@ -121,8 +121,8 @@ namespace InABox.WebSocket.Shared
                 {
                     case MessageType.Initial:
                         return InitialMessage.ReadMessage(byteReader);
-                    case MessageType.Notify:
-                        return NotifyMessage.ReadMessage(byteReader);
+                    case MessageType.Push:
+                        return PushMessage.ReadMessage(byteReader);
                 }
             }
             catch (Exception)
@@ -161,15 +161,15 @@ namespace InABox.WebSocket.Shared
         }
     }
 
-    public class NotifyMessage : SocketMessage
+    public class PushMessage : SocketMessage
     {
-        public override MessageType Type => MessageType.Notify;
+        public override MessageType Type => MessageType.Push;
 
         public string EntityType;
 
         public string EntityData;
 
-        private NotifyMessage(string entityType, string entityData)
+        private PushMessage(string entityType, string entityData)
         {
             EntityType = entityType;
             EntityData = entityData;
@@ -181,21 +181,21 @@ namespace InABox.WebSocket.Shared
             writer.WriteUTF8String(EntityData);
         }
 
-        public static NotifyMessage ReadMessage(ByteReader reader)
+        public static PushMessage ReadMessage(ByteReader reader)
         {
             var type = reader.ReadUTF8String();
             var data = reader.ReadUTF8String();
-            return new NotifyMessage(type, data);
+            return new PushMessage(type, data);
         }
 
-        public static NotifyMessage Notify<TNotification>(TNotification notification)
-            where TNotification : BaseObject
+        public static PushMessage Push<TPush>(TPush push)
+            where TPush : BaseObject
         {
-            return new NotifyMessage(typeof(TNotification).EntityName(), Serialization.Serialize(notification));
+            return new PushMessage(typeof(TPush).EntityName(), Serialization.Serialize(push));
         }
-        public static NotifyMessage Notify(Type TNotification, object notification)
+        public static PushMessage Push(Type TPush, object push)
         {
-            return new NotifyMessage(TNotification.EntityName(), Serialization.Serialize(notification));
+            return new PushMessage(TPush.EntityName(), Serialization.Serialize(push));
         }
     }
 }