Преглед изворни кода

Changing things to BaseObjecty for notification handler

Kenric Nugteren пре 2 година
родитељ
комит
b90d5c0c9b

+ 8 - 2
InABox.Core/Notifications/Notifier.cs

@@ -39,22 +39,25 @@ namespace InABox.Core
     {
         private List<IPollHandler> Handlers = new List<IPollHandler>();
 
-        protected abstract void NotifyAll<TNotification>(TNotification notification);
-        protected abstract void NotifySession<TNotification>(Guid session, TNotification notification);
+        protected abstract void NotifyAll<TNotification>(TNotification notification) where TNotification : BaseObject;
+        protected abstract void NotifySession<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject;
         protected abstract void NotifySession(Guid session, Type TNotification, object? notification);
         protected abstract IEnumerable<Guid> GetUserSessions(Guid user);
         protected abstract IEnumerable<Guid> GetSessions(Platform platform);
 
         public void Push<TNotification>(TNotification notification)
+            where TNotification : BaseObject
         {
             NotifyAll(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))
             {
@@ -62,6 +65,7 @@ namespace InABox.Core
             }
         }
         public void Push<TNotification>(Platform platform, TNotification notification)
+            where TNotification : BaseObject
         {
             foreach (var session in GetSessions(platform))
             {
@@ -81,10 +85,12 @@ namespace InABox.Core
         }
 
         public void AddPollHandler<TNotification>(PollHandler<TNotification> handler)
+            where TNotification : BaseObject
         {
             Handlers.Add(handler);
         }
         public void AddPollHandler<TNotification>(PollHandler<TNotification>.PollEvent poll)
+            where TNotification : BaseObject
         {
             Handlers.Add(new PollHandler<TNotification>(poll));
         }

+ 4 - 4
InABox.Core/Notifications/Notify.cs

@@ -10,16 +10,16 @@ namespace InABox.Core
 
         private Notify() { }
 
-        public static void Push<TNotification>(TNotification notification) => 
+        public static void Push<TNotification>(TNotification notification) where TNotification : BaseObject => 
             Notifier?.Push(notification);
 
-        public static void Push<TNotification>(Guid session, TNotification notification) => 
+        public static void Push<TNotification>(Guid session, TNotification notification) where TNotification : BaseObject => 
             Notifier?.Push(session, notification);
 
-        public static void PushUser<TNotification>(Guid userID, TNotification notification) => 
+        public static void PushUser<TNotification>(Guid userID, TNotification notification) where TNotification : BaseObject => 
             Notifier?.PushUser(userID, notification);
 
-        public static void Push<TNotification>(Platform platform, TNotification notification) => 
+        public static void Push<TNotification>(Platform platform, TNotification notification) where TNotification : BaseObject => 
             Notifier?.Push(platform, notification);
     }
 }

+ 2 - 0
inabox.server.websocket/WebSocketServer.cs

@@ -149,6 +149,7 @@ namespace InABox.Server.WebSocket
             PushMessage(NotifyMessage.Notify(TNotification, notification));
         }
         public void Push<TNotification>(TNotification notification)
+            where TNotification : BaseObject
         {
             PushMessage(NotifyMessage.Notify(notification));
         }
@@ -161,6 +162,7 @@ namespace InABox.Server.WebSocket
             }
         }
         public void Push<TNotification>(Guid sessionID, TNotification notification)
+            where TNotification : BaseObject
         {
             if(NotifyState.SessionMap.TryGetValue(sessionID, out var session))
             {

+ 1 - 0
inabox.websocket.shared/SocketMessage.cs

@@ -189,6 +189,7 @@ namespace InABox.WebSocket.Shared
         }
 
         public static NotifyMessage Notify<TNotification>(TNotification notification)
+            where TNotification : BaseObject
         {
             return new NotifyMessage(typeof(TNotification).EntityName(), Serialization.Serialize(notification));
         }