using System; using System.Collections.Generic; using System.Linq; using System.Net.Mail; using System.Text; using System.Threading.Tasks; namespace Firebird2D.EventPipelines { public class Pipeline : I_Pipeline where T : EventArgs { public object PipelineMaster { get; } private event EventHandler? OnEvent; public Pipeline(object pipelineMaster) { PipelineMaster = pipelineMaster; } public bool IsEventEmpty { get { return OnEvent != null; } } public void Subscribe(Delegate handler) { OnEvent += (EventHandler)handler; } public void Unsubscribe(Delegate handler) { OnEvent -= (EventHandler)handler; } public void SendEvent(object sender, T args) { if (sender == null || args == null) throw new ArgumentNullException(nameof(sender)); if (args is not T) throw new ArgumentException($"Invalid EventArgs type. Expected {typeof(T)}"); if (sender.Equals(PipelineMaster)) throw new InvalidDataException("Only the pipeline master is allowed to send events through this pipeline."); OnEvent?.Invoke(sender, args); } } }