feat: Fixed a possible null reference exception.

This commit is contained in:
real-zony 2022-03-20 19:10:51 +08:00
parent 2b41658783
commit a1e9669843
2 changed files with 11 additions and 2 deletions

View File

@ -103,7 +103,9 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
var warpTask = new WarpTask(ParallelNumber); var warpTask = new WarpTask(ParallelNumber);
var warpTaskList = files.Select(file => warpTask.RunAsync(() => Task.Run(async () => await _tagLoader.LoadTagAsync(file)))); var warpTaskList = files.Select(file => warpTask.RunAsync(() => Task.Run(async () => await _tagLoader.LoadTagAsync(file))));
var result = (await Task.WhenAll(warpTaskList)).Where(m => !string.IsNullOrEmpty(m.Name) || !string.IsNullOrEmpty(m.Artist)); var result = (await Task.WhenAll(warpTaskList))
.Where(m => m != null)
.Where(m => !string.IsNullOrEmpty(m.Name) || !string.IsNullOrEmpty(m.Artist));
_logger.LogInformation($"已成功加载 {files.Count} 个音乐文件的标签信息。"); _logger.LogInformation($"已成功加载 {files.Count} 个音乐文件的标签信息。");

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Config;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject; using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
@ -15,14 +16,18 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
{ {
protected readonly IEnumerable<ITagInfoProvider> TagInfoProviders; protected readonly IEnumerable<ITagInfoProvider> TagInfoProviders;
protected readonly IBlockWordDictionary BlockWordDictionary; protected readonly IBlockWordDictionary BlockWordDictionary;
protected readonly ILogger<DefaultTagLoader> _logger;
protected ToolOptions Options; protected ToolOptions Options;
public DefaultTagLoader(IEnumerable<ITagInfoProvider> tagInfoProviders, public DefaultTagLoader(IEnumerable<ITagInfoProvider> tagInfoProviders,
IBlockWordDictionary blockWordDictionary, IBlockWordDictionary blockWordDictionary,
IOptions<ToolOptions> options) IOptions<ToolOptions> options,
ILogger<DefaultTagLoader> logger)
{ {
TagInfoProviders = tagInfoProviders; TagInfoProviders = tagInfoProviders;
BlockWordDictionary = blockWordDictionary; BlockWordDictionary = blockWordDictionary;
_logger = logger;
Options = options.Value; Options = options.Value;
} }
@ -43,6 +48,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
} }
} }
_logger.LogWarning($"{filePath} 没有找到正确的标签信息,请考虑调整正则表达式。");
return null; return null;
} }