AyCode.Core/AyCode.Services.Server/SignalRs
Loretta 32018e906a Refactor SignalR: separate metadata and payload transport
Major protocol update: OnReceiveMessage now takes metadata (SignalReceiveParams) and payload (byte[]) as separate hub arguments, not a single envelope. Metadata is AcBinary-serialized; payload uses protocol fast-path. Updated all client/server code, interfaces, and docs. Added ISignalParams and SignalReceiveParams types. Improved AcBinaryHubProtocol diagnostics and made byte[] fast-path more robust. This enables clearer, more debuggable, and future-proof SignalR binary messaging.
2026-04-05 09:30:54 +02:00
..
AcLoggerSignalRHub.cs
AcSessionService.cs
AcSignalRDataSource.cs Refactor serializer options, string fast paths & analysis 2026-01-25 16:40:40 +01:00
AcSignalRSendToClientService.cs Refactor SignalR: separate metadata and payload transport 2026-04-05 09:30:54 +02:00
AcWebSignalRHubBase.cs Refactor SignalR: separate metadata and payload transport 2026-04-05 09:30:54 +02:00
ExtensionMethods.cs
IAcSessionItem.cs
IAcSignalRHubItemServer.cs
README.md Update README links to use code-style paths for docs 2026-03-30 08:01:05 +02:00
TrackingItemHelpers.cs

README.md

SignalRs

Server-side SignalR hub infrastructure: hub base class, session management, data source with change tracking, and client broadcast service.

Architecture: For full dispatch flow, tag system, and tech debt documentation see AyCode.Services/docs/SIGNALR.md.

Key Files

Hub

  • AcWebSignalRHubBase.cs — Abstract hub extending Hub<IAcSignalRHubItemServer>. Manages connection lifecycle, message dispatch via DynamicMethodRegistry, binary/JSON parameter deserialization. Response methods: ResponseToCaller(), SendMessageToOthers(), SendMessageToUserIdInternal().
  • IAcSignalRHubItemServer.cs — Server hub interfaces: IAcSignalRHubItemServer, IAcSignalRHubServer.
  • AcLoggerSignalRHub.cs — Specialized hub for receiving log items via SignalR (AddLogItem()).

Session & Broadcast

  • AcSessionService.cs — Generic session manager with ConcurrentDictionary<TSessionItemId, TSessionItem>.
  • IAcSessionItem.cs — Session item interface with SessionId property.
  • AcSignalRSendToClientService.cs — Abstract broadcast service: SendMessageToClient(), SendMessageToAllClients(), SendMessageToConnection(), SendMessageToUser().

Data Source

Full specification: AyCode.Services.Server/docs/SIGNALR_DATASOURCE.md

  • AcSignalRDataSource.cs — Generic real-time collection (AcSignalRDataSource<TDataItem, TId, TIList>) implementing IList<T> with full CRUD and change tracking.
    • Change tracking: TrackingItem<T, TId> wraps each modified item with TrackingState + OriginalValue for rollback. ChangeTracking<T, TId> manages the tracking list.
    • Loading: LoadDataSource() (sync), LoadDataSourceAsync() (async callback), LoadItem(id) (single). Binary path uses BinaryToMerge() for AcObservableCollection (batch UI update via BeginUpdate/EndUpdate).
    • Saving: SaveChanges() iterates tracked items, posts each via CRUD tag, rollbacks on failure. SaveItem() for individual saves.
    • Sync state: IsSyncing (Interlocked counter) + OnSyncingStateChanged event for UI loading indicators.
    • Locking: object _syncRoot (sync ops) + SemaphoreSlim _asyncLock (async ops). GetEnumerator() returns safe copy.
    • Working reference list: SetWorkingReferenceList() allows external list to become inner storage (zero-copy).
    • Context: ContextIds (object[]) + FilterText (string) sent with GetAll requests for server-side filtering.

Utilities

  • ExtensionMethods.csInvokeMethod() — invokes methods and unwraps Task/Task<T>/ValueTask results.
  • TrackingItemHelpers.cs — Deep clone helpers: JsonClone<T>(), ReflectionClone<T>().