From fec8ac1f8e03a3c58e939bc64a5ac1cc38d55120 Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-koubou" Date: Mon, 6 Nov 2023 20:22:19 +0900 Subject: [PATCH 1/5] =?UTF-8?q?ITF8N=EF=BC=88BOM=E7=84=A1=E3=81=97?= =?UTF-8?q?=EF=BC=89=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Commons/Helpers/EncodingHelper.cs | 14 ++++++++++++++ .../KeySwitches/Import/YamlImportContentReader.cs | 4 ++-- .../KeySwitches/YamlMemoryRepository.cs | 5 +++-- .../UseCases/KeySwitches/Export/StringContent.cs | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs diff --git a/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs b/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs new file mode 100644 index 00000000..e4cb15e5 --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs @@ -0,0 +1,14 @@ +using System.Text; + +namespace KeySwitchManager.Commons.Helpers +{ + public static class EncodingHelper + { + // ReSharper disable InconsistentNaming + public static Encoding UTF8 => Encoding.UTF8; + public static Encoding UTF8N { get; } = new UTF8Encoding( false ); + // ReSharper restore InconsistentNaming + + public static Encoding Default => UTF8N; + } +} diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/Import/YamlImportContentReader.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/Import/YamlImportContentReader.cs index 35dca122..9dbc6f7d 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/Import/YamlImportContentReader.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/Import/YamlImportContentReader.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.IO; -using System.Text; using System.Threading; using System.Threading.Tasks; using KeySwitchManager.Commons.Data; +using KeySwitchManager.Commons.Helpers; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches.Translators; using KeySwitchManager.UseCase.KeySwitches.Import; @@ -16,7 +16,7 @@ public class YamlImportContentReader : IImportContentReader public async Task> ReadAsync( IContent content, CancellationToken cancellationToken = default ) { await using var stream = await content.GetContentStreamAsync( cancellationToken ); - using var reader = new StreamReader( stream, Encoding.UTF8, true ); + using var reader = new StreamReader( stream, EncodingHelper.UTF8N ); var jsonText = await reader.ReadToEndAsync(); diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlMemoryRepository.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlMemoryRepository.cs index eef14707..d4245587 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlMemoryRepository.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlMemoryRepository.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using KeySwitchManager.Commons.Data; +using KeySwitchManager.Commons.Helpers; using KeySwitchManager.Domain.KeySwitches; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches.Translators; @@ -20,7 +21,7 @@ protected YamlMemoryRepository( Stream stream, bool leaveOpen = false ) : base() try { - reader = new StreamReader( stream, Encoding.UTF8 ); + reader = new StreamReader( stream, EncodingHelper.UTF8N ); var yaml = reader.ReadToEnd(); KeySwitches.AddRange( new YamlKeySwitchImportTranslator().Translate( new PlainText( yaml ) ) ); } @@ -36,7 +37,7 @@ protected YamlMemoryRepository( Stream stream, bool leaveOpen = false ) : base() public override async Task WriteBinaryToAsync( Stream stream, CancellationToken cancellationToken = default ) { - await using var writer = new StreamWriter( stream, Encoding.UTF8 ); + await using var writer = new StreamWriter( stream, EncodingHelper.UTF8N ); var yaml = new ReadOnlyMemory( new YamlKeySwitchExportTranslator().Translate( KeySwitches ).Value.ToCharArray() diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/StringContent.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/StringContent.cs index 67b4cd93..99aea27e 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/StringContent.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/StringContent.cs @@ -2,6 +2,8 @@ using System.Text; using System.Threading.Tasks; +using KeySwitchManager.Commons.Helpers; + namespace KeySwitchManager.UseCase.KeySwitches.Export { public class StringContent : IContent @@ -9,7 +11,7 @@ public class StringContent : IContent private readonly string data; private readonly Encoding encoding; - public StringContent( string data ) : this( data, Encoding.UTF8 ) {} + public StringContent( string data ) : this( data, EncodingHelper.UTF8N ) {} public StringContent( string data, Encoding encoding ) { From 69aeaf520b1ba58fc5456aebc2a3b1cf8a849cc6 Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-koubou" Date: Mon, 6 Nov 2023 20:25:32 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E3=82=AF?= =?UTF-8?q?=E3=83=A9=E3=82=B9=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commons/Helpers/UtcDateTimeHelper.cs | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 KeySwitchManager/Sources/Runtime/Commons/Helpers/UtcDateTimeHelper.cs diff --git a/KeySwitchManager/Sources/Runtime/Commons/Helpers/UtcDateTimeHelper.cs b/KeySwitchManager/Sources/Runtime/Commons/Helpers/UtcDateTimeHelper.cs deleted file mode 100644 index d487c252..00000000 --- a/KeySwitchManager/Sources/Runtime/Commons/Helpers/UtcDateTimeHelper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; - -using KeySwitchManager.Commons.Data; - -namespace KeySwitchManager.Commons.Helpers -{ - public static class UtcDateTimeHelper - { - public static DateTime ToDateTime( UtcDateTime dateTime ) - { - return new DateTime( - year: dateTime.Year, - month: dateTime.Month, - day: dateTime.Day, - hour: dateTime.Hour, - minute: dateTime.Minute, - second: dateTime.Second, - millisecond: dateTime.MilliSecond, - DateTimeKind.Utc - ); - } - - public static DateTime ToLocalDateTime( UtcDateTime dateTime ) - { - return new DateTime( - year: dateTime.Year, - month: dateTime.Month, - day: dateTime.Day, - hour: dateTime.Hour, - minute: dateTime.Minute, - second: dateTime.Second, - millisecond: dateTime.MilliSecond, - DateTimeKind.Local - ); - } - - } -} \ No newline at end of file From 750201b286fde15b779408b8b586c02683146495 Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-koubou" Date: Mon, 6 Nov 2023 20:26:34 +0900 Subject: [PATCH 3/5] =?UTF-8?q?kind=E3=81=AE=E6=98=8E=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E3=81=ABUTC=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=97=E5=BF=98?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Commons/Data/Extensions/UtcDateTimeExtension.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/KeySwitchManager/Sources/Runtime/Commons/Data/Extensions/UtcDateTimeExtension.cs b/KeySwitchManager/Sources/Runtime/Commons/Data/Extensions/UtcDateTimeExtension.cs index b7c59ddc..5f642938 100644 --- a/KeySwitchManager/Sources/Runtime/Commons/Data/Extensions/UtcDateTimeExtension.cs +++ b/KeySwitchManager/Sources/Runtime/Commons/Data/Extensions/UtcDateTimeExtension.cs @@ -4,12 +4,13 @@ namespace KeySwitchManager.Commons.Data.Extensions { public static class UtcDateTimeExtension { - public static DateTime As(this UtcDateTime utcDateTime) + public static DateTime As( this UtcDateTime utcDateTime ) { return new DateTime( + kind: DateTimeKind.Utc, year: utcDateTime.Year, month: utcDateTime.Month, - day:utcDateTime.Day, + day: utcDateTime.Day, hour: utcDateTime.Hour, minute: utcDateTime.Minute, second: utcDateTime.Second, From 3235e5320e8a4826d79cb70612b5dc786b9c51f0 Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-koubou" Date: Mon, 6 Nov 2023 21:06:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?UTC=E5=8F=96=E5=BE=97=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/KeySwitches/Helpers/KeySwitchFactoryHelper.cs | 9 ++++++--- .../KeySwitches/Models/Factory/IKeySwitchFactory.cs | 5 +---- .../Translators/SpreadsheetImportTranslator.cs | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/KeySwitchFactoryHelper.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/KeySwitchFactoryHelper.cs index d4d0d512..68eb7833 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/KeySwitchFactoryHelper.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/KeySwitchFactoryHelper.cs @@ -27,12 +27,14 @@ public static KeySwitch CreateTemplate( IMidiNoteOnFactory midiNoteOnFactory, IMidiControlChangeFactory midiControlChangeFactory, IMidiProgramChangeFactory midiProgramChangeFactory ) - => factory.Create( + { + var now = UtcDateTime.NowAsDateTime; + return factory.Create( Guid.NewGuid(), "Author", "Description", - UtcDateTime.NowAsDateTime, - UtcDateTime.NowAsDateTime, + now, + now, "Developer Name", "Product name", "Instrument name", @@ -65,5 +67,6 @@ public static KeySwitch CreateTemplate( { "extra2 key", "extra2 value" }, } ); + } } } diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/Factory/IKeySwitchFactory.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/Factory/IKeySwitchFactory.cs index 7b9fc2b2..efb3d37a 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/Factory/IKeySwitchFactory.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/Factory/IKeySwitchFactory.cs @@ -39,9 +39,6 @@ public KeySwitch Create( IEnumerable articulations, IReadOnlyDictionary extraData ) { - created = DateTimeHelper.ToUtc( created ); - lastUpdated = DateTimeHelper.ToUtc( lastUpdated ); - return new KeySwitch( new KeySwitchId( id ), new Author( author ), @@ -57,4 +54,4 @@ public KeySwitch Create( } } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet/KeySwitches/Translators/SpreadsheetImportTranslator.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet/KeySwitches/Translators/SpreadsheetImportTranslator.cs index 60fb48fe..990f19ad 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet/KeySwitches/Translators/SpreadsheetImportTranslator.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet/KeySwitches/Translators/SpreadsheetImportTranslator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using KeySwitchManager.Commons.Data; +using KeySwitchManager.Commons.Data.Extensions; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Domain.KeySwitches.Models.Aggregations; using KeySwitchManager.Domain.KeySwitches.Models.Factory; @@ -33,7 +34,7 @@ public IReadOnlyCollection Translate( Workbook source ) private KeySwitch TranslateWorkSheet( Worksheet sheet, ICollection parsedGuidList ) { - var now = DateTimeHelper.NowUtc(); + var now = UtcDateTime.NowAsDateTime; var articulations = new List(); var extraData = new Dictionary(); @@ -143,4 +144,4 @@ private IReadOnlyCollection TranslateMidiProgramChangeMapping } } -} \ No newline at end of file +} From bb31276bdc1fb666300e0fc42b767c787b5ef13c Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-koubou" Date: Mon, 6 Nov 2023 21:15:07 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Runtime/Commons/Helpers/EncodingHelper.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs b/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs index e4cb15e5..570cf9b5 100644 --- a/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs +++ b/KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs @@ -8,7 +8,5 @@ public static class EncodingHelper public static Encoding UTF8 => Encoding.UTF8; public static Encoding UTF8N { get; } = new UTF8Encoding( false ); // ReSharper restore InconsistentNaming - - public static Encoding Default => UTF8N; } }