Added Event Pipeline System

This commit is contained in:
Mueller Wayan
2025-04-18 21:54:07 +02:00
parent b4d5afc4ba
commit 08f66af16e
52 changed files with 1368 additions and 197 deletions
+44
View File
@@ -0,0 +1,44 @@
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 <T> : I_Pipeline where T : EventArgs
{
public object PipelineMaster { get; }
private event EventHandler<T>? OnEvent;
public Pipeline(object pipelineMaster)
{
PipelineMaster = pipelineMaster;
}
public bool IsEventEmpty { get { return OnEvent != null; } }
public void Subscribe(Delegate handler)
{
OnEvent += (EventHandler<T>)handler;
}
public void Unsubscribe(Delegate handler)
{
OnEvent -= (EventHandler<T>)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);
}
}
}