Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/blazor_import
Browse files Browse the repository at this point in the history
  • Loading branch information
r-koubou committed Nov 6, 2023
2 parents f9fc103 + 4e3cf94 commit 74558cc
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions KeySwitchManager/Sources/Runtime/Commons/Helpers/EncodingHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -65,5 +67,6 @@ public static KeySwitch CreateTemplate(
{ "extra2 key", "extra2 value" },
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public KeySwitch Create(
IEnumerable<Articulation> articulations,
IReadOnlyDictionary<string, string> extraData )
{
created = DateTimeHelper.ToUtc( created );
lastUpdated = DateTimeHelper.ToUtc( lastUpdated );

return new KeySwitch(
new KeySwitchId( id ),
new Author( author ),
Expand All @@ -57,4 +54,4 @@ public KeySwitch Create(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +34,7 @@ public IReadOnlyCollection<KeySwitch> Translate( Workbook source )

private KeySwitch TranslateWorkSheet( Worksheet sheet, ICollection<Guid> parsedGuidList )
{
var now = DateTimeHelper.NowUtc();
var now = UtcDateTime.NowAsDateTime;
var articulations = new List<Articulation>();
var extraData = new Dictionary<string, string>();

Expand Down Expand Up @@ -143,4 +144,4 @@ private IReadOnlyCollection<MidiProgramChange> TranslateMidiProgramChangeMapping
}

}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,7 +16,7 @@ public class YamlImportContentReader : IImportContentReader
public async Task<IReadOnlyCollection<KeySwitch>> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ) ) );
}
Expand All @@ -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<char>(
new YamlKeySwitchExportTranslator().Translate( KeySwitches ).Value.ToCharArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
using System.Text;
using System.Threading.Tasks;

using KeySwitchManager.Commons.Helpers;

namespace KeySwitchManager.UseCase.KeySwitches.Export
{
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 )
{
Expand Down

0 comments on commit 74558cc

Please sign in to comment.