From b1c0ee326b00e0b831186762d99155539585350f Mon Sep 17 00:00:00 2001 From: "Hiroaki@R-koubou" Date: Tue, 28 Nov 2023 21:39:57 +0900 Subject: [PATCH] =?UTF-8?q?Boundary=E3=83=BBIn/OutputData=E3=81=BE?= =?UTF-8?q?=E3=82=8F=E3=82=8A=E3=81=AE=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KeySwitchManager/KeySwitchManager.sln | 7 -- .../Blazor/Pages/CreateDatabaseFile.razor | 10 +-- .../Applications/Blazor/Pages/FetchData.razor | 1 - .../Runtime/Applications/Blazor/Program.cs | 5 +- .../Runtime/Applications/CLI/.gitignore | 2 +- .../Applications/CLI/Sources/Commands/New.cs | 4 +- .../Create/CreateFileController.cs | 7 +- .../Create/CreateFileControllerFactory.cs | 7 +- .../Controllers/Create/CreatePresenter.cs | 37 ---------- .../Create/CreateToStreamControllerFactory.cs | 4 +- .../Presenters/CreatePresenter.cs | 48 +++++++++++++ .../Views/LogView/ILogTextView.cs | 25 +++---- .../Runtime/Applications/WPF/.gitignore | 2 +- .../Applications/Xamarin.Mac/.gitignore | 2 +- .../.idea/workspace.xml | 67 ++++++++++++++++--- .../Applications.Xamarin.Mac.csproj | 6 +- .../Xamarin.Mac/Sources/ViewController.cs | 8 ++- .../Runtime/Boundaries/Boundaries.csproj | 15 ----- .../Sources/Runtime/Boundaries/IInputPort.cs | 13 ---- .../Sources/Runtime/Boundaries/IOutputPort.cs | 22 ------ .../Models/Factory/IKeySwitchFactory.cs | 2 - .../OnMemoryKeySwitchRepository.cs | 1 - .../SpreadsheetImportTranslator.cs | 3 - .../KeySwitches/YamlMemoryRepository.cs | 1 - .../KeySwitches/FileExportContentWriter.cs | 1 - .../KeySwitches/ZipExportContentWriter.cs | 1 - .../KeySwitches/CreateInteractor.cs | 17 +++-- .../Runtime/UseCases/Commons/IInputData.cs | 14 ++++ .../Runtime/UseCases/Commons/IInputPort.cs | 13 ++++ .../Commons/{IResponse.cs => IOutputData.cs} | 8 +-- .../Runtime/UseCases/Commons/IOutputPort.cs | 13 ++++ .../Runtime/UseCases/Commons/IRequest.cs | 14 ---- .../KeySwitches/Create/CreateInputData.cs | 15 +++++ ...{CreateResponse.cs => CreateOutputData.cs} | 8 +-- .../KeySwitches/Create/CreateRequest.cs | 15 ----- .../KeySwitches/Create/ICreatePresenter.cs | 40 ----------- .../KeySwitches/Create/ICreateUseCase.cs | 4 +- .../Sources/Runtime/UseCases/UseCases.csproj | 1 - 38 files changed, 215 insertions(+), 248 deletions(-) delete mode 100644 KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreatePresenter.cs create mode 100644 KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/CreatePresenter.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Boundaries/Boundaries.csproj delete mode 100644 KeySwitchManager/Sources/Runtime/Boundaries/IInputPort.cs delete mode 100644 KeySwitchManager/Sources/Runtime/Boundaries/IOutputPort.cs create mode 100644 KeySwitchManager/Sources/Runtime/UseCases/Commons/IInputData.cs create mode 100644 KeySwitchManager/Sources/Runtime/UseCases/Commons/IInputPort.cs rename KeySwitchManager/Sources/Runtime/UseCases/Commons/{IResponse.cs => IOutputData.cs} (59%) create mode 100644 KeySwitchManager/Sources/Runtime/UseCases/Commons/IOutputPort.cs delete mode 100644 KeySwitchManager/Sources/Runtime/UseCases/Commons/IRequest.cs create mode 100644 KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/CreateInputData.cs rename KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/{CreateResponse.cs => CreateOutputData.cs} (60%) delete mode 100644 KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/CreateRequest.cs delete mode 100644 KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Create/ICreatePresenter.cs diff --git a/KeySwitchManager/KeySwitchManager.sln b/KeySwitchManager/KeySwitchManager.sln index 7c35c43f..ba3eb1ec 100644 --- a/KeySwitchManager/KeySwitchManager.sln +++ b/KeySwitchManager/KeySwitchManager.sln @@ -60,8 +60,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Plist", "Sources\Ru EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage.Plist", "Sources\Tests\Infrastructures\Storage.Plist\Storage.Plist.csproj", "{33ED6810-D26B-419D-9A8E-C5F293E1431E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boundaries", "Sources\Runtime\Boundaries\Boundaries.csproj", "{24F4F144-4C43-4B0D-A6E5-90A17B4140BC}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -156,10 +154,6 @@ Global {33ED6810-D26B-419D-9A8E-C5F293E1431E}.Debug|Any CPU.Build.0 = Debug|Any CPU {33ED6810-D26B-419D-9A8E-C5F293E1431E}.Release|Any CPU.ActiveCfg = Release|Any CPU {33ED6810-D26B-419D-9A8E-C5F293E1431E}.Release|Any CPU.Build.0 = Release|Any CPU - {24F4F144-4C43-4B0D-A6E5-90A17B4140BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {24F4F144-4C43-4B0D-A6E5-90A17B4140BC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {24F4F144-4C43-4B0D-A6E5-90A17B4140BC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {24F4F144-4C43-4B0D-A6E5-90A17B4140BC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {EAE5D07E-8455-4C33-BCD1-07EFF958E21B} = {505E86DD-3A59-4038-B109-22B3678D035E} @@ -190,6 +184,5 @@ Global {634AFB40-DAF4-4A06-8C2C-95880D514C28} = {929A1972-7C22-4700-A758-E99DF592BEBF} {5F236D80-0102-44F7-904D-26A5A910C6C0} = {505E86DD-3A59-4038-B109-22B3678D035E} {33ED6810-D26B-419D-9A8E-C5F293E1431E} = {B1FC3859-B078-471F-81F2-FBB0A25C974B} - {24F4F144-4C43-4B0D-A6E5-90A17B4140BC} = {4F7FDAC2-788F-437D-8498-7EA665B4B1CA} EndGlobalSection EndGlobal diff --git a/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/CreateDatabaseFile.razor b/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/CreateDatabaseFile.razor index 59093301..00e6637b 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/CreateDatabaseFile.razor +++ b/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/CreateDatabaseFile.razor @@ -1,10 +1,10 @@ @page "/create_db" - -@inject FileDownloadService DownloadService -@using KeySwitchManager.Applications.Blazor.Services -@using KeySwitchManager.Applications.Standalone.Core.Controllers.Create @using KeySwitchManager.Applications.Standalone.Core.Controllers.Export @using KeySwitchManager.Applications.Standalone.Core.Views.LogView +@using KeySwitchManager.Applications.Blazor.Services +@using KeySwitchManager.Applications.Standalone.Core.Controllers.Create + +@inject FileDownloadService DownloadService Create Database File @@ -43,7 +43,7 @@ var target = new MemoryStream(); var factory = new CreateToStreamControllerFactory(); - var controller = factory.Create( target, Format, new ILogTextView.Null() ); + var controller = factory.Create( target, Format, ILogTextView.Null ); var outputFileName = Format switch { diff --git a/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/FetchData.razor b/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/FetchData.razor index 1d5ba24d..e76841b9 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/FetchData.razor +++ b/KeySwitchManager/Sources/Runtime/Applications/Blazor/Pages/FetchData.razor @@ -1,6 +1,5 @@ @page "/fetchdata" @inject HttpClient Http -@using KeySwitchManager.Applications.Blazor.Shared Weather forecast diff --git a/KeySwitchManager/Sources/Runtime/Applications/Blazor/Program.cs b/KeySwitchManager/Sources/Runtime/Applications/Blazor/Program.cs index a4b8ccae..6121d60c 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Blazor/Program.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Blazor/Program.cs @@ -1,8 +1,9 @@ -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using KeySwitchManager.Applications.Blazor; using KeySwitchManager.Applications.Blazor.Services; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; + using MudBlazor.Services; var builder = WebAssemblyHostBuilder.CreateDefault(args); diff --git a/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore b/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore index 0174d1d7..6f9a303a 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore +++ b/KeySwitchManager/Sources/Runtime/Applications/CLI/.gitignore @@ -1,2 +1,2 @@ # Automatically generated during the build and publish process -./VERSION.md +/VERSION.md diff --git a/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs b/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs index 738e5a67..d763cdc0 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/CLI/Sources/Commands/New.cs @@ -1,8 +1,8 @@ using CommandLine; using KeySwitchManager.Applications.Standalone.Core.Controllers.Create; +using KeySwitchManager.Applications.Standalone.Core.Presenters; using KeySwitchManager.Applications.Standalone.Core.Views.LogView; -using KeySwitchManager.UseCase.KeySwitches.Create; namespace KeySwitchManager.Applications.CLI.Commands { @@ -22,7 +22,7 @@ public int Execute( ICommandOption opt ) ICreateControllerFactory factory = new CreateFileControllerFactory(); - using var controller = factory.Create( option.OutputPath, ICreatePresenter.DefaultConsole ); + using var controller = factory.Create( option.OutputPath, new CreatePresenter( new ConsoleLogView() ) ); logView.Append( $"generating keyswitch template to {option.OutputPath}" ); controller.Execute(); diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileController.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileController.cs index f1273f4a..53ef7103 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileController.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using KeySwitchManager.Interactors.KeySwitches; +using KeySwitchManager.UseCase.Commons; using KeySwitchManager.UseCase.KeySwitches.Create; using KeySwitchManager.UseCase.KeySwitches.Export; @@ -10,11 +11,11 @@ namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Create public class CreateFileController : IController { private IExportStrategy Strategy { get; } - private ICreatePresenter Presenter { get; } + private IOutputPort Presenter { get; } public CreateFileController( IExportStrategy strategy, - ICreatePresenter presenter ) + IOutputPort presenter ) { Strategy = strategy; Presenter = presenter; @@ -25,7 +26,7 @@ public void Dispose() {} public async Task ExecuteAsync( CancellationToken cancellationToken ) { ICreateUseCase interactor = new CreateInteractor( Presenter ); - var request = new CreateRequest( Strategy ); + var request = new CreateInputData( Strategy ); await interactor.HandleAsync( request, cancellationToken ); } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileControllerFactory.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileControllerFactory.cs index 9bad3347..78a394c7 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileControllerFactory.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateFileControllerFactory.cs @@ -5,6 +5,7 @@ using KeySwitchManager.Infrastructures.Storage.KeySwitches; using KeySwitchManager.Infrastructures.Storage.Spreadsheet.ClosedXml.KeySwitches.Export; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches.Export; +using KeySwitchManager.UseCase.Commons; using KeySwitchManager.UseCase.KeySwitches.Create; using KeySwitchManager.UseCase.KeySwitches.Export; @@ -12,12 +13,12 @@ namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Create { public interface ICreateControllerFactory { - IController Create( string outputFilePath, ICreatePresenter logTextView ); + IController Create( string outputFilePath, IOutputPort presenter ); } public class CreateFileControllerFactory : ICreateControllerFactory { - IController ICreateControllerFactory.Create( string outputFilePath, ICreatePresenter logTextView ) + IController ICreateControllerFactory.Create( string outputFilePath, IOutputPort presenter ) { var outputDirectory = new DirectoryPath( Path.GetDirectoryName( outputFilePath ) ?? string.Empty ); var fileName = outputFilePath.ToLower(); @@ -43,7 +44,7 @@ IController ICreateControllerFactory.Create( string outputFilePath, ICreatePrese throw new ArgumentException( $"{outputFilePath} is unknown file format" ); } - return new CreateFileController( strategy, logTextView ); + return new CreateFileController( strategy, presenter ); } } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreatePresenter.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreatePresenter.cs deleted file mode 100644 index 181d5835..00000000 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreatePresenter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -using KeySwitchManager.Applications.Standalone.Core.Views.LogView; -using KeySwitchManager.UseCase.KeySwitches.Create; - -namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Create -{ - public class CreatePresenter : ICreatePresenter - { - private ILogTextView TextView { get; } - - public CreatePresenter( ILogTextView textView ) - { - TextView = textView; - } - - public async Task HandleAsync( CreateResponse response, CancellationToken cancellationToken = default ) - { - if( response.Result ) - { - TextView.Append( $"Created : {response.Response}" ); - } - else - { - TextView.Append( "Failed to create." ); - - if( response.Error?.StackTrace != null ) - { - TextView.Append( response.Error.StackTrace ); - } - } - - await Task.CompletedTask; - } - } -} diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateToStreamControllerFactory.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateToStreamControllerFactory.cs index b47ab6fd..b001a79a 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateToStreamControllerFactory.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Create/CreateToStreamControllerFactory.cs @@ -2,11 +2,11 @@ using System.IO; using KeySwitchManager.Applications.Standalone.Core.Controllers.Export; +using KeySwitchManager.Applications.Standalone.Core.Presenters; using KeySwitchManager.Applications.Standalone.Core.Views.LogView; using KeySwitchManager.Infrastructures.Storage.KeySwitches; using KeySwitchManager.Infrastructures.Storage.Spreadsheet.ClosedXml.KeySwitches.Export; using KeySwitchManager.Infrastructures.Storage.Yaml.KeySwitches.Export; -using KeySwitchManager.UseCase.KeySwitches.Create; using KeySwitchManager.UseCase.KeySwitches.Export; namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Create @@ -33,7 +33,7 @@ public IController Create( Stream targetStream, ExportSupportedFormat format, IL throw new ArgumentOutOfRangeException( nameof( format ), format, null ); } - return new CreateFileController( strategy, ICreatePresenter.Null ); + return new CreateFileController( strategy, CreatePresenter.Null ); } } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/CreatePresenter.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/CreatePresenter.cs new file mode 100644 index 00000000..0bfc8e08 --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/CreatePresenter.cs @@ -0,0 +1,48 @@ +using System.Threading; +using System.Threading.Tasks; + +using KeySwitchManager.Applications.Standalone.Core.Views.LogView; +using KeySwitchManager.UseCase.Commons; +using KeySwitchManager.UseCase.KeySwitches.Create; + +namespace KeySwitchManager.Applications.Standalone.Core.Presenters +{ + public sealed class CreatePresenter : IOutputPort + { + public static readonly IOutputPort Null = new NullImpl(); + + private ILogTextView TextView { get; } + + public CreatePresenter( ILogTextView textView ) + { + TextView = textView; + } + + public async Task HandleAsync( CreateOutputData outputData, CancellationToken cancellationToken = default ) + { + if( outputData.Result ) + { + TextView.Append( $"Created : {outputData.Value}" ); + } + else + { + TextView.Append( "Failed to create." ); + + if( outputData.Error?.StackTrace != null ) + { + TextView.Append( outputData.Error.StackTrace ); + } + } + + await Task.CompletedTask; + } + + private class NullImpl : IOutputPort + { + public async Task HandleAsync( CreateOutputData outputData, CancellationToken cancellationToken = default ) + { + await Task.CompletedTask; + } + } + } +} diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Views/LogView/ILogTextView.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Views/LogView/ILogTextView.cs index ba18646c..b1d4922c 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Views/LogView/ILogTextView.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Views/LogView/ILogTextView.cs @@ -4,7 +4,9 @@ namespace KeySwitchManager.Applications.Standalone.Core.Views.LogView { public interface ILogTextView { - public bool AutoScroll { get; set; } + static readonly ILogTextView Null = new NullImpl(); + + bool AutoScroll { get; set; } void Append( string text ); void AppendError( string text ); @@ -12,24 +14,15 @@ public interface ILogTextView void Clear(); void ScrollToEnd(); - public class Null : ILogTextView + private class NullImpl : ILogTextView { public bool AutoScroll { get; set; } - public void Append( string text ) - {} - - public void AppendError( string text ) - {} - - public void AppendError( Exception exception ) - {} - - public void Clear() - {} - - public void ScrollToEnd() - {} + public void Append( string text ) {} + public void AppendError( string text ) {} + public void AppendError( Exception exception ) {} + public void Clear() {} + public void ScrollToEnd() {} } } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore b/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore index 0174d1d7..6f9a303a 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore +++ b/KeySwitchManager/Sources/Runtime/Applications/WPF/.gitignore @@ -1,2 +1,2 @@ # Automatically generated during the build and publish process -./VERSION.md +/VERSION.md diff --git a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore index 0174d1d7..6f9a303a 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore +++ b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.gitignore @@ -1,2 +1,2 @@ # Automatically generated during the build and publish process -./VERSION.md +/VERSION.md diff --git a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.idea/.idea.Applications.Xamarin.Mac/.idea/workspace.xml b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.idea/.idea.Applications.Xamarin.Mac/.idea/workspace.xml index 31d12bee..ded27880 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.idea/.idea.Applications.Xamarin.Mac/.idea/workspace.xml +++ b/KeySwitchManager/Sources/Runtime/Applications/Xamarin.Mac/.idea/.idea.Applications.Xamarin.Mac/.idea/workspace.xml @@ -8,10 +8,43 @@ - + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + +