Created
June 8, 2019 12:31
-
-
Save alistairjevans/67ddd2cd4d59378bf3e4205fcdc9d574 to your computer and use it in GitHub Desktop.
Pushing data to the signalr clients.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataController : Controller | |
{ | |
private readonly IMachineState machineState; | |
private readonly ISampleWriter sampleWriter; | |
private readonly IHubContext<FeedHub> feedHub; | |
public DataController(IMachineState machineState, ISampleWriter sampleWriter, IHubContext<FeedHub> feedHub) | |
{ | |
this.machineState = machineState; | |
this.sampleWriter = sampleWriter; | |
this.feedHub = feedHub; | |
} | |
[HttpPost] | |
public async Task<ActionResult> ProvideReading(uint milliseconds, double speed, int count) | |
{ | |
// Update our machine state. | |
machineState.UpdateMachineState(milliseconds, speed, count); | |
// Write the sample to file (our sample writer) and update all clients | |
// Wait for them both to finish. | |
await Task.WhenAll( | |
sampleWriter.ProvideSample(machineState.LastSample, machineState.Speed, machineState.Count), | |
feedHub.Clients.All.SendAsync("newData", | |
machineState.LastSample.ToString("o"), | |
machineState.Speed, | |
machineState.Count) | |
); | |
return StatusCode(200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment