Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pushing data to the signalr clients.
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
You can’t perform that action at this time.