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 FeedHub : Hub | |
{ | |
private readonly IMachineState machineState; | |
private readonly ISampleWriter sampleWriter; | |
public FeedHub(IMachineState machineState, ISampleWriter sampleWriter) | |
{ | |
this.machineState = machineState; | |
this.sampleWriter = sampleWriter; | |
} |
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 void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
// | |
// Omitted standard content for brevity... | |
// | |
app.UseSignalR(cfg => cfg.MapHub<FeedHub>("/feed")); | |
} |
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 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
@page | |
<html> | |
<head> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="lblSpeed text lbl">Speed:</div> | |
<div class="valSpeed text" id="currentSpeed"><!-- speed goes here --></div> | |
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
"use strict"; | |
// Define my connection (note the /feed address to specify the hub) | |
var connection = new signalR.HubConnectionBuilder().withUrl("/feed").build(); | |
// Get the elements I need | |
var speedValue = document.getElementById("currentSpeed"); | |
var countValue = document.getElementById("currentCount"); | |
var resetButton = document.getElementById("reset"); |
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
window.onload = function () { | |
var ctx = document.getElementById('chartCanvas').getContext('2d'); | |
window.myChart = new Chart(ctx, { | |
type: 'line', | |
data: { | |
datasets: [{ | |
label: 'Speed', | |
data: [] | |
}] |
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
connection.on("newData", function (time, speed, count) { | |
// This subtract causes the data to be placed | |
// in the centre of the chart as it arrives, | |
// which I personally think looks better... | |
var dateValue = moment(time).subtract(5, 'seconds'); | |
speedValue.innerText = speed; | |
countValue.innerText = count; |
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
async static Task Main(string[] args) | |
{ | |
var httpClient = new HttpClient(); | |
httpClient.BaseAddress = new Uri("https://myserver"); | |
using (var fileSource = new StreamReader(File.OpenRead(@"C:\Data\Sources\myfile.csv"))) | |
{ | |
await StreamData(fileSource, httpClient, "/api/send"); | |
} |
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
private static async Task StreamDataInParallel(StreamReader fileSource, HttpClient httpClient, string path, int maxParallel) | |
{ | |
var block = new ActionBlock<string>( | |
async json => | |
{ | |
await httpClient.PostAsync(path, new StringContent(json, Encoding.UTF8, "application/json")); | |
}, new ExecutionDataflowBlockOptions | |
{ | |
// Tells the action block how many we want to run at once. | |
MaxDegreeOfParallelism = maxParallel, |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
autoReload="true" | |
internalLogLevel="Info" | |
internalLogFile="c:\temp\internal-nlog.txt"> | |
<!-- enable asp.net core layout renderers --> | |
<extensions> | |
<add assembly="NLog.Web.AspNetCore"/> |