-
Notifications
You must be signed in to change notification settings - Fork 1
/
StreamController.cs
44 lines (40 loc) · 1.79 KB
/
StreamController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using H.Necessaire;
using H.Playground.Streaming.Core;
using Microsoft.AspNetCore.Mvc;
namespace H.Playground.Streaming.API.HTTP.NetCoreWebApi.Controllers
{
[ApiController]
[Route("[controller]")]
public class StreamController : ControllerBase
{
StreamProvider streamProvider;
public StreamController()
{
streamProvider = new StreamProvider();
}
[HttpGet]
[Route(nameof(Timestamp))]
public async Task Timestamp([FromQuery] string? t)
{
Response.ContentType = "text/plain; charset=utf-8";
double? desiredDurationInSeconds = t?.ParseToDoubleOrFallbackTo(null);
await streamProvider.StreamTimestampTo(Response.Body, desiredDuration: desiredDurationInSeconds == null ? null : TimeSpan.FromSeconds(desiredDurationInSeconds.Value));
}
[HttpGet]
[Route(nameof(DataEntries))]
public async Task DataEntries([FromQuery] string? t)
{
Response.ContentType = "text/plain; charset=utf-8; x-subtype=json";
double? desiredDurationInSeconds = t?.ParseToDoubleOrFallbackTo(null);
await streamProvider.StreamDataEntriesTo(Response.Body, desiredDuration: desiredDurationInSeconds == null ? null : TimeSpan.FromSeconds(desiredDurationInSeconds.Value));
}
[HttpGet]
[Route(nameof(Numbers))]
public async Task Numbers([FromQuery] string? t)
{
Response.ContentType = "text/plain; charset=utf-8; x-subtype=json";
double? desiredDurationInSeconds = t?.ParseToDoubleOrFallbackTo(null);
await streamProvider.StreamNumbersTo(Response.Body, desiredDuration: desiredDurationInSeconds == null ? null : TimeSpan.FromSeconds(desiredDurationInSeconds.Value));
}
}
}