help
Root Question Message
public class FluxApiService
{
private HueApiService _hueApiService;
private HttpListener _listener;
private string _url = "http://localhost:8000/";
public FluxApiService(HueApiService hueApiService)
{
_listener = new HttpListener();
_listener.Prefixes.Add(_url);
_hueApiService = hueApiService;
}
public void Start()
{
Task.Run(async () => { await HandleIncomingConnections(); });
}
private async Task HandleIncomingConnections()
{
_listener.Start();
while (true)
{
try
{
HttpListenerContext ctx = await _listener.GetContextAsync();
HttpListenerRequest req = ctx.Request;
if (req.Url == null) continue;
var colorTemp = HttpUtility.ParseQueryString(req.Url.Query).Get("ct");
var brightness = HttpUtility.ParseQueryString(req.Url.Query).Get("bri");
if (colorTemp == null || brightness == null) continue;
await _hueApiService.UpdateScenes(int.Parse(colorTemp), Math.Clamp(float.Parse(brightness) * 100f, 0f, 100f));
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
_listener.Stop();
break;
}
}
}
}