Add uploader advanced settings and live status
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
@@ -17,6 +18,7 @@ public sealed class UploadService
|
||||
private readonly ConcurrentDictionary<string, byte> _pending = new(StringComparer.OrdinalIgnoreCase);
|
||||
private string _userAgent = "FotospielPhotoboothUploader";
|
||||
private CancellationTokenSource? _cts;
|
||||
private readonly List<Task> _workers = new();
|
||||
|
||||
public void Configure(string userAgent)
|
||||
{
|
||||
@@ -36,7 +38,11 @@ public sealed class UploadService
|
||||
Stop();
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
_ = Task.Run(() => WorkerAsync(settings, onQueued, onUploading, onSuccess, onFailure, _cts.Token));
|
||||
var workerCount = GetWorkerCount(settings);
|
||||
for (var i = 0; i < workerCount; i++)
|
||||
{
|
||||
_workers.Add(Task.Run(() => WorkerAsync(settings, onQueued, onUploading, onSuccess, onFailure, _cts.Token)));
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -44,6 +50,7 @@ public sealed class UploadService
|
||||
_cts?.Cancel();
|
||||
_cts = null;
|
||||
_pending.Clear();
|
||||
_workers.Clear();
|
||||
}
|
||||
|
||||
public void Enqueue(string path, Action<string> onQueued)
|
||||
@@ -171,4 +178,15 @@ public sealed class UploadService
|
||||
_ => "image/jpeg",
|
||||
};
|
||||
}
|
||||
|
||||
private static int GetWorkerCount(PhotoboothSettings settings)
|
||||
{
|
||||
var count = settings.MaxConcurrentUploads;
|
||||
if (count < 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return count > 5 ? 5 : count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user