Skip to content

Add RealTimeChartsWithSignalRAndAngular: migrate the SignalR + Angular real-time charts sample - #2139

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/signalr-trio-realtime-charts
Open

Add RealTimeChartsWithSignalRAndAngular: migrate the SignalR + Angular real-time charts sample#2139
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/signalr-trio-realtime-charts

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Migrates the sample behind three SignalR articles out of the legacy per-article repository CodeMazeBlog/realtime-charts-signalr-angular and into CodeMazeGuides, as one folder under aspnetcore-features, beside the existing HowToCallSignalRAspDotNet.

The legacy repository served three articles from three branches:

  • /netcore-signalr-angular-realtime-charts (master)
  • /how-to-send-client-specific-messages-using-signalr (signalR-client-specific-messages)
  • /signalr-automatic-reconnect-option (signalR-automatic-reconnect)

CodeMazeGuides has one main, so the three branches collapse into one tree.

What is in here

  • net10.0 retarget of the server. Angular stays at 13.2 deliberately — CodeMazeGuides already hosts Angular front ends at 12.2, 13.1 and 14.0, and an Angular 13 to 22 upgrade is separate work with its own budget.
  • ChartHub now carries every method the three articles teach. BroadcastChartData(List<ChartModel>) keeps its form; the client-specific version is renamed BroadcastChartDataToClient(List<ChartModel>, string). The two cannot coexist under one name: SignalR throws NotSupportedException: Duplicate definitions of 'BroadcastChartData'. Overloading is not supported. at MapHub time.
  • signalr.service.ts is a three-way hand merge — it is the one file all three branches modify.
  • A defect the merge creates, fixed here: the client-specific branch stores a connectionId; the reconnect branch adds withAutomaticReconnect(). Neither branch has both, so neither was wrong. Together, every reconnect invalidates the stored id silently. onreconnected now takes the id it is already handed and assigns it.
  • onreconnecting and onclose handlers added.
  • TimerManager drops an AutoResetEvent that was constructed, passed to the timer and never read, and null-checks its two fields (two CS8602 on net10.0).
  • broadcastedData spelling, ChartModel.data: number[], and AppComponent implements OnInit.
  • A Tests project (xunit + Moq, matching HowToCallSignalRAspDotNet), seven tests over the hub methods.

dotnet build and dotnet test: 0 warnings, 0 errors, 7/7 passing on net10.0. The merged hub maps and the host starts clean.

…-charts-signalr-angular

Consolidates the three branches of CodeMazeBlog/realtime-charts-signalr-angular
(master, signalR-client-specific-messages, signalR-automatic-reconnect) into one
sample under aspnetcore-features, beside HowToCallSignalRAspDotNet.

- Retarget the server to net10.0.
- ChartHub carries every method the three articles teach. BroadcastChartData
  keeps its single-argument form and the client-specific overload is renamed to
  BroadcastChartDataToClient, because SignalR does not support hub method
  overloads and throws at MapHub time.
- signalr.service.ts is a three-way merge of the three branches: the stored
  connectionId and the client-specific invoke, plus withAutomaticReconnect,
  logging and the reconnect handlers.
- onreconnected now refreshes the stored connectionId from its own argument.
  A reconnect is a new connection, so the previously stored id was stale.
- Add onreconnecting and onclose handlers.
- TimerManager drops the unused AutoResetEvent and null-checks its fields.
- Fix broadcastedData, ChartModel.data: number[] and AppComponent implements OnInit.
- Add a Tests project: xunit and Moq, seven tests over the hub methods.

Angular stays at 13.2; upgrading it is separate work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant