123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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);
- }
- }
- }
|