• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版94f8f43fbb15aa9d17e755ae53465417e386b12b (tree)
时间2022-05-21 18:41:49
作者yoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Log Message

[CLEAN] リファクタ
・ヘルパクラスをより関連のある名前空間に移動
・リソースヘルパクラスの例外処理を改善

更改概述

差异

--- a/CleanAuLait48.csproj
+++ b/CleanAuLait48.csproj
@@ -88,8 +88,8 @@
8888 <Compile Include="Core\DI\IRequestScopeGenerator.cs" />
8989 <Compile Include="Core\DI\RequestScopeGenerator.cs" />
9090 <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" />
9393 <Compile Include="Core\Resource\IMessageRepository.cs" />
9494 <Compile Include="Core\Resource\MessageRepository.cs" />
9595 <Compile Include="Core\Resource\ResourceHelper.cs" />
--- a/Core/Helper/JsonHelper.cs
+++ b/Core/Converter/JsonHelper.cs
@@ -2,7 +2,7 @@
22 using System.Runtime.Serialization.Json;
33 using System.Text;
44
5-namespace CleanAuLait48.Core.Helper
5+namespace CleanAuLait48.Core.Converter
66 {
77 /// <see href="https://mokake.hatenablog.com/entry/2017/09/12/195656">
88 public static class JsonHelper
--- a/Core/Helper/LogHelper.cs
+++ b/Core/Log/LogHelper.cs
@@ -1,4 +1,4 @@
1-namespace CleanAuLait48.Core.Helper
1+namespace CleanAuLait48.Core.Log
22 {
33 public static class LogHelper
44 {
--- a/Core/Resource/MessageRepository.cs
+++ b/Core/Resource/MessageRepository.cs
@@ -14,7 +14,7 @@ namespace CleanAuLait48.Core.Resource
1414
1515 private void ReadMessageResource(string nameSpace, string path, Assembly asm)
1616 {
17- string content = ResourceHelper.GetResourceFile(nameSpace, path, asm);
17+ string content = ResourceHelper.LoadTextFromResource(nameSpace, path, asm);
1818
1919 string[] lines = content.Split('\n');
2020
--- a/Core/Resource/ResourceHelper.cs
+++ b/Core/Resource/ResourceHelper.cs
@@ -1,4 +1,5 @@
1-using System;
1+using NLog;
2+using System;
23 using System.IO;
34 using System.Reflection;
45
@@ -6,30 +7,40 @@ namespace CleanAuLait48.Core.Resource
67 {
78 public static class ResourceHelper
89 {
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)
1013 {
1114 string resourceName = nameSpace + path;
1215
13- if (asm == null)
16+ try
1417 {
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)
2219 {
23- throw new ApplicationException($"埋め込みリソース {resourceName} が見つかりません");
20+ asm = Assembly.GetCallingAssembly();
2421 }
2522
26- using (var sr = new StreamReader(stream))
23+ string content = "";
24+ using (var stream = asm.GetManifestResourceStream(resourceName))
2725 {
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+ }
2935 }
30- }
3136
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+ }
3344 }
3445 }
3546 }
--- a/OuterEdge/Repository/Db/Tx/AbstractConnectionFactory.cs
+++ b/OuterEdge/Repository/Db/Tx/AbstractConnectionFactory.cs
@@ -1,4 +1,4 @@
1-using CleanAuLait48.Core.Helper;
1+using CleanAuLait48.Core.Log;
22 using NLog;
33 using System;
44 using System.Collections.Generic;
--- a/OuterEdge/Repository/Db/Tx/DbConnectionWrapper.cs
+++ b/OuterEdge/Repository/Db/Tx/DbConnectionWrapper.cs
@@ -1,4 +1,4 @@
1-using CleanAuLait48.Core.Helper;
1+using CleanAuLait48.Core.Log;
22 using NPoco;
33 using System;
44 using System.Data;
--- a/OuterEdge/Repository/Db/Tx/DbTransactionWrapper.cs
+++ b/OuterEdge/Repository/Db/Tx/DbTransactionWrapper.cs
@@ -1,4 +1,4 @@
1-using CleanAuLait48.Core.Helper;
1+using CleanAuLait48.Core.Log;
22 using NLog;
33 using System.Data;
44 using System.Diagnostics;
--- a/OuterEdge/Repository/Db/Tx/TransactionManager.cs
+++ b/OuterEdge/Repository/Db/Tx/TransactionManager.cs
@@ -1,4 +1,4 @@
1-using CleanAuLait48.Core.Helper;
1+using CleanAuLait48.Core.Log;
22 using NLog;
33 using System.Collections.Generic;
44 using System.Data;