diff --git a/KeySwitchManager/KeySwitchManager.sln b/KeySwitchManager/KeySwitchManager.sln index b535c524..cd292b61 100644 --- a/KeySwitchManager/KeySwitchManager.sln +++ b/KeySwitchManager/KeySwitchManager.sln @@ -14,8 +14,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interactors", "Sources\Runt EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructures", "Infrastructures", "{505E86DD-3A59-4038-B109-22B3678D035E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Database.LiteDB", "Sources\Runtime\Infrastructures\Database.LiteDB\Database.LiteDB.csproj", "{20749A6A-AD52-4545-B6B2-A921EC8CF850}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Json", "Sources\Runtime\Infrastructures\Storage.Json\Storage.Json.csproj", "{EAE5D07E-8455-4C33-BCD1-07EFF958E21B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Xml", "Sources\Runtime\Infrastructures\Storage.Xml\Storage.Xml.csproj", "{499CCE1B-A7D9-4EFA-B890-8785C137EF72}" @@ -32,8 +30,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Sources\Tests\Dom EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructures", "Infrastructures", "{B1FC3859-B078-471F-81F2-FBB0A25C974B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Database.LiteDB", "Sources\Tests\Infrastructures\Database.LiteDB\Database.LiteDB.csproj", "{87930720-147C-4DD4-89C8-F022A65BE461}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Xml", "Sources\Tests\Infrastructures\Storage.Xml\Storage.Xml.csproj", "{20F51031-CED4-48E2-BBC2-99239D4C3A68}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Yaml", "Sources\Runtime\Infrastructures\Storage.Yaml\Storage.Yaml.csproj", "{17FB1646-6A55-422B-AB7C-9AEB25126D03}" @@ -74,10 +70,6 @@ Global {8CAA9A5D-B054-42F7-8589-300866F8223A}.Debug|Any CPU.Build.0 = Debug|Any CPU {8CAA9A5D-B054-42F7-8589-300866F8223A}.Release|Any CPU.ActiveCfg = Release|Any CPU {8CAA9A5D-B054-42F7-8589-300866F8223A}.Release|Any CPU.Build.0 = Release|Any CPU - {20749A6A-AD52-4545-B6B2-A921EC8CF850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {20749A6A-AD52-4545-B6B2-A921EC8CF850}.Debug|Any CPU.Build.0 = Debug|Any CPU - {20749A6A-AD52-4545-B6B2-A921EC8CF850}.Release|Any CPU.ActiveCfg = Release|Any CPU - {20749A6A-AD52-4545-B6B2-A921EC8CF850}.Release|Any CPU.Build.0 = Release|Any CPU {EAE5D07E-8455-4C33-BCD1-07EFF958E21B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EAE5D07E-8455-4C33-BCD1-07EFF958E21B}.Debug|Any CPU.Build.0 = Debug|Any CPU {EAE5D07E-8455-4C33-BCD1-07EFF958E21B}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -106,10 +98,6 @@ Global {D023CB3F-71C6-4925-9651-5FBA3BEF4404}.Debug|Any CPU.Build.0 = Debug|Any CPU {D023CB3F-71C6-4925-9651-5FBA3BEF4404}.Release|Any CPU.ActiveCfg = Release|Any CPU {D023CB3F-71C6-4925-9651-5FBA3BEF4404}.Release|Any CPU.Build.0 = Release|Any CPU - {87930720-147C-4DD4-89C8-F022A65BE461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {87930720-147C-4DD4-89C8-F022A65BE461}.Debug|Any CPU.Build.0 = Debug|Any CPU - {87930720-147C-4DD4-89C8-F022A65BE461}.Release|Any CPU.ActiveCfg = Release|Any CPU - {87930720-147C-4DD4-89C8-F022A65BE461}.Release|Any CPU.Build.0 = Release|Any CPU {20F51031-CED4-48E2-BBC2-99239D4C3A68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {20F51031-CED4-48E2-BBC2-99239D4C3A68}.Debug|Any CPU.Build.0 = Debug|Any CPU {20F51031-CED4-48E2-BBC2-99239D4C3A68}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -136,14 +124,12 @@ Global {D35DCF05-CE3B-4258-AF17-5D73C2A9EE86}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution - {20749A6A-AD52-4545-B6B2-A921EC8CF850} = {505E86DD-3A59-4038-B109-22B3678D035E} {EAE5D07E-8455-4C33-BCD1-07EFF958E21B} = {505E86DD-3A59-4038-B109-22B3678D035E} {499CCE1B-A7D9-4EFA-B890-8785C137EF72} = {505E86DD-3A59-4038-B109-22B3678D035E} {1747E137-ABC6-4DE6-BE33-9C6B6335266F} = {505E86DD-3A59-4038-B109-22B3678D035E} {62BED324-A809-4740-BB44-7D0ADC88B8E3} = {505E86DD-3A59-4038-B109-22B3678D035E} {BA5C1A39-004B-45EC-8FB6-59DB7F80A305} = {505E86DD-3A59-4038-B109-22B3678D035E} {01822D19-80DD-4979-BA62-FE10E4ACE5CA} = {DF635B48-6000-45EF-AA41-01E06BA4A254} - {87930720-147C-4DD4-89C8-F022A65BE461} = {B1FC3859-B078-471F-81F2-FBB0A25C974B} {20F51031-CED4-48E2-BBC2-99239D4C3A68} = {B1FC3859-B078-471F-81F2-FBB0A25C974B} {17FB1646-6A55-422B-AB7C-9AEB25126D03} = {505E86DD-3A59-4038-B109-22B3678D035E} {A2D9D05E-00A1-456D-93DF-40CB784BB74A} = {B1FC3859-B078-471F-81F2-FBB0A25C974B} diff --git a/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore b/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore new file mode 100644 index 00000000..0174d1d7 --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore @@ -0,0 +1,2 @@ +# Automatically generated during the build and publish process +./VERSION.md diff --git a/KeySwitchManager/Sources/Runtime/Applications/CLI/Applications.CLI.csproj b/KeySwitchManager/Sources/Runtime/Applications/CLI/Applications.CLI.csproj index b9a9f504..da7a58be 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/CLI/Applications.CLI.csproj +++ b/KeySwitchManager/Sources/Runtime/Applications/CLI/Applications.CLI.csproj @@ -8,7 +8,7 @@ KeySwitchManager.Applications.CLI R-Koubou KeySwitchManager CLI Application - 0.5.2 + 0.5.3 KeySwitchManager CLI Application enable diff --git a/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs b/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs index 583d7ad9..ebbacf55 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs @@ -9,7 +9,7 @@ public class New : ICommand [Verb( "new", HelpText = "export a template file" )] public class CommandOption : ICommandOption { - [Value( index: 0, MetaName = "output", HelpText = "Output path for template file (*.yaml or *.xlsx or *.db)", Default = "(ProductName).yaml" )] + [Value( index: 0, MetaName = "output", HelpText = "Output path for template file (*.yaml or *.xlsx)", Default = "(ProductName).yaml" )] public string OutputPath { get; set; } = string.Empty; } diff --git a/KeySwitchManager/Sources/Runtime/Applications/CLI/VERSION.md b/KeySwitchManager/Sources/Runtime/Applications/CLI/VERSION.md deleted file mode 100644 index 774d77ac..00000000 --- a/KeySwitchManager/Sources/Runtime/Applications/CLI/VERSION.md +++ /dev/null @@ -1,10 +0,0 @@ -KeySwitchManager CLI Application -============================== - -## Assembly Version - -0.5.2.0 - -## Build At - -2023-06-24 01:17:09 +09:00 diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Applications.Core.csproj b/KeySwitchManager/Sources/Runtime/Applications/Core/Applications.Core.csproj index baf97ff1..9c453f29 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Applications.Core.csproj +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Applications.Core.csproj @@ -14,7 +14,6 @@ - diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/ControlExecutor.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/ControlExecutor.cs index 3a9a44b1..d694155b 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/ControlExecutor.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/ControlExecutor.cs @@ -8,11 +8,14 @@ namespace KeySwitchManager.Applications.Core.Controllers public static class ControlExecutor { public static void Execute( Func controllerFactory, ILogTextView logTextView ) + => ExecuteAsync( controllerFactory, logTextView ).GetAwaiter().GetResult(); + + public static async Task ExecuteAsync( Func controllerFactory, ILogTextView logTextView ) { try { using var controller = controllerFactory.Invoke(); - ExecuteImpl( controller, logTextView ); + await ExecuteImplAsync( controller, logTextView ); } catch( Exception exception ) { @@ -20,23 +23,16 @@ public static void Execute( Func controllerFactory, ILogTextView lo } } - private static void ExecuteImpl( IController controller, ILogTextView logTextView ) + private static async Task ExecuteImplAsync( IController controller, ILogTextView logTextView ) { try { - controller.Execute(); + await controller.ExecuteAsync(); } catch( Exception e ) { logTextView.Append( e.ToString() ); } } - - public static async Task ExecuteAsync( Func controllerFactory, ILogTextView logTextView ) - { - await Task.Run( () => { - Execute( controllerFactory, logTextView ); - } ); - } } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateControllerFactory.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateControllerFactory.cs index f853328f..c5be9074 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateControllerFactory.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateControllerFactory.cs @@ -4,7 +4,6 @@ using KeySwitchManager.Applications.Core.Views.LogView; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches; using KeySwitchManager.Infrastructures.Storage.Spreadsheet.ClosedXml.KeySwitches; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches; @@ -26,11 +25,6 @@ public static IController Create( string outputFilePath, ILogTextView logTextVie return CreateImpl( outputFilePath, logTextView, ( stream ) => new YamlKeySwitchWriter( stream ) ); } - if( path.EndsWith( ".db" ) ) - { - return CreateImpl( logTextView, new LiteDbFileWriter( new FilePath( outputFilePath ) ) ); - } - throw new ArgumentException( $"{outputFilePath} is unknown file format" ); } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateFileController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateFileController.cs index 633c6477..a2985748 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateFileController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Create/CreateFileController.cs @@ -1,4 +1,6 @@ -using KeySwitchManager.Domain.KeySwitches.Models; +using System.Threading.Tasks; + +using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Interactors.KeySwitches; using KeySwitchManager.UseCase.KeySwitches.Create; @@ -27,10 +29,10 @@ public void Dispose() } } - public void Execute() + async Task IController.ExecuteAsync() { - var interactor = new CreateFileInteractor( Presenter ); - var response = interactor.Execute( new CreateFileRequest( Writer ) ); + ICreateFileUseCase interactor = new CreateFileInteractor( Presenter ); + var response = await interactor.ExecuteAsync( new CreateFileRequest( Writer ) ); Presenter.Complete( response ); } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Delete/DeleteController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Delete/DeleteController.cs index a184d406..5f7d2173 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Delete/DeleteController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Delete/DeleteController.cs @@ -1,4 +1,6 @@ -using KeySwitchManager.Domain.KeySwitches.Models; +using System.Threading.Tasks; + +using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Interactors.KeySwitches; using KeySwitchManager.UseCase.KeySwitches.Delete; @@ -41,11 +43,11 @@ public void Dispose() } } - public void Execute() + async Task IController.ExecuteAsync() { - var interactor = new DeleteInteractor( DatabaseRepository, Presenter ); + IDeleteUseCase interactor = new DeleteInteractor( DatabaseRepository, Presenter ); var request = new DeleteRequest( DeveloperName, ProductName, InstrumentName ); - var response = interactor.Execute( request ); + var response = await interactor.ExecuteAsync( request ); if( response.RemovedCount > 0 ) { diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Dump/DumpFileController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Dump/DumpFileController.cs index 1f777f0c..4e5c5a5e 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Dump/DumpFileController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Dump/DumpFileController.cs @@ -1,4 +1,6 @@ -using KeySwitchManager.Domain.KeySwitches.Models; +using System.Threading.Tasks; + +using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Interactors.KeySwitches; using KeySwitchManager.UseCase.KeySwitches.Dump; @@ -32,15 +34,15 @@ public void Dispose() } } - public void Execute() + async Task IController.ExecuteAsync() { - var interactor = new DumpFileInteractor( + IDumpFileUseCase interactor = new DumpFileInteractor( SourceRepository, Writer, Presenter ); - var response = interactor.Execute( new DumpFileRequest() ); + var response = await interactor.ExecuteAsync( new DumpFileRequest() ); Presenter.Complete( response ); } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Export/ExportFileController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Export/ExportFileController.cs index 78225178..aeb19d16 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Export/ExportFileController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Export/ExportFileController.cs @@ -1,5 +1,6 @@ using System; using System.Reactive.Subjects; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Domain.KeySwitches.Models.Values; @@ -53,15 +54,15 @@ public void Dispose() } } - public void Execute() + async Task IController.ExecuteAsync() { - var interactor = new ExportFileInteractor( + IExportFileUseCase interactor = new ExportFileInteractor( SourceRepository, Writer, Presenter ); - var response = interactor.Execute( + var response = await interactor.ExecuteAsync( new ExportFileRequest( DeveloperName.Value, ProductName.Value, diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Find/FindController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Find/FindController.cs index fa83350a..80d7abba 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Find/FindController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Find/FindController.cs @@ -1,4 +1,6 @@ -using KeySwitchManager.Domain.KeySwitches.Models; +using System.Threading.Tasks; + +using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Interactors.KeySwitches; using KeySwitchManager.UseCase.KeySwitches.Find; @@ -41,11 +43,11 @@ public void Dispose() } } - public void Execute() + async Task IController.ExecuteAsync() { - var interactor = new FindInteractor( DatabaseRepository, Presenter ); + IFindUseCase interactor = new FindInteractor( DatabaseRepository, Presenter ); var request = new FindRequest( DeveloperName, ProductName, InstrumentName ); - var response = interactor.Execute( request ); + var response = await interactor.ExecuteAsync( request ); Presenter.Complete( response ); } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/IController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/IController.cs index 5f7543d3..ae7cb84a 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/IController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/IController.cs @@ -1,9 +1,13 @@ using System; +using System.Threading.Tasks; namespace KeySwitchManager.Applications.Core.Controllers { public interface IController : IDisposable { - void Execute(); + void Execute() + => ExecuteAsync().GetAwaiter().GetResult(); + + Task ExecuteAsync(); } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Import/ImportFileController.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Import/ImportFileController.cs index 5b6df1a5..488970b1 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Import/ImportFileController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Controllers/Import/ImportFileController.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Interactors.KeySwitches; @@ -49,13 +50,13 @@ public void Dispose() } } - public void Execute() + async Task IController.ExecuteAsync() { var keySwitches = KeySwitchReader.Read(); - var interactor = new ImportFileInteractor( DatabaseRepository, Presenter ); + IImportFileUseCase interactor = new ImportFileInteractor( DatabaseRepository, Presenter ); var request = new ImportFileRequest( keySwitches ); - var response = interactor.Execute( request ); - DatabaseRepository.Flush(); + var response = await interactor.ExecuteAsync( request ); + await DatabaseRepository.FlushAsync(); Presenter.Complete( response ); } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Core/Helpers/KeySwitchRepositoryFactory.cs b/KeySwitchManager/Sources/Runtime/Applications/Core/Helpers/KeySwitchRepositoryFactory.cs index 0324fa34..6414b5a3 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Core/Helpers/KeySwitchRepositoryFactory.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Core/Helpers/KeySwitchRepositoryFactory.cs @@ -2,7 +2,6 @@ using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches; namespace KeySwitchManager.Applications.Core.Helpers @@ -13,11 +12,6 @@ public static IKeySwitchRepository CreateFileRepository(string filePath) { var path = filePath.ToLower(); - if( path.EndsWith( ".db" ) ) - { - return new LiteDbRepository( new FilePath( filePath ) ); - } - if( path.EndsWith( ".yaml" ) || path.EndsWith( ".yml" ) ) { return new YamlRepository( new FilePath( filePath ) ); diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore b/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore new file mode 100644 index 00000000..0174d1d7 --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore @@ -0,0 +1,2 @@ +# Automatically generated during the build and publish process +./VERSION.md diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/Applications.WPF.csproj b/KeySwitchManager/Sources/Runtime/Applications/WPF/Applications.WPF.csproj index 8b874445..4829654d 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Applications.WPF.csproj +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Applications.WPF.csproj @@ -5,9 +5,10 @@ net7.0-windows true KeySwitchManager + KeySwitchManager.Applications.WPF KeySwitchManager WPF Application KeySwitchManager WPF Application - 0.5.2 + 0.5.3 enable @@ -21,7 +22,6 @@ - diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml index 1da800c6..ccbbdd33 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml @@ -1,4 +1,4 @@ - diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml.cs b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml.cs index 3d62ccd1..1d4aa681 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/App.xaml.cs @@ -1,4 +1,4 @@ -namespace KeySwitchManager.WPF +namespace KeySwitchManager.Applications.WPF { /// /// Interaction logic for App.xaml diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/ApplicationConfig.cs b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/ApplicationConfig.cs index ccf6532d..a39ad8f1 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/ApplicationConfig.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/ApplicationConfig.cs @@ -6,7 +6,7 @@ using YamlDotNet.Serialization; -namespace KeySwitchManager.WPF +namespace KeySwitchManager.Applications.WPF { public class ApplicationConfigModel { diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml index 8d260563..5f1e8b56 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml @@ -1,4 +1,4 @@ - /// Interaction logic for MainWindow.xaml @@ -29,8 +27,8 @@ namespace KeySwitchManager.WPF public partial class MainWindow { private const string KeySwitchDefinitionFileFilter = "KeySwitch definition File|*.xlsx;*.yaml;*.yml"; - private const string KeySwitchDatabaseFileFilter = "KeySwitch Database File|*.yaml;*.yml;*.db"; - private const string KeySwitchAllFileFilter = "Supported File|*.xlsx;*.yaml;*.yml;*.db"; + private const string KeySwitchDatabaseFileFilter = "KeySwitch Database File|*.yaml;*.yml"; + private const string KeySwitchAllFileFilter = "Supported File|*.xlsx;*.yaml;*.yml"; #region UI Binding #endregion @@ -51,9 +49,21 @@ public MainWindow() private void InitializeCustomComponent() { ExportFormatCombobox.ItemsSource = ExportSupportedFormatList; + InitializeWindowTitle(); LoadApplicationConfig(); } + private void InitializeWindowTitle() + { + var version = typeof( MainWindow ).Assembly.GetName().Version; + + if( version != null ) + { + Title = $"{Title} (Version {version.ToString( 3 )})"; + } + + } + #region Executions private void PreExecuteController() { @@ -79,7 +89,12 @@ private void PostExecuteController() private async Task ExecuteControllerAsync( Func controllerFactory ) { PreExecuteController(); - await ControlExecutor.ExecuteAsync( controllerFactory, LogTextView ); + + await Task.Run( async () => { + await ControlExecutor.ExecuteAsync( controllerFactory, LogTextView ); + } + ); + PostExecuteController(); } #endregion diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/WpfView/LogTextView.cs b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/WpfView/LogTextView.cs index 3b7d4a99..8972c0e0 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/WpfView/LogTextView.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/WpfView/LogTextView.cs @@ -4,7 +4,7 @@ using KeySwitchManager.Applications.Core.Views.LogView; -namespace KeySwitchManager.WPF.WpfView +namespace KeySwitchManager.Applications.WPF.WpfView { public class LogTextView : ILogTextView { diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/VERSION.md b/KeySwitchManager/Sources/Runtime/Applications/WPF/VERSION.md index 080b450f..9fe7c3a8 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/VERSION.md +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/VERSION.md @@ -3,8 +3,8 @@ KeySwitchManager WPF Application ## Assembly Version -0.5.2.0 +0.5.3.0 ## Build At -2023-06-24 01:18:53 +09:00 +2023-10-23 23:32:45 +09:00 diff --git a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore new file mode 100644 index 00000000..0174d1d7 --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore @@ -0,0 +1,2 @@ +# Automatically generated during the build and publish process +./VERSION.md diff --git a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Applications.Xamarin.Mac.csproj b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Applications.Xamarin.Mac.csproj index b91a658a..c67558db 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Applications.Xamarin.Mac.csproj +++ b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Applications.Xamarin.Mac.csproj @@ -6,7 +6,7 @@ {6343EE02-E18E-4492-B3B3-B0544ACE01E5} {A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe - 0.5.0 + 0.5.3 KeySwitchManager Xamarin.Mac Application KeySwitchManager.Xamarin.Mac KeySwitchManager @@ -88,9 +88,6 @@ - - Always - Always diff --git a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Sources/ViewController.cs b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Sources/ViewController.cs index 7dc5365c..fd473a1e 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Sources/ViewController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/Sources/ViewController.cs @@ -92,7 +92,12 @@ private void PostExecuteController() private async Task ExecuteControllerAsync( Func controllerFactory ) { PreExecuteController(); - await ControlExecutor.ExecuteAsync( controllerFactory, LogView ); + + await Task.Run( async () => { + await ControlExecutor.ExecuteAsync( controllerFactory, LogView ); + } + ); + PostExecuteController(); } #endregion @@ -108,7 +113,7 @@ partial void OnCreateDefinitionFileChooserButtonClicked( NSObject sender ) { ChooseSaveFilePath( ( path ) => { NewFileText.StringValue = path; - }, "db", "yaml", "xlsx" ); + }, "yaml", "yml", "xlsx" ); } async partial void OnOpenNewFileButtonClicked( NSObject sender ) @@ -130,14 +135,14 @@ partial void OnOpenDatabaseFileChooserButtonClicked( NSObject sender ) { ChooseOpenFilePath( ( path ) => { ImportDatabaseFileText.StringValue = path; - }, "db" ); + }, "yaml", "yml" ); } partial void OnOpenFileChooserButtonClicked( NSObject sender ) { ChooseOpenFilePath( ( path ) => { ImportFileText.StringValue = path; - }, "yaml", "xlsx" ); + }, "yaml", "yml", "xlsx" ); } async partial void OnDoImportButtonClicked( NSObject sender ) @@ -159,7 +164,7 @@ partial void OpenFindDatabaseFileChooserButtonClicked( NSObject sender ) { ChooseOpenFilePath( ( path ) => { FindDatabaseFileText.StringValue = path; - }, "db" ); + }, "yaml", "yml" ); } async partial void OnFindButtonClicked( NSObject sender ) diff --git a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/VERSION.md b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/VERSION.md deleted file mode 100644 index a4480ba5..00000000 --- a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/VERSION.md +++ /dev/null @@ -1,10 +0,0 @@ -KeySwitchManager Xamarin.Mac Application -============================== - -## Version - -0.3.1 - -## Build At - -2022-10-04 04:14:37 +09:00 diff --git a/KeySwitchManager/Sources/Runtime/Commons/Commons.csproj b/KeySwitchManager/Sources/Runtime/Commons/Commons.csproj index 077bffd4..d17251c1 100644 --- a/KeySwitchManager/Sources/Runtime/Commons/Commons.csproj +++ b/KeySwitchManager/Sources/Runtime/Commons/Commons.csproj @@ -14,7 +14,7 @@ - + diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/SearchHelper.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/SearchHelper.cs index 6e0562ba..fa4b1f60 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/SearchHelper.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Helpers/SearchHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Domain.KeySwitches.Models.Values; @@ -11,13 +12,21 @@ namespace KeySwitchManager.Domain.KeySwitches.Helpers public static class SearchHelper { #region Search + public static IReadOnlyCollection Search( IKeySwitchRepository repository, string developerName = "", string productName = "", string instrumentName = "" ) + => SearchAsync( repository, developerName, productName, instrumentName ).GetAwaiter().GetResult(); + + public static async Task> SearchAsync( + IKeySwitchRepository repository, + string developerName = "", + string productName = "", + string instrumentName = "" ) { - return Search( repository, default, developerName, productName, instrumentName ); + return await SearchAsync( repository, default, developerName, productName, instrumentName ); } public static IReadOnlyCollection Search( @@ -26,11 +35,19 @@ public static IReadOnlyCollection Search( string developerName = "", string productName = "", string instrumentName = "" ) + => SearchAsync( repository, guid, developerName, productName, instrumentName ).GetAwaiter().GetResult(); + + public static async Task> SearchAsync( + IKeySwitchRepository repository, + Guid guid = default, + string developerName = "", + string productName = "", + string instrumentName = "" ) { #region By Guid if( guid != default ) { - return new List( repository.Find( new KeySwitchId( guid ) ) ); + return new List( await repository.FindAsync( new KeySwitchId( guid ) ) ); } #endregion @@ -38,7 +55,7 @@ public static IReadOnlyCollection Search( if( !StringHelper.IsEmpty( developerName, productName, instrumentName ) ) { return new List( - repository.Find( + await repository.FindAsync( new DeveloperName( developerName ), new ProductName( productName ), new InstrumentName( instrumentName ) ) @@ -50,7 +67,7 @@ public static IReadOnlyCollection Search( if( !StringHelper.IsEmpty( developerName, productName ) ) { return new List( - repository.Find( + await repository.FindAsync( new DeveloperName( developerName ), new ProductName( productName ) ) @@ -62,7 +79,7 @@ public static IReadOnlyCollection Search( if( !StringHelper.IsEmpty( developerName ) ) { return new List( - repository.Find( + await repository.FindAsync( new DeveloperName( developerName ) ) ); @@ -70,14 +87,19 @@ public static IReadOnlyCollection Search( #endregion // All - return new List( repository.FindAll() ); + return new List( await repository.FindAllAsync() ); } public static IReadOnlyCollection Search( IKeySwitchRepository repository, KeySwitchInfo info ) + => SearchAsync( repository, info ).GetAwaiter().GetResult(); + + public static async Task> SearchAsync( + IKeySwitchRepository repository, + KeySwitchInfo info ) { - return Search( + return await SearchAsync( repository, info.DeveloperName, info.ProductName @@ -86,4 +108,4 @@ public static IReadOnlyCollection Search( #endregion } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchReader.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchReader.cs index f01f1041..58fa3ede 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchReader.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchReader.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace KeySwitchManager.Domain.KeySwitches.Models { @@ -7,6 +8,10 @@ public interface IKeySwitchReader : IDisposable { public const int DefaultStreamReaderBufferSize = 4096; // System.IO.StreamReader.DefaultBufferSize is 4096 public bool LeaveOpen { get; } - public IReadOnlyCollection Read( IObserver? loggingSubject = null ); + + public IReadOnlyCollection Read( IObserver? loggingSubject = null ) + => ReadAsync( loggingSubject ).GetAwaiter().GetResult(); + + public Task> ReadAsync( IObserver? loggingSubject ); } } diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchRepository.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchRepository.cs index b89a2b43..274fc832 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchRepository.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models.Values; @@ -12,22 +13,95 @@ public interface IKeySwitchRepository : IDisposable public IObservable OnLogging { get; } public int Count(); - public SaveResult Save( KeySwitch keySwitch ); - public int Flush() => 0; - public int Delete( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ); - public int Delete( DeveloperName developerName, ProductName productName ); - public int Delete( DeveloperName developerName ); - public int Delete( ProductName productName ); - public int Delete( InstrumentName instrumentName ); - public int Delete( KeySwitchId keySwitchId ); - public int DeleteAll(); - public IReadOnlyCollection Find( KeySwitchId keySwitchId ); - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ); - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName ); - public IReadOnlyCollection Find( DeveloperName developerName ); - public IReadOnlyCollection Find( ProductName productName ); - public IReadOnlyCollection Find( InstrumentName instrumentName ); - public IReadOnlyCollection FindAll(); + + #region Save + public SaveResult Save( KeySwitch keySwitch ) + => SaveAsync( keySwitch ).GetAwaiter().GetResult(); + + public Task SaveAsync( KeySwitch keySwitch ); + #endregion + + #region Flush + public int Flush() + => FlushAsync().GetAwaiter().GetResult(); + + public Task FlushAsync() + => Task.FromResult( 0 ); + #endregion + + #region Delete + public int Delete( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) + => DeleteAsync(developerName, productName, instrumentName).GetAwaiter().GetResult(); + + public Task DeleteAsync( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ); + + public int Delete( DeveloperName developerName, ProductName productName ) + => DeleteAsync( developerName, productName ).GetAwaiter().GetResult(); + + public Task DeleteAsync( DeveloperName developerName, ProductName productName ); + + public int Delete( DeveloperName developerName ) + => DeleteAsync( developerName ).GetAwaiter().GetResult(); + + public Task DeleteAsync( DeveloperName developerName ); + + public int Delete( ProductName productName ) + => DeleteAsync( productName ).GetAwaiter().GetResult(); + + public Task DeleteAsync( ProductName productName ); + + public int Delete( InstrumentName instrumentName ) + => DeleteAsync( instrumentName ).GetAwaiter().GetResult(); + + public Task DeleteAsync( InstrumentName instrumentName ); + + public int Delete( KeySwitchId keySwitchId ) + => DeleteAsync( keySwitchId ).GetAwaiter().GetResult(); + + public Task DeleteAsync( KeySwitchId keySwitchId ); + + public int DeleteAll() + => DeleteAllAsync().GetAwaiter().GetResult(); + + public Task DeleteAllAsync(); + #endregion + + #region Find + public IReadOnlyCollection Find( KeySwitchId keySwitchId ) + => FindAsync( keySwitchId ).GetAwaiter().GetResult(); + + public Task> FindAsync( KeySwitchId keySwitchId ); + + public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) + => FindAsync( developerName, productName, instrumentName ).GetAwaiter().GetResult(); + + public Task> FindAsync( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ); + + public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName ) + => FindAsync( developerName, productName ).GetAwaiter().GetResult(); + + public Task> FindAsync( DeveloperName developerName, ProductName productName ); + + public IReadOnlyCollection Find( DeveloperName developerName ) + => FindAsync( developerName ).GetAwaiter().GetResult(); + + public Task> FindAsync( DeveloperName developerName ); + + public IReadOnlyCollection Find( ProductName productName ) + => FindAsync( productName ).GetAwaiter().GetResult(); + + public Task> FindAsync( ProductName productName ); + + public IReadOnlyCollection Find( InstrumentName instrumentName ) + => FindAsync( instrumentName ).GetAwaiter().GetResult(); + + public Task> FindAsync( InstrumentName instrumentName ); + + public IReadOnlyCollection FindAll() + => FindAllAsync().GetAwaiter().GetResult(); + + public Task> FindAllAsync(); + #endregion public class SaveResult : IEquatable { @@ -57,4 +131,4 @@ public bool Equals( SaveResult? other ) } } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchWriter.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchWriter.cs index be0777f3..92a68967 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/IKeySwitchWriter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace KeySwitchManager.Domain.KeySwitches.Models { @@ -8,6 +9,9 @@ public interface IKeySwitchWriter : IDisposable public const int DefaultStreamWriterBufferSize = 1024; // System.IO.StreamWriter.DefaultBufferSize is 1024 public bool LeaveOpen { get; } - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ); + public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + => WriteAsync( keySwitches, loggingSubject ).GetAwaiter().GetResult(); + + public Task WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ); } } diff --git a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/OnMemoryKeySwitchRepository.cs b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/OnMemoryKeySwitchRepository.cs index fe3c9a2c..d311da0a 100644 --- a/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/OnMemoryKeySwitchRepository.cs +++ b/KeySwitchManager/Sources/Runtime/Domain/KeySwitches/Models/OnMemoryKeySwitchRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reactive.Subjects; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Helpers; using KeySwitchManager.Domain.KeySwitches.Models.Values; @@ -37,140 +38,141 @@ public int Count() => KeySwitches.Count; #region Save - public IKeySwitchRepository.SaveResult Save( KeySwitch keySwitch ) + public async Task SaveAsync( KeySwitch keySwitch ) { var exist = KeySwitches.Find( x => x.Id.Value.Equals( keySwitch.Id.Value ) ); if( exist != null ) { var index = KeySwitches.IndexOf( exist ); - KeySwitches[ index ] = keySwitch; - return new IKeySwitchRepository.SaveResult( 0, 1 ); + KeySwitches[ index ] = keySwitch; + return await Task.FromResult( new IKeySwitchRepository.SaveResult( 0, 1 ) ); } KeySwitches.Add( keySwitch ); - return new IKeySwitchRepository.SaveResult( 1, 0 ); + + return await Task.FromResult( new IKeySwitchRepository.SaveResult( 1, 0 ) ); } - public virtual int Flush() - => Count(); + public virtual async Task FlushAsync() + => await Task.FromResult( Count() ); #endregion #region Delete - public int Delete( KeySwitchId keySwitchId ) + public async Task DeleteAsync( KeySwitchId keySwitchId ) { - var founds = Find( keySwitchId ); + var founds = await FindAsync( keySwitchId ); return founds.Sum( x => KeySwitches.Remove( x ) ? 1 : 0 ); } - public int Delete( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) + public async Task DeleteAsync( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) { - var founds = Find( developerName, productName, instrumentName ); + var founds = await FindAsync( developerName, productName, instrumentName ); return founds.Sum( x => KeySwitches.Remove( x ) ? 1 : 0 ); } - public int Delete( DeveloperName developerName, ProductName productName ) + public async Task DeleteAsync( DeveloperName developerName, ProductName productName ) { - var founds = Find( developerName, productName ); + var founds = await FindAsync( developerName, productName ); return founds.Sum( x => KeySwitches.Remove( x ) ? 1 : 0 ); } - public int Delete( DeveloperName developerName ) + public async Task DeleteAsync( DeveloperName developerName ) { - var founds = Find( developerName ); + var founds = await FindAsync( developerName ); return founds.Sum( x => KeySwitches.Remove( x ) ? 1 : 0 ); } - public int Delete( ProductName productName ) + public async Task DeleteAsync( ProductName productName ) { - var founds = Find( productName ); + var founds = await FindAsync( productName ); return founds.Sum( x => KeySwitches.Remove( x ) ? 1 : 0 ); } - public int Delete( InstrumentName instrumentName ) + public async Task DeleteAsync( InstrumentName instrumentName ) { - var founds = Find( instrumentName ); + var founds = await FindAsync( instrumentName ); return founds.Sum( x => KeySwitches.Remove( x ) ? 1 : 0 ); } - public int DeleteAll() + public async Task DeleteAllAsync() { var count = KeySwitches.Count; KeySwitches.Clear(); - return count; + return await Task.FromResult( count ); } #endregion #region Find - public IReadOnlyCollection Find( KeySwitchId keySwitchId ) - => KeySwitchHelper.SortByAlphabetical( + public async Task> FindAsync( KeySwitchId keySwitchId ) + => await Task.FromResult( KeySwitchHelper.SortByAlphabetical( KeySwitches.FindAll( x => x.Id.Value == keySwitchId.Value - )); + ))); - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) + public async Task> FindAsync( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) { var d = developerName.Value; var p = productName.Value; var i = instrumentName.Value; - return KeySwitchHelper.SortByAlphabetical( + return await Task.FromResult( KeySwitchHelper.SortByAlphabetical( KeySwitches.FindAll( x => ( d == DeveloperName.Any.Value || x.DeveloperName.Value.Contains( d ) ) && ( p == ProductName.Any.Value || x.ProductName.Value.Contains( p ) ) && ( i == InstrumentName.Any.Value || x.InstrumentName.Value.Contains( i ) ) - )); + ))); } - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName ) + public async Task> FindAsync( DeveloperName developerName, ProductName productName ) { var d = developerName.Value; var p = productName.Value; - return KeySwitchHelper.SortByAlphabetical( + return await Task.FromResult( KeySwitchHelper.SortByAlphabetical( KeySwitches.FindAll( x => ( d == DeveloperName.Any.Value || x.DeveloperName.Value.Contains( d ) ) && ( p == ProductName.Any.Value || x.ProductName.Value.Contains( p ) ) - )); + ))); } - public IReadOnlyCollection Find( DeveloperName developerName ) + public async Task> FindAsync( DeveloperName developerName ) { var d = developerName.Value; - return KeySwitchHelper.SortByAlphabetical( + return await Task.FromResult( KeySwitchHelper.SortByAlphabetical( KeySwitches.FindAll( x => d == DeveloperName.Any.Value || x.DeveloperName.Value.Contains( d ) - )); + ))); } - public IReadOnlyCollection Find( ProductName productName ) + public async Task> FindAsync( ProductName productName ) { var p = productName.Value; - return KeySwitchHelper.SortByAlphabetical( + return await Task.FromResult( KeySwitchHelper.SortByAlphabetical( KeySwitches.FindAll( x => p == ProductName.Any.Value || x.ProductName.Value.Contains( p ) - )); + ))); } - public IReadOnlyCollection Find( InstrumentName instrumentName ) + public async Task> FindAsync( InstrumentName instrumentName ) { var i = instrumentName.Value; - return KeySwitchHelper.SortByAlphabetical( + return await Task.FromResult( KeySwitchHelper.SortByAlphabetical( KeySwitches.FindAll( x => i == InstrumentName.Any.Value || x.InstrumentName.Value.Contains( i ) - )); + ))); } - public IReadOnlyCollection FindAll() - => KeySwitchHelper.SortByAlphabetical( new List( KeySwitches ) ); + public async Task> FindAllAsync() + => await Task.FromResult( KeySwitchHelper.SortByAlphabetical( new List( KeySwitches ) ) ); #endregion } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/Database.LiteDB.csproj b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/Database.LiteDB.csproj deleted file mode 100644 index e86d2b8c..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/Database.LiteDB.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - 9 - netstandard2.1 - - R-Koubou - R-Koubou - KeySwitchManager.Database.LiteDB - KeySwitchManager.Infrastructures.Database.LiteDB - KeySwitchManager.Infrastructures.Database.LiteDB - enable - - - - - - - - - - - - diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbFileWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbFileWriter.cs deleted file mode 100644 index 7c12c84b..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbFileWriter.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.KeySwitches.Models; - -using RkHelper.System; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches -{ - public class LiteDbFileWriter : IKeySwitchWriter - { - private LiteDbRepository Repository { get; } - - public bool LeaveOpen => false; - - public LiteDbFileWriter( FilePath dbFilePath ) - { - Repository = new LiteDbRepository( dbFilePath ); - } - - public void Dispose() - { - Disposer.Dispose( Repository ); - } - - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) - { - foreach( var x in keySwitches ) - { - loggingSubject?.OnNext( x.ToString() ); - Repository.Save( x ); - } - } - } -} diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbRepository.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbRepository.cs deleted file mode 100644 index e419f34c..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbRepository.cs +++ /dev/null @@ -1,275 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reactive.Subjects; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.KeySwitches.Helpers; -using KeySwitchManager.Domain.KeySwitches.Models; -using KeySwitchManager.Domain.KeySwitches.Models.Values; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Models; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Translators; - -using LiteDB; - -using RkHelper.System; -using RkHelper.Time; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches -{ - [Obsolete( "Use YamlhRepository instead" )] - public class LiteDbRepository : IKeySwitchRepository - { - public const string KeySwitchesTableName = @"keyswitches"; - - private readonly Subject logging = new(); - public IObservable OnLogging => logging; - - private LiteDatabase Database { get; set; } - - private ILiteCollection KeySwitchTable - => Database.GetCollection( KeySwitchesTableName ); - - public LiteDbRepository( FilePath dbFilePath ) - { - Database = new LiteDatabase( dbFilePath.Path ); - } - - public void Dispose() - { - Disposer.Dispose( logging ); - Close(); - } - - private void Close() - { - lock( this ) - { - if( Database == default! ) - { - return; - } - - Database.Dispose(); - Database = default!; - } - } - - public int Count() - { - var table = Database.GetCollection( KeySwitchesTableName ); - return table.Count(); - } - - #region Save - public IKeySwitchRepository.SaveResult Save( KeySwitch keySwitch ) - { - logging.OnNext( keySwitch.ToString() ); - - var table = Database.GetCollection( KeySwitchesTableName ); - - var translator = new KeySwitchExportTranslator(); - var entity = translator.Translate( keySwitch ); - var exist = table.Find( x => x.Id.Equals( keySwitch.Id.Value ), 0, 1 ).ToList(); - - if( exist.Any() ) - { - entity.Created = DateTimeHelper.ToUtc( exist[ 0 ].Created ); - entity.LastUpdated = DateTimeHelper.NowUtc(); - var updated = table.Update( entity ) ? 1 : 0; - - return new IKeySwitchRepository.SaveResult( - inserted: 0, - updated: updated - ); - } - - entity.Id = keySwitch.Id.Value; - - var insertedId = table.Insert( entity ).AsGuid; - return new IKeySwitchRepository.SaveResult( - inserted: insertedId == entity.Id ? 1 : 0, - updated: 0 - ); - } - - #endregion - - #region Delete - public int Delete( KeySwitchId keySwitchId ) - { - var result = KeySwitchTable.Delete( keySwitchId.Value ); - return result ? 1 : 0; - } - - public int Delete( - DeveloperName developerName, - ProductName productName, - InstrumentName instrumentName ) - { - var d = developerName.Value; - var p = productName.Value; - var i = instrumentName.Value; - - return KeySwitchTable.DeleteMany( - x => - ( d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) ) && - ( p == ProductName.Any.Value || x.ProductName.Contains( p ) ) && - ( i == InstrumentName.Any.Value || x.InstrumentName.Contains( i ) ) - ); - } - - public int Delete( DeveloperName developerName, ProductName productName ) - { - var d = developerName.Value; - var p = productName.Value; - - return KeySwitchTable.DeleteMany( - x => - ( d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) ) && - ( p == ProductName.Any.Value || x.ProductName.Contains( p ) ) - ); - } - - public int Delete( DeveloperName developerName ) - { - var d = developerName.Value; - - return KeySwitchTable.DeleteMany( - x => - d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) - ); - } - - public int Delete( ProductName productName ) - { - var p = productName.Value; - - return KeySwitchTable.DeleteMany( - x => - p == ProductName.Any.Value || x.ProductName.Contains( p ) - ); - } - - public int Delete( InstrumentName instrumentName ) - { - var i = instrumentName.Value; - - return KeySwitchTable.DeleteMany( - x => - i == InstrumentName.Any.Value || x.InstrumentName.Contains( i ) - ); - } - - public int DeleteAll() - { - var table = Database.GetCollection( KeySwitchesTableName ); - return table.DeleteAll(); - } - #endregion - - #region Find - private IReadOnlyCollection CreateEntities( IEnumerable query ) - { - var result = new List(); - var translator = new KeySwitchImportTranslator(); - - foreach( var item in query ) - { - result.Add( translator.Translate( item ) ); - } - - return KeySwitchHelper.SortByAlphabetical( result ); - } - - public IReadOnlyCollection Find( KeySwitchId keySwitchId ) - { - return CreateEntities( KeySwitchTable.Find( x => x.Id == keySwitchId.Value ) ); - } - - public IReadOnlyCollection Find( - DeveloperName developerName, - ProductName productName, - InstrumentName instrumentName ) - { - var d = developerName.Value; - var p = productName.Value; - var i = instrumentName.Value; - - return CreateEntities( - KeySwitchTable.Find( - x => - ( d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) ) && - ( p == ProductName.Any.Value || x.ProductName.Contains( p ) ) && - ( i == InstrumentName.Any.Value || x.InstrumentName.Contains( i ) ) - ) - ); - } - - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName ) - { - var d = developerName.Value; - var p = productName.Value; - - return CreateEntities( - KeySwitchTable.Find( - x => - ( d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) ) && - ( p == ProductName.Any.Value || x.ProductName.Contains( p ) ) - ) - ); - } - - public IReadOnlyCollection Find( DeveloperName developerName ) - { - var d = developerName.Value; - - if( d == DeveloperName.Any.Value ) - { - return FindAll(); - } - - return CreateEntities( - KeySwitchTable.Find( - x => - x.DeveloperName.Contains( d ) - ) - ); - } - - public IReadOnlyCollection Find( ProductName productName ) - { - var p = productName.Value; - - if( p == ProductName.Any.Value ) - { - return FindAll(); - } - - return CreateEntities( - KeySwitchTable.Find( - x => - x.ProductName.Contains( p ) - ) - ); - } - - public IReadOnlyCollection Find( InstrumentName instrumentName ) - { - var i = instrumentName.Value; - - return CreateEntities( - KeySwitchTable.Find( - x => - i == InstrumentName.Any.Value || x.InstrumentName.Contains( i ) - ) - ); - } - - public IReadOnlyCollection FindAll() - { - return CreateEntities( KeySwitchTable.FindAll() ); - } - #endregion - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/ArticulationModel.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/ArticulationModel.cs deleted file mode 100644 index b25514ba..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/ArticulationModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Models -{ - internal class ArticulationModel - { - public string ArticulationName { get; set; } = "Unknown"; - public ICollection NoteOn { get; set; } = new List(); - public ICollection ControlChange { get; set; } = new List(); - public ICollection ProgramChange { get; set; } = new List(); - public IDictionary ExtraData { get; set; } = new Dictionary(); - - public ArticulationModel() - {} - - public ArticulationModel( - string articulationName, - ICollection midiNoteOns, - ICollection midiControlChanges, - ICollection midiProgramChanges, - IDictionary extraData ) - { - ArticulationName = articulationName; - NoteOn = midiNoteOns; - ControlChange = midiControlChanges; - ProgramChange = midiProgramChanges; - ExtraData = extraData; - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/KeySwitchModel.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/KeySwitchModel.cs deleted file mode 100644 index e8d5db27..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/KeySwitchModel.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; - -using LiteDB; - -using RkHelper.Time; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Models -{ - internal class KeySwitchModel - { - [BsonId] - public Guid Id { get; set; } = Guid.NewGuid(); - - public string Author { get; set; } = "Unknwon"; - public string Description { get; set; } = string.Empty; - public DateTime Created { get; set; } = DateTimeHelper.NowUtc(); - public DateTime LastUpdated { get; set; } = DateTimeHelper.NowUtc(); - public string DeveloperName { get; set; } = "Unknown"; - public string ProductName { get; set; } = "Unknown"; - public string InstrumentName { get; set; } = "Unknown"; - public ICollection Articulations { get; set; } = new List(); - public IDictionary ExtraData { get; set; } = new Dictionary(); - - public KeySwitchModel() - {} - - public KeySwitchModel( - Guid id, - string author, - string description, - DateTime created, - DateTime lastUpdated, - string developerName, - string productName, - string instrumentName, - ICollection articulations, - IDictionary extraData ) - { - Id = id; - Author = author; - Description = description; - Created = created; - LastUpdated = lastUpdated; - DeveloperName = developerName; - ProductName = productName; - InstrumentName = instrumentName; - Articulations = articulations; - ExtraData = extraData; - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/MidiMessageModel.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/MidiMessageModel.cs deleted file mode 100644 index a5c936e4..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/MidiMessageModel.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Models -{ - internal class MidiMessageModel - { - public int Status { get; set; } - public int DataByte1 { get; set; } - public int DataByte2 { get; set; } - - public MidiMessageModel() - {} - - public MidiMessageModel( - int status, - int dataByte1, - int dataByte2 ) - { - Status = status; - DataByte1 = dataByte1; - DataByte2 = dataByte2; - } - - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchExportTranslator.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchExportTranslator.cs deleted file mode 100644 index 1f6a40b7..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchExportTranslator.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Collections.Generic; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Commons.Helpers; -using KeySwitchManager.Domain.KeySwitches.Models; -using KeySwitchManager.Domain.KeySwitches.Models.Values; -using KeySwitchManager.Domain.MidiMessages.Models.Aggregations; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Models; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Translators -{ - internal class KeySwitchExportTranslator : IDataTranslator - { - public KeySwitchModel Translate( KeySwitch source ) - { - var articulationModels = new List(); - - foreach( var i in source.Articulations ) - { - var noteOn = new List(); - var controlChange = new List(); - var programChange = new List(); - - ConvertMessageList( i.MidiNoteOns, noteOn ); - ConvertMessageList( i.MidiControlChanges, controlChange ); - ConvertMessageList( i.MidiProgramChanges, programChange ); - - var articulation = new ArticulationModel( - i.ArticulationName.Value, - noteOn, - controlChange, - programChange, - ConvertExtraData( i.ExtraData ) - ); - - articulationModels.Add( articulation ); - } - - return new KeySwitchModel( - source.Id.Value, - source.Author.Value, - source.Description.Value, - UtcDateTimeHelper.ToDateTime( source.Created ), - UtcDateTimeHelper.ToDateTime( source.LastUpdated ), - source.DeveloperName.Value, - source.ProductName.Value, - source.InstrumentName.Value, - articulationModels, - ConvertExtraData( source.ExtraData ) - ); - } - - private static void ConvertMessageList( IReadOnlyCollection src, ICollection dest ) - { - foreach( var i in src ) - { - dest.Add( - new MidiMessageModel( - i.Status.Value, - i.DataByte1.Value, - i.DataByte2.Value - ) - ); - } - } - - private static Dictionary ConvertExtraData( ExtraData source ) - { - var extra = new Dictionary(); - - foreach( var keyValuePair in source ) - { - var k = keyValuePair.Key.Value; - var v = keyValuePair.Value.Value; - extra[ k ] = v; - } - - return extra; - } - - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchImportTranslator.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchImportTranslator.cs deleted file mode 100644 index c0bf6db8..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchImportTranslator.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.KeySwitches.Models; -using KeySwitchManager.Domain.KeySwitches.Models.Aggregations; -using KeySwitchManager.Domain.KeySwitches.Models.Factory; -using KeySwitchManager.Domain.MidiMessages.Models.Aggregations; -using KeySwitchManager.Domain.MidiMessages.Models.Factory; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Models; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches.Translators -{ - internal class KeySwitchImportTranslator : IDataTranslator - { - public KeySwitch Translate( KeySwitchModel source ) - { - var articulations = new List(); - - foreach( var i in source.Articulations ) - { - var noteOn = new List(); - var controlChange = new List(); - var programChange = new List(); - - ConvertMessageList( i.NoteOn, noteOn, IMidiNoteOnFactory.Default ); - ConvertMessageList( i.ControlChange, controlChange, IMidiControlChangeFactory.Default ); - ConvertMessageList( i.ProgramChange, programChange, IMidiProgramChangeFactory.Default ); - - var articulation = IArticulationFactory.Default.Create( - i.ArticulationName, - noteOn, - controlChange, - programChange, - ConvertExtraData( i.ExtraData ) - ); - - articulations.Add( articulation ); - } - - return IKeySwitchFactory.Default.Create( - source.Id, - source.Author, - source.Description, - source.Created, - source.LastUpdated, - source.DeveloperName, - source.ProductName, - source.InstrumentName, - articulations, - ConvertExtraData( source.ExtraData ) - ); - - } - - private static IReadOnlyDictionary ConvertExtraData( IDictionary source ) - { - var extra = new Dictionary(); - - foreach( var keyValuePair in source ) - { - var k = keyValuePair.Key; - var v = keyValuePair.Value; - extra.Add( k, v.ToString()! ); - } - - return extra; - } - - private static void ConvertMessageList( - IEnumerable src, - ICollection dest, - IMidiChannelVoiceMessageFactory messageFactory ) - { - foreach( var i in src ) - { - dest.Add( - messageFactory.Create( - i.Status & 0x0F, - i.DataByte1, - i.DataByte2 - ) - ); - } - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/CakewalkWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/CakewalkWriter.cs index e7ed5e28..67ea693c 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/CakewalkWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/CakewalkWriter.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Infrastructures.Storage.Json.KeySwitches.Cakewalk.Translators; @@ -38,7 +39,7 @@ public void Dispose() Stream = null; } - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { if( Stream == null ) { @@ -59,11 +60,11 @@ public void Write( IReadOnlyCollection keySwitches, IObserver loggingSubject?.OnNext( source.ToString() ); - using var writer = new StreamWriter( Stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); + await using var writer = new StreamWriter( Stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); // TODO すべての要素を束ねた 1 JSONファイルにしたい(Cakewalkは保持できる) var jsonText = new CakewalkExportTranslator( true ).Translate( source ); - writer.WriteLine( jsonText ); + await writer.WriteLineAsync( jsonText.Value ); } } } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/DividedCakewalkWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/DividedCakewalkWriter.cs index dcfc433e..242871a6 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/DividedCakewalkWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Json/KeySwitches/Cakewalk/DividedCakewalkWriter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -26,9 +27,9 @@ public DividedCakewalkWriter( DirectoryPath outputDirectory, Encoding filEncodin public void Dispose() {} - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { - MultipleWritingHelper.Write( + await MultipleWritingHelper.WriteAsync( keySwitches, OutputDirectory, Suffix, diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlReader.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlReader.cs index e4c68917..29c7a4ba 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlReader.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlReader.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Infrastructures.Storage.Spreadsheet.ClosedXml.KeySwitches.Helper; @@ -37,7 +38,7 @@ public void Dispose() Stream = null; } - public IReadOnlyCollection Read( IObserver? loggingSubject = null ) + async Task> IKeySwitchReader.ReadAsync( IObserver? loggingSubject ) { if( Stream == null ) { @@ -46,8 +47,8 @@ public IReadOnlyCollection Read( IObserver? loggingSubject = using var memory = new MemoryStream( InitialBufferSize ); - StreamHelper.ReadAllAndWrite( Stream, memory ); - byte[] xlsxBytes = memory.ToArray(); + await StreamHelper.ReadAllAndWriteAsync( Stream, memory ); + var xlsxBytes = memory.ToArray(); var workBook = XlsxWorkBookParsingHelper.Parse( xlsxBytes ); var translator = new SpreadsheetImportTranslator(); diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlWriter.cs index 4b56744a..c0fc7089 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/ClosedXmlWriter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using ClosedXML.Excel; @@ -36,7 +37,7 @@ public void Dispose() Stream = null; } - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { using var template = new XLWorkbook( StreamHelper.GetAssemblyResourceStream( "Template.xlsx" ) @@ -61,6 +62,8 @@ public void Write( IReadOnlyCollection keySwitches, IObserver } workbook.SaveAs( Stream ); + + await Task.CompletedTask; } } } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/CombinedClosedXmlWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/CombinedClosedXmlWriter.cs index 7257bd6e..32714065 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/CombinedClosedXmlWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/CombinedClosedXmlWriter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Helpers; @@ -23,7 +24,7 @@ public CombinedClosedXmlWriter( DirectoryPath outputDirectory ) public void Dispose() {} - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { var groupByDeveloperAndProduct = KeySwitchHelper.GroupBy( keySwitches ); @@ -33,7 +34,7 @@ public void Write( IReadOnlyCollection keySwitches, IObserver var product = kvp.Key.Item2; var items = kvp.Value; - CombinedWritingHelper.Write( + await CombinedWritingHelper.WriteAsync( items, OutputDirectory, items.First(), diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/DividedClosedXmlWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/DividedClosedXmlWriter.cs index e6fd232a..748962fd 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/DividedClosedXmlWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Spreadsheet.ClosedXml/KeySwitches/DividedClosedXmlWriter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -21,9 +22,9 @@ public DividedClosedXmlWriter( DirectoryPath outputDirectory ) public void Dispose() {} - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { - MultipleWritingHelper.Write( + await MultipleWritingHelper.WriteAsync( keySwitches, OutputDirectory, Suffix, diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/Cubase/CubaseWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/Cubase/CubaseWriter.cs index acedbc97..584be3e6 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/Cubase/CubaseWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/Cubase/CubaseWriter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -28,15 +29,15 @@ public CubaseWriter( DirectoryPath outputDirectory, Encoding filEncoding ) public void Dispose() {} - public void Write( IReadOnlyCollection keySwitches, IObserver? logging = null ) - => MultipleWritingHelper.Write( keySwitches, OutputDirectory, Suffix, logging, WriteImpl ); + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? logging ) + => await MultipleWritingHelper.WriteAsync( keySwitches, OutputDirectory, Suffix, logging, WriteImplAsync ); - private void WriteImpl( Stream stream, KeySwitch keySwitch, IObserver? logging ) + private async Task WriteImplAsync( Stream stream, KeySwitch keySwitch, IObserver? logging ) { - using var writer = new StreamWriter( stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); + await using var writer = new StreamWriter( stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); var xmlText = new CubaseExportTranslator().Translate( keySwitch ); - writer.WriteLine( xmlText ); + await writer.WriteLineAsync( xmlText.Value ); } } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/StudioOne/StudioOneWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/StudioOne/StudioOneWriter.cs index 9ce063da..bfafe80a 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/StudioOne/StudioOneWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Xml/KeySwitches/StudioOne/StudioOneWriter.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Helpers; @@ -34,7 +35,7 @@ public StudioOneWriter( DirectoryPath outputDirectory, Encoding filEncoding ) public void Dispose() {} - public void Write( IReadOnlyCollection keySwitches, IObserver? logging = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? logging ) { if( !keySwitches.Any() ) { @@ -50,11 +51,11 @@ public void Write( IReadOnlyCollection keySwitches, IObserver Translate( rootElement, developerName, productName, x, logging ); var filePath = CreatePathHelper.CreateFilePath( developerName, productName, Suffix, OutputDirectory ); - using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); - using var writer = new StreamWriter( stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); + await using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); + await using var writer = new StreamWriter( stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); var xmlText = XmlHelper.ToXmlString( rootElement ); - writer.WriteLine( xmlText ); + await writer.WriteLineAsync( xmlText ); } } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/DividedYamlFileWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/DividedYamlFileWriter.cs index 9247e881..49e3807b 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/DividedYamlFileWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/DividedYamlFileWriter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -26,9 +27,9 @@ public DividedYamlFileWriter( DirectoryPath outputDirectory, Encoding filEncodin public void Dispose() {} - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { - MultipleWritingHelper.Write( + await MultipleWritingHelper.WriteAsync( keySwitches, OutputDirectory, Suffix, diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchReader.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchReader.cs index 4619d7f8..2545881a 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchReader.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchReader.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -37,7 +38,7 @@ public void Dispose() Stream = null; } - public IReadOnlyCollection Read( IObserver? loggingSubject = null ) + async Task> IKeySwitchReader.ReadAsync( IObserver? loggingSubject ) { if( Stream == null ) { @@ -45,7 +46,7 @@ public IReadOnlyCollection Read( IObserver? loggingSubject = } using var reader = new StreamReader( Stream, FileEncoding, true, IKeySwitchReader.DefaultStreamReaderBufferSize, LeaveOpen ); - var jsonText = reader.ReadToEnd(); + var jsonText = await reader.ReadToEndAsync(); var keySwitches = new YamlKeySwitchImportTranslator().Translate( new PlainText( jsonText ) ); diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchWriter.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchWriter.cs index 0024ac9c..801a03b0 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchWriter.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlKeySwitchWriter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches.Translators; @@ -45,7 +46,7 @@ public void Dispose() Stream = null; } - public void Write( IReadOnlyCollection keySwitches, IObserver? loggingSubject = null ) + async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) { if( Stream == null ) { @@ -60,10 +61,10 @@ public void Write( IReadOnlyCollection keySwitches, IObserver } } - using var writer = new StreamWriter( Stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); + await using var writer = new StreamWriter( Stream, FileEncoding, IKeySwitchWriter.DefaultStreamWriterBufferSize, LeaveOpen ); var yamlText = new YamlKeySwitchExportTranslator().Translate( keySwitches ); - writer.WriteLine( yamlText ); + await writer.WriteLineAsync( yamlText.Value ); } } } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlRepository.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlRepository.cs index ec8297a8..4901de71 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlRepository.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage.Yaml/KeySwitches/YamlRepository.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reactive.Subjects; using System.Text; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Helpers; @@ -37,16 +38,16 @@ public YamlRepository(FilePath filePath) YamlModel = deserializer.Deserialize( yaml ); } - public void Dispose() + public async void Dispose() { - Flush(); + await FlushAsync(); } public int Count() => YamlModel.KeySwitches.Count; #region Save - public IKeySwitchRepository.SaveResult Save( KeySwitch keySwitch ) + public async Task SaveAsync( KeySwitch keySwitch ) { var yamlModels = YamlModel.KeySwitches; var model = TranslateModelHelper.Translate( keySwitch ); @@ -61,17 +62,17 @@ public IKeySwitchRepository.SaveResult Save( KeySwitch keySwitch ) model.Created = exist.Created; model.LastUpdated = UtcDateTime.NowAsDateTime; yamlModels[ index ] = model; - return new IKeySwitchRepository.SaveResult( 0, 1 ); + return await Task.FromResult( new IKeySwitchRepository.SaveResult( 0, 1 ) ); } yamlModels.Add( model ); - return new IKeySwitchRepository.SaveResult( 1, 0 ); + return await Task.FromResult( new IKeySwitchRepository.SaveResult( 1, 0 ) ); } - public int Flush() + public async Task FlushAsync() { - using var stream = YamlFilePath.OpenWriteStream(); - using var writer = new StreamWriter( stream, Encoding.UTF8 ); + await using var stream = YamlFilePath.OpenWriteStream(); + await using var writer = new StreamWriter( stream, Encoding.UTF8 ); var serializer = new Serializer(); serializer.Serialize( writer, YamlModel ); @@ -81,66 +82,66 @@ public int Flush() #endregion #region Delete - public int Delete( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) + public async Task DeleteAsync( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) { var keySwitches = YamlModel.KeySwitches; var founds = YamlModel.Find( developerName, productName, instrumentName ); - return founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ); + return await Task.FromResult( founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ) ); } - public int Delete( DeveloperName developerName, ProductName productName ) + public async Task DeleteAsync( DeveloperName developerName, ProductName productName ) { var keySwitches = YamlModel.KeySwitches; var founds = YamlModel.Find( developerName, productName ); - return founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ); + return await Task.FromResult( founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ) ); } - public int Delete( DeveloperName developerName ) + public async Task DeleteAsync( DeveloperName developerName ) { var keySwitches = YamlModel.KeySwitches; var founds = YamlModel.Find( developerName ); - return founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ); + return await Task.FromResult( founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ) ); } - public int Delete( ProductName productName ) + public async Task DeleteAsync( ProductName productName ) { var keySwitches = YamlModel.KeySwitches; var founds = YamlModel.Find( productName ); - return founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ); + return await Task.FromResult( founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ) ); } - public int Delete( InstrumentName instrumentName ) + public async Task DeleteAsync( InstrumentName instrumentName ) { var keySwitches = YamlModel.KeySwitches; var founds = YamlModel.Find( instrumentName ); - return founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ); + return await Task.FromResult( founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ) ); } - public int Delete( KeySwitchId keySwitchId ) + public async Task DeleteAsync( KeySwitchId keySwitchId ) { var keySwitches = YamlModel.KeySwitches; var founds = YamlModel.Find( keySwitchId ); - return founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ); + return await Task.FromResult( founds.Sum( x => keySwitches.Remove( x ) ? 1 : 0 ) ); } - public int DeleteAll() + public async Task DeleteAllAsync() { var count = YamlModel.KeySwitches.Count; YamlModel.KeySwitches.Clear(); - return count; + return await Task.FromResult( count ); } #endregion #region Find - private static IReadOnlyCollection Convert( IReadOnlyCollection source ) + private static async Task> ConvertAsync( IReadOnlyCollection source ) { var result = new List(); @@ -149,43 +150,43 @@ private static IReadOnlyCollection Convert( IReadOnlyCollection Find( KeySwitchId keySwitchId ) + public async Task> FindAsync( KeySwitchId keySwitchId ) { - return Convert( YamlModel.Find( keySwitchId ) ); + return await ConvertAsync( YamlModel.Find( keySwitchId ) ); } - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) + public async Task> FindAsync( DeveloperName developerName, ProductName productName, InstrumentName instrumentName ) { - return Convert( YamlModel.Find( developerName, productName, instrumentName ) ); + return await ConvertAsync( YamlModel.Find( developerName, productName, instrumentName ) ); } - public IReadOnlyCollection Find( DeveloperName developerName, ProductName productName ) + public async Task> FindAsync( DeveloperName developerName, ProductName productName ) { - return Convert( YamlModel.Find( developerName, productName ) ); + return await ConvertAsync( YamlModel.Find( developerName, productName ) ); } - public IReadOnlyCollection Find( DeveloperName developerName ) + public async Task> FindAsync( DeveloperName developerName ) { - return Convert( YamlModel.Find( developerName ) ); + return await ConvertAsync( YamlModel.Find( developerName ) ); } - public IReadOnlyCollection Find( ProductName productName ) + public async Task> FindAsync( ProductName productName ) { - return Convert( YamlModel.Find( productName ) ); + return await ConvertAsync( YamlModel.Find( productName ) ); } - public IReadOnlyCollection Find( InstrumentName instrumentName ) + public async Task> FindAsync( InstrumentName instrumentName ) { - return Convert( YamlModel.Find( instrumentName ) ); + return await ConvertAsync( YamlModel.Find( instrumentName ) ); } - public IReadOnlyCollection FindAll() + public async Task> FindAllAsync() { - return Convert( YamlModel.KeySwitches ); + return await ConvertAsync( YamlModel.KeySwitches ); } #endregion } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/CombinedWritingHelper.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/CombinedWritingHelper.cs index bfdf2b5d..496d88fd 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/CombinedWritingHelper.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/CombinedWritingHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -10,14 +11,17 @@ namespace KeySwitchManager.Infrastructures.Storage.KeySwitches.Helper public static class CombinedWritingHelper { public static void Write( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, KeySwitch prefix, string suffix, IObserver? loggingSubject, Func writerFactory ) + => WriteAsync( keySwitches, outputDirectory, prefix, suffix, loggingSubject, writerFactory ).GetAwaiter().GetResult(); + + public static async Task WriteAsync( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, KeySwitch prefix, string suffix, IObserver? loggingSubject, Func writerFactory ) { var filePath = CreatePathHelper.CreateFilePath( prefix.DeveloperName, prefix.ProductName, string.Empty, suffix, outputDirectory ); // Some writers require Read/Write access stream - using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); + await using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); using var fileWriter = writerFactory.Invoke( stream ); - fileWriter.Write( keySwitches, loggingSubject ); + await fileWriter.WriteAsync( keySwitches, loggingSubject ); loggingSubject?.OnNext( $"{nameof(CombinedWritingHelper)} : {keySwitches.Count} records has been written" ); } } diff --git a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/MultipleWritingHelper.cs b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/MultipleWritingHelper.cs index 6a777f6c..95659e1e 100644 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/MultipleWritingHelper.cs +++ b/KeySwitchManager/Sources/Runtime/Infrastructures/Storage/KeySwitches/Helper/MultipleWritingHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using KeySwitchManager.Commons.Data; using KeySwitchManager.Domain.KeySwitches.Models; @@ -10,22 +11,28 @@ namespace KeySwitchManager.Infrastructures.Storage.KeySwitches.Helper public static class MultipleWritingHelper { public static void Write( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, string suffix, IObserver? loggingSubject, Func writerFactory ) + => WriteAsync( keySwitches, outputDirectory, suffix, loggingSubject, writerFactory ).GetAwaiter().GetResult(); + + public static async Task WriteAsync( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, string suffix, IObserver? loggingSubject, Func writerFactory ) { foreach( var x in keySwitches ) { var filePath = CreatePathHelper.CreateFilePath( x, suffix, outputDirectory ); // Some writers require Read/Write access stream - using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); + await using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); using var fileWriter = writerFactory.Invoke( stream ); - fileWriter.Write( new[] { x }, loggingSubject ); + await fileWriter.WriteAsync( new[] { x }, loggingSubject ); } loggingSubject?.OnNext( $"{nameof(MultipleWritingHelper)} : {keySwitches.Count} records has been written" ); } - public static void Write( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, string suffix, IObserver? logging, Action?> write ) + public static void Write( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, string suffix, IObserver? logging, Func?, Task> write ) + => WriteAsync( keySwitches, outputDirectory, suffix, logging, write ).GetAwaiter().GetResult(); + + public static async Task WriteAsync( IReadOnlyCollection keySwitches, DirectoryPath outputDirectory, string suffix, IObserver? logging, Func?, Task> write ) { foreach( var x in keySwitches ) { @@ -34,7 +41,7 @@ public static void Write( IReadOnlyCollection keySwitches, DirectoryP var filePath = CreatePathHelper.CreateFilePath( x, suffix, outputDirectory ); // Some writers require Read/Write access stream - using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); + await using var stream = filePath.OpenStream( FileMode.Create, FileAccess.ReadWrite ); write.Invoke( stream, x, logging ); } diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/CreateFileInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/CreateFileInteractor.cs index 2f55e039..1000e33d 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/CreateFileInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/CreateFileInteractor.cs @@ -1,3 +1,5 @@ +using System.Threading.Tasks; + using KeySwitchManager.Domain.KeySwitches.Helpers; using KeySwitchManager.UseCase.KeySwitches.Create; @@ -15,10 +17,10 @@ public CreateFileInteractor( ICreateFilePresenter presenter ) Presenter = presenter; } - public CreateFileResponse Execute( CreateFileRequest request ) + async Task ICreateFileUseCase.ExecuteAsync( CreateFileRequest request ) { var keyswitch = KeySwitchFactoryHelper.CreateTemplate(); - request.Writer.Write( new[] { keyswitch } ); + await request.Writer.WriteAsync( new[] { keyswitch }, null ); return new CreateFileResponse(); } diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DeleteInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DeleteInteractor.cs index 26ec09be..ce1153a7 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DeleteInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DeleteInteractor.cs @@ -1,3 +1,5 @@ +using System.Threading.Tasks; + using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Domain.KeySwitches.Models.Values; using KeySwitchManager.UseCase.KeySwitches.Delete; @@ -23,7 +25,7 @@ public DeleteInteractor( Presenter = presenter; } - public DeleteResponse Execute( DeleteRequest request ) + async Task IDeleteUseCase.ExecuteAsync( DeleteRequest request ) { var developerName = request.DeveloperName; var productName = request.ProductName; @@ -35,7 +37,7 @@ public DeleteResponse Execute( DeleteRequest request ) if( !StringHelper.IsEmpty( developerName, productName, instrumentName ) ) { - removedCount = Repository.Delete( + removedCount = await Repository.DeleteAsync( new DeveloperName( developerName ), new ProductName( productName ), new InstrumentName( instrumentName ) @@ -43,7 +45,7 @@ public DeleteResponse Execute( DeleteRequest request ) } else if( !StringHelper.IsEmpty( developerName, productName ) ) { - removedCount = Repository.Delete( + removedCount = await Repository.DeleteAsync( new DeveloperName( developerName ), new ProductName( productName ) ); @@ -61,4 +63,4 @@ public DeleteResponse Execute( DeleteRequest request ) return new DeleteResponse( removedCount ); } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DumpFileInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DumpFileInteractor.cs index 1ebb863e..fa534060 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DumpFileInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/DumpFileInteractor.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.UseCase.KeySwitches.Dump; @@ -26,9 +27,9 @@ public DumpFileInteractor( Presenter = presenter; } - public DumpFileResponse Execute( DumpFileRequest request ) + async Task IDumpFileUseCase.ExecuteAsync( DumpFileRequest request ) { - var all = Repository.FindAll(); + var all = await Repository.FindAllAsync(); var sorted = all.OrderBy( x => x.DeveloperName.Value ) .ThenBy( x => x.ProductName.Value ) @@ -36,7 +37,7 @@ public DumpFileResponse Execute( DumpFileRequest request ) if( sorted.Count > 0 ) { - Writer.Write( sorted ); + await Writer.WriteAsync( sorted, null ); return new DumpFileResponse( sorted.Count ); } @@ -44,4 +45,4 @@ public DumpFileResponse Execute( DumpFileRequest request ) return new DumpFileResponse( 0 ); } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ExportFileInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ExportFileInteractor.cs index 4f63cc2b..228aee9a 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ExportFileInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ExportFileInteractor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Helpers; using KeySwitchManager.Domain.KeySwitches.Models; @@ -30,13 +31,13 @@ public ExportFileInteractor( Presenter = presenter; } - public ExportFileResponse Execute( ExportFileRequest request, IObserver? loggingSubject = null ) + async Task IExportFileUseCase.ExecuteAsync( ExportFileRequest request, IObserver? loggingSubject ) { var developerName = request.DeveloperName; var productName = request.ProductName; var instrumentName = request.InstrumentName; - var queryResult = SearchHelper.Search( + var queryResult = await SearchHelper.SearchAsync( Repository, developerName, productName, @@ -45,7 +46,7 @@ public ExportFileResponse Execute( ExportFileRequest request, IObserver? if( queryResult.Any() ) { - Writer.Write( queryResult, loggingSubject ); + await Writer.WriteAsync( queryResult, loggingSubject ); return new ExportFileResponse( queryResult ); } @@ -53,4 +54,4 @@ public ExportFileResponse Execute( ExportFileRequest request, IObserver? return new ExportFileResponse( new List() ); } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs index 1a961f45..90517638 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Domain.KeySwitches.Models.Values; @@ -26,7 +27,7 @@ public FindInteractor( Presenter = presenter; } - public FindResponse Execute( FindRequest request ) + async Task IFindUseCase.ExecuteAsync( FindRequest request ) { var developerName = request.DeveloperName; var productName = request.ProductName; @@ -35,7 +36,7 @@ public FindResponse Execute( FindRequest request ) #region By Developer, Product, Instrument if( !StringHelper.IsEmpty( developerName, productName, instrumentName ) ) { - var keySwitches = Repository.Find( + var keySwitches = await Repository.FindAsync( new DeveloperName( request.DeveloperName ), new ProductName( request.ProductName ), new InstrumentName( request.InstrumentName ) @@ -48,7 +49,7 @@ public FindResponse Execute( FindRequest request ) #region By Developer, Product if( !StringHelper.IsEmpty( developerName, productName ) ) { - var keySwitches = Repository.Find( + var keySwitches = await Repository.FindAsync( new DeveloperName( request.DeveloperName ), new ProductName( request.ProductName ) ); @@ -60,7 +61,7 @@ public FindResponse Execute( FindRequest request ) #region By Developer if( !StringHelper.IsEmpty( developerName ) ) { - var keySwitches = Repository.Find( + var keySwitches = await Repository.FindAsync( new DeveloperName( request.DeveloperName ) ); @@ -71,4 +72,4 @@ public FindResponse Execute( FindRequest request ) return new FindResponse( new List() ); } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ImportFileInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ImportFileInteractor.cs index 652f3866..2f045289 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ImportFileInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/ImportFileInteractor.cs @@ -1,3 +1,5 @@ +using System.Threading.Tasks; + using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.UseCase.KeySwitches.Import; @@ -21,14 +23,14 @@ public ImportFileInteractor( Presenter = presenter; } - public ImportFileResponse Execute( ImportFileRequest request ) + async Task IImportFileUseCase.ExecuteAsync( ImportFileRequest request ) { var insertedCount = 0; var updatedCount = 0; foreach( var i in request.KeySwitches ) { - var r = Repository.Save( i ); + var r = await Repository.SaveAsync( i ); updatedCount += r.Updated; insertedCount += r.Inserted; } @@ -39,4 +41,4 @@ public ImportFileResponse Execute( ImportFileRequest request ) } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/AddRequest.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/AddRequest.cs deleted file mode 100644 index 6541d505..00000000 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/AddRequest.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; - -using KeySwitchManager.Domain.MidiMessages.Models.Aggregations; - -namespace KeySwitchManager.UseCase.KeySwitches.Add -{ - public class AddRequest - { - public string Author { get; } - public string Description { get; } - public string DeveloperName { get; } - public string ProductName { get; } - public string InstrumentName { get; } - public string ArticulationName { get; } - public IReadOnlyCollection MidiNoteOns { get; } - public IReadOnlyCollection MidiControlChanges { get; } - public IReadOnlyCollection MidiProgramChanges { get; } - public IReadOnlyDictionary ExtraData { get; } - - public AddRequest( - string author, - string description, - string developerName, - string productName, - string instrumentName, - string articulationName, - IReadOnlyCollection midiNoteOns, - IReadOnlyCollection midiControlChanges, - IReadOnlyCollection midiProgramChanges, - IReadOnlyDictionary extraData ) - { - Author = author; - Description = description; - DeveloperName = developerName; - ProductName = productName; - InstrumentName = instrumentName; - ArticulationName = articulationName; - MidiNoteOns = midiNoteOns; - MidiControlChanges = midiControlChanges; - MidiProgramChanges = midiProgramChanges; - ExtraData = extraData; - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/AddingResponse.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/AddingResponse.cs deleted file mode 100644 index 6494e40d..00000000 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/AddingResponse.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace KeySwitchManager.UseCase.KeySwitches.Add -{ - public class AddingResponse - { - public bool Result { get; } - - public AddingResponse( bool result ) - { - Result = result; - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/IAddPresenter.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/IAddPresenter.cs deleted file mode 100644 index 9741057b..00000000 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/IAddPresenter.cs +++ /dev/null @@ -1,13 +0,0 @@ -using KeySwitchManager.UseCase.Commons; - -namespace KeySwitchManager.UseCase.KeySwitches.Add -{ - public interface IAddPresenter : IPresenter - { - public class Null : IAddPresenter - { - public void Complete( AddingResponse response ) - {} - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/IAddUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/IAddUseCase.cs deleted file mode 100644 index 62850bfd..00000000 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Add/IAddUseCase.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace KeySwitchManager.UseCase.KeySwitches.Add -{ - public interface IAddUseCase - { - public AddingResponse Execute( AddRequest request ); - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/ICreateFileUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/ICreateFileUseCase.cs index 7a09e2eb..dc15acdd 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/ICreateFileUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/ICreateFileUseCase.cs @@ -1,7 +1,12 @@ +using System.Threading.Tasks; + namespace KeySwitchManager.UseCase.KeySwitches.Create { public interface ICreateFileUseCase { - public CreateFileResponse Execute( CreateFileRequest request ); + public CreateFileResponse Execute( CreateFileRequest request ) + => ExecuteAsync( request ).GetAwaiter().GetResult(); + + public Task ExecuteAsync( CreateFileRequest request ); } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Delete/IDeleteUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Delete/IDeleteUseCase.cs index 6525e336..234b29c0 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Delete/IDeleteUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Delete/IDeleteUseCase.cs @@ -1,7 +1,12 @@ +using System.Threading.Tasks; + namespace KeySwitchManager.UseCase.KeySwitches.Delete { public interface IDeleteUseCase { - public DeleteResponse Execute( DeleteRequest request ); + public DeleteResponse Execute( DeleteRequest request ) + => ExecuteAsync( request ).GetAwaiter().GetResult(); + + public Task ExecuteAsync( DeleteRequest request ); } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Dump/IDumpFileUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Dump/IDumpFileUseCase.cs index ba871d4c..80740017 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Dump/IDumpFileUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Dump/IDumpFileUseCase.cs @@ -1,7 +1,12 @@ +using System.Threading.Tasks; + namespace KeySwitchManager.UseCase.KeySwitches.Dump { public interface IDumpFileUseCase { - public DumpFileResponse Execute( DumpFileRequest request ); + public DumpFileResponse Execute( DumpFileRequest request ) + => ExecuteAsync( request ).GetAwaiter().GetResult(); + + public Task ExecuteAsync( DumpFileRequest request ); } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/IExportFileUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/IExportFileUseCase.cs index af857303..cdf8bdd8 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/IExportFileUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Export/IExportFileUseCase.cs @@ -1,9 +1,13 @@ using System; +using System.Threading.Tasks; namespace KeySwitchManager.UseCase.KeySwitches.Export { public interface IExportFileUseCase { - public ExportFileResponse Execute( ExportFileRequest request, IObserver? loggingSubject = null ); + public ExportFileResponse Execute( ExportFileRequest request, IObserver? loggingSubject = null ) + => ExecuteAsync( request, loggingSubject ).GetAwaiter().GetResult(); + + public Task ExecuteAsync( ExportFileRequest request, IObserver? loggingSubject ); } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs index 9c873509..2d69d8ff 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs @@ -1,7 +1,12 @@ +using System.Threading.Tasks; + namespace KeySwitchManager.UseCase.KeySwitches.Find { public interface IFindUseCase { - public FindResponse Execute( FindRequest request ); + public FindResponse Execute( FindRequest request ) + => ExecuteAsync( request ).GetAwaiter().GetResult(); + + public Task ExecuteAsync( FindRequest request ); } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Import/IImportFileUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Import/IImportFileUseCase.cs index afef1b02..782a8ddd 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Import/IImportFileUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Import/IImportFileUseCase.cs @@ -1,7 +1,12 @@ +using System.Threading.Tasks; + namespace KeySwitchManager.UseCase.KeySwitches.Import { public interface IImportFileUseCase { - public ImportFileResponse Execute( ImportFileRequest request ); + public ImportFileResponse Execute( ImportFileRequest request ) + => ExecuteAsync( request ).GetAwaiter().GetResult(); + + public Task ExecuteAsync( ImportFileRequest request ); } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/Database.LiteDB.csproj b/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/Database.LiteDB.csproj deleted file mode 100644 index 1b7d1de7..00000000 --- a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/Database.LiteDB.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - 9 - net5.0 - KeySwitchManager.Testing.Database.LiteDB - enable - false - - - - - - - - - - - - - - diff --git a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbDeleteTest.cs b/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbDeleteTest.cs deleted file mode 100644 index dcac46e5..00000000 --- a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbDeleteTest.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.KeySwitches.Models; -using KeySwitchManager.Domain.KeySwitches.Models.Values; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches; -using KeySwitchManager.Testing.Commons.KeySwitches; - -using NUnit.Framework; - -namespace KeySwitchManager.Testing.Database.LiteDB.KeySwitches -{ - [TestFixture] - public class LiteDbDeleteTest - { - private static IKeySwitchRepository CreateRepository() - => new LiteDbRepository( new FilePath( $"{Path.GetTempFileName()}.db" ) ); - - [Test] - public void DeleteByIdTest() - { - using var repository = CreateRepository(); - var record = TestDataGenerator.CreateKeySwitch(); - - repository.Save( record ); - Assert.AreEqual( 1, repository.Count() ); - - repository.Delete( record.Id ); - Assert.AreEqual( 0, repository.Count() ); - - } - - [Test] - public void DeleteByDeveloperAndProduct() - { - using var repository = CreateRepository(); - var record = TestDataGenerator.CreateKeySwitch(); - - repository.Save( record ); - Assert.AreEqual( 1, repository.Count() ); - - repository.Delete( record.DeveloperName, record.ProductName ); - Assert.AreEqual( 0, repository.Count() ); - } - - [Test] - public void DeleteByWildcardTest() - { - using var repository = CreateRepository(); - - var saveRecord = TestDataGenerator.CreateKeySwitch(); - var deleteRecord = TestDataGenerator.CreateKeySwitch( - DeveloperName.Any.Value, - ProductName.Any.Value, - InstrumentName.Any.Value - ); - - repository.Save( saveRecord ); - Assert.AreEqual( 1, repository.Count() ); - - var deleted = repository.Delete( deleteRecord.DeveloperName, deleteRecord.ProductName ); - Assert.AreEqual( 1, deleted ); - Assert.AreEqual( 0, repository.Count() ); - - } - - [Test] - public void DeleteAllTest() - { - using var repository = CreateRepository(); - var record = new List - { - TestDataGenerator.CreateKeySwitch(), - TestDataGenerator.CreateKeySwitch() - }; - - repository.Save( record[ 0 ] ); - repository.Save( record[ 1 ] ); - Assert.AreEqual( record.Count, repository.Count() ); - - repository.DeleteAll(); - Assert.AreEqual( 0, repository.Count() ); - } - } -} \ No newline at end of file diff --git a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbInsertTest.cs b/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbInsertTest.cs deleted file mode 100644 index 6e2b9463..00000000 --- a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbInsertTest.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.MidiMessages.Models.Aggregations; -using KeySwitchManager.Domain.MidiMessages.Models.Values; -using KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches; -using KeySwitchManager.Testing.Commons.KeySwitches; - -using NUnit.Framework; - -namespace KeySwitchManager.Testing.Database.LiteDB.KeySwitches -{ - [TestFixture] - public class LiteDbInsertTest - { - [Test] - public void InsertTest() - { - using var repository = new LiteDbRepository( new FilePath( $"{Path.GetTempFileName()}.db" ) ); - var articulation = TestDataGenerator.CreateArticulation( - new List() - { - new MidiNoteOn( new MidiChannel( 0 ), new MidiNoteNumber( 1 ), new MidiVelocity( 100 ) ) - }, - new List(), - new List() - ); - var record = TestDataGenerator.CreateKeySwitch( articulation ); - - var result = repository.Save( record ); - Assert.AreEqual( 1, result.Inserted ); - - var seq = repository.Find( record.ProductName ); - var cmp = seq.First(); - Assert.AreEqual( record, cmp ); - - seq = repository.Find( record.DeveloperName ); - cmp = seq.First(); - Assert.AreEqual( record, cmp ); - - seq = repository.Find( record.ProductName ); - cmp = seq.First(); - Assert.AreEqual( record, cmp ); - - seq = repository.Find( record.DeveloperName, record.ProductName, record.InstrumentName ); - cmp = seq.First(); - Assert.AreEqual( record, cmp ); - - } - } -} \ No newline at end of file diff --git a/NOTICE.md b/NOTICE.md index 85201399..32d60b0c 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -73,36 +73,6 @@ SOFTWARE. ---- -### LiteDB - -https://github.com/mbdavid/LiteDB - -``` -The MIT License (MIT) - -Copyright (c) 2014-2020 Mauricio David - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` - ----- - ### YamlDotNet https://github.com/aaubry/YamlDotNet