Skip to content

Commit

Permalink
Merge pull request #65 from r-koubou/refactor/usecase_create
Browse files Browse the repository at this point in the history
Refactor/usecase create
  • Loading branch information
r-koubou authored Nov 28, 2023
2 parents 595cc2f + 312674a commit 2d2f056
Show file tree
Hide file tree
Showing 36 changed files with 298 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -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

<PageTitle>Create Database File</PageTitle>

Expand Down Expand Up @@ -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
{
Expand All @@ -67,7 +67,7 @@
StateHasChanged();
});
}
catch( OperationCanceledException ce ) {}
catch( OperationCanceledException ) {}
catch( Exception e )
{
Console.WriteLine( e );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@page "/fetchdata"
@inject HttpClient Http
@using KeySwitchManager.Applications.Blazor.Shared

<PageTitle>Weather forecast</PageTitle>

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Automatically generated during the build and publish process
./VERSION.md
/VERSION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommandLine;

using KeySwitchManager.Applications.Standalone.Core.Controllers.Create;
using KeySwitchManager.Applications.Standalone.Core.Presenters;
using KeySwitchManager.Applications.Standalone.Core.Views.LogView;

namespace KeySwitchManager.Applications.CLI.Commands
Expand All @@ -21,7 +22,7 @@ public int Execute( ICommandOption opt )

ICreateControllerFactory factory = new CreateFileControllerFactory();

using var controller = factory.Create( option.OutputPath, logView );
using var controller = factory.Create( option.OutputPath, new CreatePresenter( new ConsoleLogView() ) );
logView.Append( $"generating keyswitch template to {option.OutputPath}" );
controller.Execute();

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

Expand All @@ -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<CreateOutputData> Presenter { get; }

public CreateFileController(
IExportStrategy strategy,
ICreatePresenter presenter )
IOutputPort<CreateOutputData> presenter )
{
Strategy = strategy;
Presenter = presenter;
Expand All @@ -24,9 +25,9 @@ public void Dispose() {}

public async Task ExecuteAsync( CancellationToken cancellationToken )
{
ICreateUseCase interactor = new CreateInteractor( Strategy, Presenter );
var response = await interactor.ExecuteAsync( cancellationToken );
Presenter.Complete( response );
ICreateUseCase interactor = new CreateInteractor( Presenter );
var request = new CreateInputData( Strategy );
await interactor.HandleAsync( request, cancellationToken );
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using System;
using System.IO;

using KeySwitchManager.Applications.Standalone.Core.Views.LogView;
using KeySwitchManager.Commons.Data;
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;

namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Create
{
public interface ICreateControllerFactory
{
IController Create( string outputFilePath, ILogTextView logTextView );
IController Create( string outputFilePath, IOutputPort<CreateOutputData> presenter );
}

public class CreateFileControllerFactory : ICreateControllerFactory
{
IController ICreateControllerFactory.Create( string outputFilePath, ILogTextView logTextView )
IController ICreateControllerFactory.Create( string outputFilePath, IOutputPort<CreateOutputData> presenter )
{
var outputDirectory = new DirectoryPath( Path.GetDirectoryName( outputFilePath ) ?? string.Empty );
var fileName = outputFilePath.ToLower();
Expand All @@ -43,7 +44,7 @@ IController ICreateControllerFactory.Create( string outputFilePath, ILogTextView
throw new ArgumentException( $"{outputFilePath} is unknown file format" );
}

return new CreateFileController( strategy, new CreatePresenter( logTextView ) );
return new CreateFileController( strategy, presenter );
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +33,7 @@ public IController Create( Stream targetStream, ExportSupportedFormat format, IL
throw new ArgumentOutOfRangeException( nameof( format ), format, null );
}

return new CreateFileController( strategy, new ICreatePresenter.Null() );
return new CreateFileController( strategy, CreatePresenter.Null );
}
}
}
Original file line number Diff line number Diff line change
@@ -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<CreateOutputData>
{
public static readonly IOutputPort<CreateOutputData> 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<CreateOutputData>
{
public async Task HandleAsync( CreateOutputData outputData, CancellationToken cancellationToken = default )
{
await Task.CompletedTask;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@ 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 );
void AppendError( Exception exception );
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() {}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Automatically generated during the build and publish process
./VERSION.md
/VERSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
using KeySwitchManager.Applications.Standalone.Core.Controllers.Export;
using KeySwitchManager.Applications.Standalone.Core.Controllers.Find;
using KeySwitchManager.Applications.Standalone.Core.Controllers.Import;
using KeySwitchManager.Applications.Standalone.Core.Presenters;
using KeySwitchManager.Applications.WPF.WpfView;

using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;

using RkHelper.Enumeration;
using RkHelper.Text;
using RkHelper.Primitives;

namespace KeySwitchManager.Applications.WPF
{
Expand Down Expand Up @@ -186,8 +187,9 @@ private async void OnDoCreateNewDefinitionButtonClicked( object sender, RoutedEv
}

ICreateControllerFactory factory = new CreateFileControllerFactory();
var presenter = new CreatePresenter( LogTextView );

await ExecuteControllerAsync( () => factory.Create( path, LogTextView ) );
await ExecuteControllerAsync( () => factory.Create( path, presenter ) );
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Automatically generated during the build and publish process
./VERSION.md
/VERSION.md
Loading

0 comments on commit 2d2f056

Please sign in to comment.