2025-07-04 00:04:51 +03:00
|
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
|
/* Copyright © 2024-2025 Gregory Lirent */
|
2025-07-03 20:01:19 +03:00
|
|
|
|
|
2025-07-03 15:22:40 +03:00
|
|
|
|
namespace WebmrAPI.Services.Scanners
|
|
|
|
|
{
|
|
|
|
|
public class ScanQueue : IScannable
|
|
|
|
|
{
|
|
|
|
|
private ScanTarget _target = 0;
|
|
|
|
|
public ScanTarget Target { get => _target; }
|
|
|
|
|
|
|
|
|
|
private Queue<IScannable> _queue = new();
|
|
|
|
|
|
|
|
|
|
public ScanQueue Add(IScannable item)
|
|
|
|
|
{
|
|
|
|
|
_queue.Enqueue(item);
|
|
|
|
|
_target |= item.Target;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 20:01:19 +03:00
|
|
|
|
public async Task ScanAsync()
|
2025-07-03 15:22:40 +03:00
|
|
|
|
{
|
2025-07-03 20:01:19 +03:00
|
|
|
|
var tasks = new List<Task>();
|
2025-07-03 15:22:40 +03:00
|
|
|
|
while (_queue.Count > 0)
|
|
|
|
|
{
|
2025-07-03 20:01:19 +03:00
|
|
|
|
tasks.Add(_queue.Dequeue().ScanAsync());
|
2025-07-03 15:22:40 +03:00
|
|
|
|
}
|
2025-07-03 20:01:19 +03:00
|
|
|
|
await Task.WhenAll(tasks.ToArray());
|
2025-07-03 15:22:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|