12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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<Notifier> Notifiers { get; set; } = new List<Notifier>();
- private Notify() { }
- public static void AddNotifier(Notifier 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));
- }
- }
- }
|