using System; using System.Collections.Generic; using System.Text; namespace InABox.Core { public class Notify { private static List Handlers = new List(); private static List Notifiers { get; set; } = new List(); private Notify() { } public static void AddNotifier(Notifier notifier) => Notifiers.Add(notifier); public static void Push(TNotification notification) where TNotification : BaseObject => Notifiers.ForEach(x => x.Push(notification)); public static void Push(Guid session, TNotification notification) where TNotification : BaseObject => Notifiers.ForEach(x => x.Push(session, notification)); public static void PushUser(Guid userID, TNotification notification) where TNotification : BaseObject => Notifiers.ForEach(x => x.PushUser(userID, notification)); public static void Push(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(PollHandler handler) where TNotification : BaseObject { Handlers.Add(handler); } public static void AddPollHandler(PollHandler.PollEvent poll) where TNotification : BaseObject { Handlers.Add(new PollHandler(poll)); } } }