Ejemplo n.º 1
0
        protected override async Task <int> OnExecuteAsync(CommandLineApplication app)
        {
            if (Directory.Exists(FilePath))
            {
                _logger.LogInformation("开始扫描文件夹,请稍等...");

                var files = (await _fileScanner.ScanAsync(FilePath, new[] { "*.ncm" }))
                            .SelectMany(f => f.FilePaths)
                            .ToList();

                _logger.LogInformation($"扫描完成,共 {files.Count} 个文件,准备转换。");

                var wrapTask = new WarpTask(4);
                var tasks    = files.Select(path => wrapTask.RunAsync(() => Convert(path)));

                await Task.WhenAll(tasks);
            }
            else if (File.Exists(FilePath))
            {
                await Convert(FilePath);
            }

            _logger.LogInformation("所有文件已经转换完成...");

            return(0);
        }
Ejemplo n.º 2
0
        private async Task <List <string> > ScanMusicFilesAsync()
        {
            var files = (await _fileScanner.ScanAsync(Directory, _options.SupportFileExtensions))
                        .SelectMany(t => t.FilePaths)
                        .ToList();

            if (files.Count == 0)
            {
                _logger.LogError("没有找到任何音乐文件。");
                throw new ErrorCodeException(ErrorCodes.NoFilesWereScanned);
            }

            _logger.LogInformation($"已经扫描到了 {files.Count} 个音乐文件。");

            return(files);
        }