From 442d31c4130eecf75d2e93d540d059336a20b46c Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-Koubou" Date: Sun, 22 Oct 2023 22:46:50 +0900 Subject: [PATCH] =?UTF-8?q?Obsolete=E3=82=92=E3=81=A4=E3=81=91=E3=81=A6?= =?UTF-8?q?=E5=89=8A=E9=99=A4=E4=BA=88=E5=AE=9A=E3=81=A0=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=EF=BC=88LiteDB=EF=BC=89=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KeySwitchManager/KeySwitchManager.sln | 14 - .../Applications/CLI/Sources/Commands/New.cs | 2 +- .../Core/Applications.Core.csproj | 1 - .../Create/CreateControllerFactory.cs | 6 - .../Helpers/KeySwitchRepositoryFactory.cs | 6 - .../WPF/Sources/MainWindow.xaml.cs | 4 +- .../Xamarin.Mac/Sources/ViewController.cs | 15 +- .../Database.LiteDB/Database.LiteDB.csproj | 24 -- .../KeySwitches/LiteDbFileWriter.cs | 37 --- .../KeySwitches/LiteDbRepository.cs | 276 ------------------ .../KeySwitches/Models/ArticulationModel.cs | 30 -- .../KeySwitches/Models/KeySwitchModel.cs | 52 ---- .../KeySwitches/Models/MidiMessageModel.cs | 23 -- .../Translators/KeySwitchExportTranslator.cs | 82 ------ .../Translators/KeySwitchImportTranslator.cs | 86 ------ .../Database.LiteDB/Database.LiteDB.csproj | 22 -- .../KeySwitches/LiteDbDeleteTest.cs | 86 ------ .../KeySwitches/LiteDbInsertTest.cs | 54 ---- NOTICE.md | 30 -- 19 files changed, 13 insertions(+), 837 deletions(-) delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/Database.LiteDB.csproj delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbFileWriter.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbRepository.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/ArticulationModel.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/KeySwitchModel.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Models/MidiMessageModel.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchExportTranslator.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/Translators/KeySwitchImportTranslator.cs delete mode 100644 KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/Database.LiteDB.csproj delete mode 100644 KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbDeleteTest.cs delete mode 100644 KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbInsertTest.cs 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/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/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/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/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/Sources/MainWindow.xaml.cs b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml.cs index 3dc8fc9f..cae5dab7 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/Sources/MainWindow.xaml.cs @@ -27,8 +27,8 @@ namespace KeySwitchManager.Applications.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 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/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 62e44991..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbFileWriter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.KeySwitches.Models; - -using RkHelper.System; - -namespace KeySwitchManager.Infrastructures.Database.LiteDB.KeySwitches -{ - public class LiteDbFileWriter : IKeySwitchWriter - { - private IKeySwitchRepository Repository { get; } - - public bool LeaveOpen => false; - - public LiteDbFileWriter( FilePath dbFilePath ) - { - Repository = new LiteDbRepository( dbFilePath ); - } - - public void Dispose() - { - Disposer.Dispose( Repository ); - } - - async Task IKeySwitchWriter.WriteAsync( IReadOnlyCollection keySwitches, IObserver? loggingSubject ) - { - foreach( var x in keySwitches ) - { - loggingSubject?.OnNext( x.ToString() ); - await Repository.SaveAsync( 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 2e91de52..00000000 --- a/KeySwitchManager/Sources/Runtime/Infrastructures/Database.LiteDB/KeySwitches/LiteDbRepository.cs +++ /dev/null @@ -1,276 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reactive.Subjects; -using System.Threading.Tasks; - -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 async Task SaveAsync( 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 await Task.FromResult( new IKeySwitchRepository.SaveResult( - inserted: 0, - updated: updated - )); - } - - entity.Id = keySwitch.Id.Value; - - var insertedId = table.Insert( entity ).AsGuid; - return await Task.FromResult( new IKeySwitchRepository.SaveResult( - inserted: insertedId == entity.Id ? 1 : 0, - updated: 0 - )); - } - - #endregion - - #region Delete - public async Task DeleteAsync( KeySwitchId keySwitchId ) - { - var result = KeySwitchTable.Delete( keySwitchId.Value ); - return await Task.FromResult( result ? 1 : 0 ); - } - - public async Task DeleteAsync( - DeveloperName developerName, - ProductName productName, - InstrumentName instrumentName ) - { - var d = developerName.Value; - var p = productName.Value; - var i = instrumentName.Value; - - return await Task.FromResult( 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 async Task DeleteAsync( DeveloperName developerName, ProductName productName ) - { - var d = developerName.Value; - var p = productName.Value; - - return await Task.FromResult( KeySwitchTable.DeleteMany( - x => - ( d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) ) && - ( p == ProductName.Any.Value || x.ProductName.Contains( p ) ) - )); - } - - public async Task DeleteAsync( DeveloperName developerName ) - { - var d = developerName.Value; - - return await Task.FromResult( KeySwitchTable.DeleteMany( - x => - d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) - )); - } - - public async Task DeleteAsync( ProductName productName ) - { - var p = productName.Value; - - return await Task.FromResult( KeySwitchTable.DeleteMany( - x => - p == ProductName.Any.Value || x.ProductName.Contains( p ) - )); - } - - public async Task DeleteAsync( InstrumentName instrumentName ) - { - var i = instrumentName.Value; - - return await Task.FromResult( KeySwitchTable.DeleteMany( - x => - i == InstrumentName.Any.Value || x.InstrumentName.Contains( i ) - )); - } - - public async Task DeleteAllAsync() - { - var table = Database.GetCollection( KeySwitchesTableName ); - return await Task.FromResult( 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 async Task> FindAsync( KeySwitchId keySwitchId ) - { - return await Task.FromResult( CreateEntities( KeySwitchTable.Find( x => x.Id == keySwitchId.Value ) ) ); - } - - public async Task> FindAsync( - DeveloperName developerName, - ProductName productName, - InstrumentName instrumentName ) - { - var d = developerName.Value; - var p = productName.Value; - var i = instrumentName.Value; - - return await Task.FromResult( 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 async Task> FindAsync( DeveloperName developerName, ProductName productName ) - { - var d = developerName.Value; - var p = productName.Value; - - return await Task.FromResult( CreateEntities( - KeySwitchTable.Find( - x => - ( d == DeveloperName.Any.Value || x.DeveloperName.Contains( d ) ) && - ( p == ProductName.Any.Value || x.ProductName.Contains( p ) ) - ) - )); - } - - public async Task> FindAsync( DeveloperName developerName ) - { - var d = developerName.Value; - - if( d == DeveloperName.Any.Value ) - { - return await FindAllAsync(); - } - - return await Task.FromResult( CreateEntities( - KeySwitchTable.Find( - x => - x.DeveloperName.Contains( d ) - ) - )); - } - - public async Task> FindAsync( ProductName productName ) - { - var p = productName.Value; - - if( p == ProductName.Any.Value ) - { - return await FindAllAsync(); - } - - return await Task.FromResult( CreateEntities( - KeySwitchTable.Find( - x => - x.ProductName.Contains( p ) - ) - )); - } - - public async Task> FindAsync( InstrumentName instrumentName ) - { - var i = instrumentName.Value; - - return await Task.FromResult( CreateEntities( - KeySwitchTable.Find( - x => - i == InstrumentName.Any.Value || x.InstrumentName.Contains( i ) - ) - )); - } - - public async Task> FindAllAsync() - { - return await Task.FromResult( CreateEntities( KeySwitchTable.FindAll() ) ); - } - #endregion - } -} 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/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 582de424..00000000 --- a/KeySwitchManager/Sources/Tests/Infrastructures/Database.LiteDB/KeySwitches/LiteDbInsertTest.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using KeySwitchManager.Commons.Data; -using KeySwitchManager.Domain.KeySwitches.Models; -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 IKeySwitchRepository 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 ); - - } - } -} 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