Load Data in Serial
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"); | |
} | |
} | |
private static async Task StreamData(StreamReader fileSource, HttpClient httpClient, string path) | |
{ | |
string line; | |
// Read from the file until it's empty | |
while ((line = await fileSource.ReadLineAsync()) != null) | |
{ | |
// Convert a line of data into JSON compatible with the API | |
var jsonMsg = GetDataJson(line); | |
// Send it to the server | |
await httpClient.PostAsync(path, new StringContent(jsonMsg, Encoding.UTF8, "application/json")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment