From 9f96aa0186ffb14c0e0f489cff77fcd0c4e32aa4 Mon Sep 17 00:00:00 2001 From: real-zony Date: Thu, 6 Oct 2022 12:27:21 +0800 Subject: [PATCH] refactor: Move the related configuration items to the Common library. --- ZonyLrcTools.sln | 7 ++++++ src/ZonyLrcTools.Cli/Config/ProviderOption.cs | 16 ------------ src/ZonyLrcTools.Cli/Config/ToolOptions.cs | 3 ++- .../Lyric/LyricItemCollection.cs | 13 +++++----- .../Tag/TagInfoProviderOptions.cs | 25 ------------------- src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj | 4 +++ .../Configuration/BlockWordOptions.cs} | 4 +-- .../GlobalLyricsConfigOptions.cs} | 20 +++------------ .../Configuration/LyricsOptions.cs | 13 ++++++++++ .../Configuration/LyricsProviderOptions.cs} | 4 +-- .../Configuration/ProviderOptions.cs | 14 +++++++++++ .../Configuration/TagInfoOptions.cs | 11 ++++++++ .../Configuration/TagInfoProviderOptions.cs | 11 ++++++++ .../Lyrics}/LineBreakType.cs | 2 +- .../ZonyLrcTools.Common.csproj | 9 +++++++ .../Lyric/LyricCollectionTests.cs | 4 ++- 16 files changed, 89 insertions(+), 71 deletions(-) delete mode 100644 src/ZonyLrcTools.Cli/Config/ProviderOption.cs delete mode 100644 src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs rename src/{ZonyLrcTools.Cli/Config/BlockWordOption.cs => ZonyLrcTools.Common/Configuration/BlockWordOptions.cs} (82%) rename src/{ZonyLrcTools.Cli/Config/LyricOption.cs => ZonyLrcTools.Common/Configuration/GlobalLyricsConfigOptions.cs} (66%) create mode 100644 src/ZonyLrcTools.Common/Configuration/LyricsOptions.cs rename src/{ZonyLrcTools.Cli/Config/LyricProviderOption.cs => ZonyLrcTools.Common/Configuration/LyricsProviderOptions.cs} (84%) create mode 100644 src/ZonyLrcTools.Common/Configuration/ProviderOptions.cs create mode 100644 src/ZonyLrcTools.Common/Configuration/TagInfoOptions.cs create mode 100644 src/ZonyLrcTools.Common/Configuration/TagInfoProviderOptions.cs rename src/{ZonyLrcTools.Cli/Infrastructure/Lyric => ZonyLrcTools.Common/Lyrics}/LineBreakType.cs (90%) create mode 100644 src/ZonyLrcTools.Common/ZonyLrcTools.Common.csproj diff --git a/ZonyLrcTools.sln b/ZonyLrcTools.sln index 59ba155..09bb7fc 100644 --- a/ZonyLrcTools.sln +++ b/ZonyLrcTools.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Tests", "tests EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.LocalServer", "src\ZonyLrcTools.LocalServer\ZonyLrcTools.LocalServer.csproj", "{2875A08A-FFD6-4863-B815-5384DCFE88FC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Common", "src\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj", "{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +33,10 @@ Global {2875A08A-FFD6-4863-B815-5384DCFE88FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {2875A08A-FFD6-4863-B815-5384DCFE88FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {2875A08A-FFD6-4863-B815-5384DCFE88FC}.Release|Any CPU.Build.0 = Release|Any CPU + {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -42,5 +48,6 @@ Global {55D74323-ABFA-4A73-A3BF-F3E8D5DE6DE8} = {C29FB05C-54B1-4020-94D2-87E192EB2F98} {FFBD3200-568F-455B-8390-5E76C51D522C} = {AF8ADB2F-E46C-4DEE-8316-652D9FE1A69B} {2875A08A-FFD6-4863-B815-5384DCFE88FC} = {C29FB05C-54B1-4020-94D2-87E192EB2F98} + {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67} = {C29FB05C-54B1-4020-94D2-87E192EB2F98} EndGlobalSection EndGlobal diff --git a/src/ZonyLrcTools.Cli/Config/ProviderOption.cs b/src/ZonyLrcTools.Cli/Config/ProviderOption.cs deleted file mode 100644 index 011cd94..0000000 --- a/src/ZonyLrcTools.Cli/Config/ProviderOption.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ZonyLrcTools.Cli.Infrastructure.Tag; - -namespace ZonyLrcTools.Cli.Config; - -public class ProviderOption -{ - /// - /// 标签加载器相关的配置属性。 - /// - public TagOption Tag { get; set; } - - /// - /// 歌词下载相关的配置信息。 - /// - public LyricOption Lyric { get; set; } -} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Config/ToolOptions.cs b/src/ZonyLrcTools.Cli/Config/ToolOptions.cs index 8c4b623..c07c64f 100644 --- a/src/ZonyLrcTools.Cli/Config/ToolOptions.cs +++ b/src/ZonyLrcTools.Cli/Config/ToolOptions.cs @@ -3,6 +3,7 @@ using YamlDotNet.Serialization; using ZonyLrcTools.Cli.Infrastructure.Lyric; using ZonyLrcTools.Cli.Infrastructure.Network; using ZonyLrcTools.Cli.Infrastructure.Tag; +using ZonyLrcTools.Common.Configuration; namespace ZonyLrcTools.Cli.Config { @@ -21,6 +22,6 @@ namespace ZonyLrcTools.Cli.Config /// /// 定义下载器的相关配置信息。 /// - public ProviderOption Provider { get; set; } + public ProviderOptions Provider { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs index badbcfe..2bc1cfb 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Infrastructure.Extensions; +using ZonyLrcTools.Common.Configuration; namespace ZonyLrcTools.Cli.Infrastructure.Lyric { @@ -17,11 +18,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric /// public bool IsPruneMusic => Count == 0; - public LyricConfigOption Option { get; private set; } + public GlobalLyricsConfigOptions Options { get; private set; } - public LyricItemCollection(LyricConfigOption option) + public LyricItemCollection(GlobalLyricsConfigOptions options) { - Option = option; + Options = options; } public static LyricItemCollection operator +(LyricItemCollection left, LyricItemCollection right) @@ -31,7 +32,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric return left; } - var option = left.Option; + var option = left.Options; var newCollection = new LyricItemCollection(option); var indexDiff = left.Count - right.Count; if (!option.IsOneLine) @@ -104,8 +105,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric public override string ToString() { var lyricBuilder = new StringBuilder(); - ForEach(lyric => lyricBuilder.Append(lyric).Append(Option.LineBreak)); - return lyricBuilder.ToString().TrimEnd(Option.LineBreak); + ForEach(lyric => lyricBuilder.Append(lyric).Append(Options.LineBreak)); + return lyricBuilder.ToString().TrimEnd(Options.LineBreak); } public byte[] GetUtf8Bytes() diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs deleted file mode 100644 index ff5457e..0000000 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; -using YamlDotNet.Serialization; -using ZonyLrcTools.Cli.Config; - -namespace ZonyLrcTools.Cli.Infrastructure.Tag -{ - public class TagInfoProviderOption - { - public string Name { get; set; } - - public int Priority { get; set; } - - public Dictionary Extensions { get; set; } - } - - public class TagOption - { - public IEnumerable Plugin { get; set; } - - /// - /// 屏蔽词功能相关配置。 - /// - public BlockWordOption BlockWord { get; set; } - } -} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj b/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj index e54a4d3..9069f1f 100644 --- a/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj +++ b/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj @@ -43,4 +43,8 @@ + + + + diff --git a/src/ZonyLrcTools.Cli/Config/BlockWordOption.cs b/src/ZonyLrcTools.Common/Configuration/BlockWordOptions.cs similarity index 82% rename from src/ZonyLrcTools.Cli/Config/BlockWordOption.cs rename to src/ZonyLrcTools.Common/Configuration/BlockWordOptions.cs index c31557a..17d4d69 100644 --- a/src/ZonyLrcTools.Cli/Config/BlockWordOption.cs +++ b/src/ZonyLrcTools.Common/Configuration/BlockWordOptions.cs @@ -1,9 +1,9 @@ -namespace ZonyLrcTools.Cli.Config +namespace ZonyLrcTools.Common.Configuration { /// /// 屏蔽词选项类。 /// - public class BlockWordOption + public class BlockWordOptions { /// /// 是否启用本功能。 diff --git a/src/ZonyLrcTools.Cli/Config/LyricOption.cs b/src/ZonyLrcTools.Common/Configuration/GlobalLyricsConfigOptions.cs similarity index 66% rename from src/ZonyLrcTools.Cli/Config/LyricOption.cs rename to src/ZonyLrcTools.Common/Configuration/GlobalLyricsConfigOptions.cs index e474e4c..764901e 100644 --- a/src/ZonyLrcTools.Cli/Config/LyricOption.cs +++ b/src/ZonyLrcTools.Common/Configuration/GlobalLyricsConfigOptions.cs @@ -1,22 +1,8 @@ -using System.Collections.Generic; -using System.Linq; -using ZonyLrcTools.Cli.Infrastructure.Lyric; +using ZonyLrcTools.Common.Lyrics; -namespace ZonyLrcTools.Cli.Config; +namespace ZonyLrcTools.Common.Configuration; -public class LyricOption -{ - public IEnumerable Plugin { get; set; } - - public LyricConfigOption Config { get; set; } - - public LyricProviderOption GetLyricProviderOption(string name) - { - return Plugin.FirstOrDefault(x => x.Name == name); - } -} - -public class LyricConfigOption +public class GlobalLyricsConfigOptions { /// /// 双语歌词是否合并为一行。 diff --git a/src/ZonyLrcTools.Common/Configuration/LyricsOptions.cs b/src/ZonyLrcTools.Common/Configuration/LyricsOptions.cs new file mode 100644 index 0000000..ed61c9a --- /dev/null +++ b/src/ZonyLrcTools.Common/Configuration/LyricsOptions.cs @@ -0,0 +1,13 @@ +namespace ZonyLrcTools.Common.Configuration; + +public class LyricsOptions +{ + public IEnumerable Plugin { get; set; } + + public GlobalLyricsConfigOptions Config { get; set; } + + public LyricsProviderOptions GetLyricProviderOption(string name) + { + return Plugin.FirstOrDefault(x => x.Name == name); + } +} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs b/src/ZonyLrcTools.Common/Configuration/LyricsProviderOptions.cs similarity index 84% rename from src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs rename to src/ZonyLrcTools.Common/Configuration/LyricsProviderOptions.cs index 7d3be8b..8240d7f 100644 --- a/src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs +++ b/src/ZonyLrcTools.Common/Configuration/LyricsProviderOptions.cs @@ -1,6 +1,6 @@ -namespace ZonyLrcTools.Cli.Config +namespace ZonyLrcTools.Common.Configuration { - public class LyricProviderOption + public class LyricsProviderOptions { /// /// 歌词下载器的唯一标识。 diff --git a/src/ZonyLrcTools.Common/Configuration/ProviderOptions.cs b/src/ZonyLrcTools.Common/Configuration/ProviderOptions.cs new file mode 100644 index 0000000..22a4e71 --- /dev/null +++ b/src/ZonyLrcTools.Common/Configuration/ProviderOptions.cs @@ -0,0 +1,14 @@ +namespace ZonyLrcTools.Common.Configuration; + +public class ProviderOptions +{ + /// + /// 标签加载器相关的配置属性。 + /// + public TagInfoOptions Tag { get; set; } + + /// + /// 歌词下载相关的配置信息。 + /// + public LyricsOptions Lyric { get; set; } +} \ No newline at end of file diff --git a/src/ZonyLrcTools.Common/Configuration/TagInfoOptions.cs b/src/ZonyLrcTools.Common/Configuration/TagInfoOptions.cs new file mode 100644 index 0000000..5d40ce1 --- /dev/null +++ b/src/ZonyLrcTools.Common/Configuration/TagInfoOptions.cs @@ -0,0 +1,11 @@ +namespace ZonyLrcTools.Common.Configuration; + +public class TagInfoOptions +{ + public IEnumerable Plugin { get; set; } + + /// + /// 屏蔽词功能相关配置。 + /// + public BlockWordOptions BlockWord { get; set; } +} \ No newline at end of file diff --git a/src/ZonyLrcTools.Common/Configuration/TagInfoProviderOptions.cs b/src/ZonyLrcTools.Common/Configuration/TagInfoProviderOptions.cs new file mode 100644 index 0000000..f9c100d --- /dev/null +++ b/src/ZonyLrcTools.Common/Configuration/TagInfoProviderOptions.cs @@ -0,0 +1,11 @@ +namespace ZonyLrcTools.Common.Configuration +{ + public class TagInfoProviderOptions + { + public string Name { get; set; } + + public int Priority { get; set; } + + public Dictionary Extensions { get; set; } + } +} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LineBreakType.cs b/src/ZonyLrcTools.Common/Lyrics/LineBreakType.cs similarity index 90% rename from src/ZonyLrcTools.Cli/Infrastructure/Lyric/LineBreakType.cs rename to src/ZonyLrcTools.Common/Lyrics/LineBreakType.cs index b0c9be5..a3e2214 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LineBreakType.cs +++ b/src/ZonyLrcTools.Common/Lyrics/LineBreakType.cs @@ -1,4 +1,4 @@ -namespace ZonyLrcTools.Cli.Infrastructure.Lyric +namespace ZonyLrcTools.Common.Lyrics { /// /// 换行符格式定义。 diff --git a/src/ZonyLrcTools.Common/ZonyLrcTools.Common.csproj b/src/ZonyLrcTools.Common/ZonyLrcTools.Common.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/ZonyLrcTools.Common/ZonyLrcTools.Common.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs index 8bd16a4..4a28794 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs @@ -2,6 +2,8 @@ using Xunit; using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Infrastructure.Lyric; +using ZonyLrcTools.Common.Configuration; +using ZonyLrcTools.Common.Lyrics; namespace ZonyLrcTools.Tests.Infrastructure.Lyric { @@ -10,7 +12,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric [Fact] public void LyricCollectionLineBreak_Test() { - var lyricObject = new LyricItemCollection(new LyricConfigOption + var lyricObject = new LyricItemCollection(new GlobalLyricsConfigOptions { IsOneLine = false, LineBreak = LineBreakType.MacOs