Files
DP44/docs/ai/DataPRO/DataPRO.Core/EventManager.md
2026-04-17 14:55:32 -04:00

3.3 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/DataPRO.Core/EventManager/EventManager.cs
2026-04-17T16:11:20.602481+00:00 zai-org/GLM-5-FP8 1 bb36e013f0f39c56

EventManager

Purpose

This module implements a type-safe, loosely-coupled publish/subscribe event system. It allows components to communicate without direct references to each other, supporting filtered subscriptions and diagnostic monitoring of event flow. This decouples publishers from subscribers and centralizes event routing.

Public Interface

EventManager (static class)

  • static void Publish<T>(T eventData) where T : class — Publishes an event to all subscribers of type T. If no subscribers exist, returns immediately. Each subscriber's filter (if present) is evaluated before invoking the callback.
  • static void Subscribe<T>(SubscriberCallbackDelegate<T> listener) where T : class — Subscribes to events of type T without a filter.
  • static void Subscribe<T>(SubscriberCallbackDelegate<T> listener, Predicate<T> eventFilter) where T : class — Subscribes to events of type T with a filter predicate. The callback is only invoked when the filter returns true.
  • static void UnSubscribe<T>(SubscriberCallbackDelegate<T> listener) where T : class — Removes all subscriptions matching the given listener delegate.
  • static void Clear() — Removes all subscribers from all event types.
  • static void SubscribeToDiagnosticEvents(DiagnosticCallbackDelegate listener) — Registers a callback to receive diagnostic events about the event system itself.
  • static void UnSubscribeToDiagnosticEvents(DiagnosticCallbackDelegate listener) — Removes a diagnostic listener.
  • static void ClearDiagnosticEvents() — Removes all diagnostic listeners.

SubscriberCallbackDelegate<in T> (delegate)

  • void SubscriberCallbackDelegate<in T>(T item) where T : class — The signature for event callbacks.

DiagnosticCallbackDelegate (delegate)

  • void DiagnosticCallbackDelegate(EventDiagnosticType eventType, Type t, object eventData, string listener) — The signature for diagnostic callbacks.

EventDiagnosticType (enum)

  • Values: AddListener = 0, AddListenerDiagnostic = 1, PublishEvent = 2, RemoveListenerDiagnostic = 3, RemoveListener = 4

Invariants

  • SubscriberList and DiagnosticList are never null (initialized inline).
  • Publish<T> silently does nothing if no subscribers exist for type T.
  • Subscribers are stored in insertion order; callbacks are invoked in that order during Publish.
  • UnSubscribe<T> removes all matching entries (not just the first).
  • EventMetaData<T> is internal and always contains a non-null Callback after construction.

Dependencies

  • Depends on: System, System.Collections.Generic, System.Reflection.
  • Depended on by: Unknown from source alone—likely used throughout the application for cross-component communication.

Gotchas

  • Subscribers hold references to callbacks. If a subscriber fails to call UnSubscribe, the callback (and potentially its capturing object) will not be garbage collected, causing memory leaks.
  • Publish iterates over listeners directly; if a callback modifies the subscriber list (e.g., by calling Subscribe or UnSubscribe), behavior is undefined (likely an exception or skipped