37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using System.Diagnostics;
|
|
using System.Threading.Channels;
|
|
using NLog;
|
|
using PiwigoDirectorySync.Service;
|
|
using Spectre.Console.Cli;
|
|
|
|
namespace PiwigoDirectorySync.Commands;
|
|
|
|
public class ScanCommand : AsyncCommand<ScanSettings>
|
|
{
|
|
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
public override async Task<int> ExecuteAsync(CommandContext context, ScanSettings settings)
|
|
{
|
|
Logger.Info("Starting scanner and remover");
|
|
var stopWatch = Stopwatch.StartNew();
|
|
|
|
var cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
var fileQueue = Channel.CreateUnbounded<string>();
|
|
|
|
var indexer = new FileIndexer(fileQueue);
|
|
var indexerTask = indexer.StartProcessingAsync(cancellationTokenSource.Token);
|
|
|
|
var scanner = new FileScanner(fileQueue);
|
|
await scanner.ScanAsync(cancellationTokenSource.Token);
|
|
|
|
fileQueue.Writer.Complete();
|
|
|
|
await Task.WhenAll(fileQueue.Reader.Completion, indexerTask);
|
|
|
|
stopWatch.Stop();
|
|
Logger.Info($"Processed {indexer.TotalFilesScanned} image files in {stopWatch.Elapsed.TotalSeconds} seconds");
|
|
|
|
return 0;
|
|
}
|
|
} |