Improve uploader client connection and diagnostics
This commit is contained in:
@@ -12,10 +12,20 @@ namespace PhotoboothUploader.Services;
|
||||
|
||||
public sealed class UploadService
|
||||
{
|
||||
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(20);
|
||||
private readonly Channel<string> _queue = Channel.CreateUnbounded<string>();
|
||||
private readonly ConcurrentDictionary<string, byte> _pending = new(StringComparer.OrdinalIgnoreCase);
|
||||
private string _userAgent = "FotospielPhotoboothUploader";
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
public void Configure(string userAgent)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(userAgent))
|
||||
{
|
||||
_userAgent = userAgent;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start(
|
||||
PhotoboothSettings settings,
|
||||
Action<string> onQueued,
|
||||
@@ -61,6 +71,9 @@ public sealed class UploadService
|
||||
}
|
||||
|
||||
using var client = new HttpClient();
|
||||
client.Timeout = DefaultTimeout;
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
while (await _queue.Reader.WaitToReadAsync(token))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user