修订版 | 94f8f43fbb15aa9d17e755ae53465417e386b12b (tree) |
---|---|
时间 | 2022-05-21 18:41:49 |
作者 | yoshy <yoshy.org.bitbucket@gz.j...> |
Commiter | yoshy |
[CLEAN] リファクタ
・ヘルパクラスをより関連のある名前空間に移動
・リソースヘルパクラスの例外処理を改善
@@ -88,8 +88,8 @@ | ||
88 | 88 | <Compile Include="Core\DI\IRequestScopeGenerator.cs" /> |
89 | 89 | <Compile Include="Core\DI\RequestScopeGenerator.cs" /> |
90 | 90 | <Compile Include="Core\Helper\DateTimeHelper.cs" /> |
91 | - <Compile Include="Core\Helper\JsonHelper.cs" /> | |
92 | - <Compile Include="Core\Helper\LogHelper.cs" /> | |
91 | + <Compile Include="Core\Converter\JsonHelper.cs" /> | |
92 | + <Compile Include="Core\Log\LogHelper.cs" /> | |
93 | 93 | <Compile Include="Core\Resource\IMessageRepository.cs" /> |
94 | 94 | <Compile Include="Core\Resource\MessageRepository.cs" /> |
95 | 95 | <Compile Include="Core\Resource\ResourceHelper.cs" /> |
@@ -2,7 +2,7 @@ | ||
2 | 2 | using System.Runtime.Serialization.Json; |
3 | 3 | using System.Text; |
4 | 4 | |
5 | -namespace CleanAuLait48.Core.Helper | |
5 | +namespace CleanAuLait48.Core.Converter | |
6 | 6 | { |
7 | 7 | /// <see href="https://mokake.hatenablog.com/entry/2017/09/12/195656"> |
8 | 8 | public static class JsonHelper |
@@ -1,4 +1,4 @@ | ||
1 | -namespace CleanAuLait48.Core.Helper | |
1 | +namespace CleanAuLait48.Core.Log | |
2 | 2 | { |
3 | 3 | public static class LogHelper |
4 | 4 | { |
@@ -14,7 +14,7 @@ namespace CleanAuLait48.Core.Resource | ||
14 | 14 | |
15 | 15 | private void ReadMessageResource(string nameSpace, string path, Assembly asm) |
16 | 16 | { |
17 | - string content = ResourceHelper.GetResourceFile(nameSpace, path, asm); | |
17 | + string content = ResourceHelper.LoadTextFromResource(nameSpace, path, asm); | |
18 | 18 | |
19 | 19 | string[] lines = content.Split('\n'); |
20 | 20 |
@@ -1,4 +1,5 @@ | ||
1 | -using System; | |
1 | +using NLog; | |
2 | +using System; | |
2 | 3 | using System.IO; |
3 | 4 | using System.Reflection; |
4 | 5 |
@@ -6,30 +7,40 @@ namespace CleanAuLait48.Core.Resource | ||
6 | 7 | { |
7 | 8 | public static class ResourceHelper |
8 | 9 | { |
9 | - public static string GetResourceFile(string nameSpace, string path, Assembly asm) | |
10 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
11 | + | |
12 | + public static string LoadTextFromResource(string nameSpace, string path, Assembly asm = null) | |
10 | 13 | { |
11 | 14 | string resourceName = nameSpace + path; |
12 | 15 | |
13 | - if (asm == null) | |
16 | + try | |
14 | 17 | { |
15 | - asm = Assembly.GetCallingAssembly(); | |
16 | - } | |
17 | - | |
18 | - string content = ""; | |
19 | - using (var stream = asm.GetManifestResourceStream(resourceName)) | |
20 | - { | |
21 | - if (stream == null) | |
18 | + if (asm == null) | |
22 | 19 | { |
23 | - throw new ApplicationException($"埋め込みリソース {resourceName} が見つかりません"); | |
20 | + asm = Assembly.GetCallingAssembly(); | |
24 | 21 | } |
25 | 22 | |
26 | - using (var sr = new StreamReader(stream)) | |
23 | + string content = ""; | |
24 | + using (var stream = asm.GetManifestResourceStream(resourceName)) | |
27 | 25 | { |
28 | - content = sr.ReadToEnd(); | |
26 | + if (stream == null) | |
27 | + { | |
28 | + throw new ApplicationException($"埋め込みリソーステキスト {resourceName} が見つかりません"); | |
29 | + } | |
30 | + | |
31 | + using (var sr = new StreamReader(stream)) | |
32 | + { | |
33 | + content = sr.ReadToEnd(); | |
34 | + } | |
29 | 35 | } |
30 | - } | |
31 | 36 | |
32 | - return content; | |
37 | + return content; | |
38 | + } | |
39 | + catch (Exception e) when ((e is SystemException) || (e is IOException)) | |
40 | + { | |
41 | + logger.Error(e); | |
42 | + throw new ApplicationException($"埋め込みリソーステキスト {resourceName} の読み込みに失敗しました", e); | |
43 | + } | |
33 | 44 | } |
34 | 45 | } |
35 | 46 | } |
@@ -1,4 +1,4 @@ | ||
1 | -using CleanAuLait48.Core.Helper; | |
1 | +using CleanAuLait48.Core.Log; | |
2 | 2 | using NLog; |
3 | 3 | using System; |
4 | 4 | using System.Collections.Generic; |
@@ -1,4 +1,4 @@ | ||
1 | -using CleanAuLait48.Core.Helper; | |
1 | +using CleanAuLait48.Core.Log; | |
2 | 2 | using NPoco; |
3 | 3 | using System; |
4 | 4 | using System.Data; |
@@ -1,4 +1,4 @@ | ||
1 | -using CleanAuLait48.Core.Helper; | |
1 | +using CleanAuLait48.Core.Log; | |
2 | 2 | using NLog; |
3 | 3 | using System.Data; |
4 | 4 | using System.Diagnostics; |
@@ -1,4 +1,4 @@ | ||
1 | -using CleanAuLait48.Core.Helper; | |
1 | +using CleanAuLait48.Core.Log; | |
2 | 2 | using NLog; |
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Data; |