-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feature/blazor_import
- Loading branch information
Showing
8 changed files
with
107 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...tchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlFileRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using KeySwitchManager.Commons.Data; | ||
|
||
namespace KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches | ||
{ | ||
public sealed class YamlFileRepository : YamlMemoryRepository | ||
{ | ||
private FilePath YamlFilePath { get; } | ||
public YamlFileRepository( FilePath filePath ) : base( filePath.OpenReadStream() ) | ||
{ | ||
YamlFilePath = filePath; | ||
} | ||
|
||
public override async void Dispose() | ||
{ | ||
await FlushAsync( default ); | ||
} | ||
|
||
public override async Task<int> FlushAsync( CancellationToken cancellationToken = default ) | ||
{ | ||
await using var stream = YamlFilePath.OpenWriteStream(); | ||
await WriteBinaryToAsync( stream, cancellationToken ); | ||
return Count(); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...hManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlMemoryRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using KeySwitchManager.Commons.Data; | ||
using KeySwitchManager.Domain.KeySwitches; | ||
using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches.Translators; | ||
|
||
using RkHelper.System; | ||
|
||
namespace KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches | ||
{ | ||
public abstract class YamlMemoryRepository : OnMemoryKeySwitchRepository | ||
{ | ||
protected YamlMemoryRepository( Stream stream, bool leaveOpen = false ) : base() | ||
{ | ||
StreamReader? reader = null; | ||
|
||
try | ||
{ | ||
reader = new StreamReader( stream, Encoding.UTF8 ); | ||
var yaml = reader.ReadToEnd(); | ||
KeySwitches.AddRange( new YamlKeySwitchImportTranslator().Translate( new PlainText( yaml ) ) ); | ||
} | ||
finally | ||
{ | ||
if( !leaveOpen && reader is not null ) | ||
{ | ||
Disposer.Dispose( reader ); | ||
Disposer.Dispose( stream ); | ||
} | ||
} | ||
} | ||
|
||
public override async Task WriteBinaryToAsync( Stream stream, CancellationToken cancellationToken = default ) | ||
{ | ||
await using var writer = new StreamWriter( stream, Encoding.UTF8 ); | ||
|
||
var yaml = new ReadOnlyMemory<char>( | ||
new YamlKeySwitchExportTranslator().Translate( KeySwitches ).Value.ToCharArray() | ||
); | ||
|
||
await writer.WriteAsync( yaml, cancellationToken ); | ||
await writer.FlushAsync(); | ||
} | ||
} | ||
} |
189 changes: 0 additions & 189 deletions
189
KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlRepository.cs
This file was deleted.
Oops, something went wrong.