Skip to content

Commit

Permalink
Merge pull request #69 from r-koubou/refactor/usecase_export
Browse files Browse the repository at this point in the history
Refactor/usecase export
  • Loading branch information
r-koubou authored Nov 29, 2023
2 parents e9e4aef + 94c6b4d commit 542d098
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public int Execute( ICommandOption opt )
var option = (CommandOption)opt;
var logView = new ConsoleLogView();

ICreateControllerFactory factory = new CreateFileControllerFactory();
ICreateFileControllerFactory factory = new CreateFileControllerFactory();

using var controller = factory.Create( option.OutputPath, new CreatePresenter( new ConsoleLogView() ) );
logView.Append( $"generating keyswitch template to {option.OutputPath}" );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;

using KeySwitchManager.Commons.Data;
using KeySwitchManager.Infrastructures.Storage.KeySwitches;
Expand All @@ -10,16 +9,15 @@

namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Create
{
public interface ICreateControllerFactory
public interface ICreateFileControllerFactory
{
IController Create( string outputFilePath, ICreatePresenter presenter );
}

public class CreateFileControllerFactory : ICreateControllerFactory
public class CreateFileControllerFactory : ICreateFileControllerFactory
{
IController ICreateControllerFactory.Create( string outputFilePath, ICreatePresenter presenter )
IController ICreateFileControllerFactory.Create( string outputFilePath, ICreatePresenter presenter )
{
var outputDirectory = new DirectoryPath( Path.GetDirectoryName( outputFilePath ) ?? string.Empty );
var fileName = outputFilePath.ToLower();

IExportContentFactory contentFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Reactive.Subjects;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;

using KeySwitchManager.Domain.KeySwitches;
Expand All @@ -12,62 +10,51 @@

namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Export
{
public class ExportFileController : IController
public class ExportController : IController
{
private IKeySwitchRepository SourceRepository { get; }
private IExportStrategy Strategy { get; }
private DeveloperName DeveloperName { get; }
private ProductName ProductName { get; }
private InstrumentName InstrumentName { get; }
private IExportFilePresenter Presenter { get; }
private readonly Subject<string> logging = new();
private IExportPresenter Presenter { get; }

public ExportFileController(
public ExportController(
DeveloperName developerName,
ProductName productName,
InstrumentName instrumentName,
IKeySwitchRepository sourceRepository,
IExportStrategy strategy,
IExportFilePresenter presenter )
IExportPresenter presenter )
{
DeveloperName = developerName;
ProductName = productName;
InstrumentName = instrumentName;
SourceRepository = sourceRepository;
Strategy = strategy;
Presenter = presenter;

logging.Subscribe(
onNext: presenter.Present,
onError: presenter.Present
);

}

public void Dispose()
{
Disposer.Dispose( logging );
Disposer.Dispose( SourceRepository );
}

public async Task ExecuteAsync( CancellationToken cancellationToken )
{
IExportFileUseCase interactor = new ExportFileInteractor(
IExportFileUseCase interactor = new ExportInteractor(
SourceRepository,
Strategy,
Presenter
);

var response = await interactor.ExecuteAsync(
new ExportFileRequest(
DeveloperName.Value,
ProductName.Value,
InstrumentName.Value
),
cancellationToken
var inputValue = new ExportInputValue(
DeveloperName.Value,
ProductName.Value,
InstrumentName.Value
);

Presenter.Complete( response );
await interactor.HandleAsync( new ExportInputData( inputValue ), cancellationToken );
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;

using KeySwitchManager.Applications.Standalone.Core.Helpers;
using KeySwitchManager.Applications.Standalone.Core.Presenters;
using KeySwitchManager.Applications.Standalone.Core.Views.LogView;
using KeySwitchManager.Commons.Data;
using KeySwitchManager.Domain.KeySwitches.Models.Values;
Expand Down Expand Up @@ -44,7 +45,7 @@ public IController Create(
try
{
IController CreateImpl( IExportStrategy strategy )
=> new ExportFileController( developer, product, instrument, sourceDatabase, strategy, new ExportFilePresenter( logTextView ) );
=> new ExportController( developer, product, instrument, sourceDatabase, strategy, new ExportPresenter( logTextView ) );

IExportContentFactory contentFactory;
IExportContentWriterFactory contentWriterFactory;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using KeySwitchManager.Applications.Standalone.Core.Views.LogView;
using KeySwitchManager.Domain.KeySwitches.Models;
using KeySwitchManager.UseCase.KeySwitches.Export;

namespace KeySwitchManager.Applications.Standalone.Core.Presenters
{
public class ExportPresenter : IExportPresenter
{
private ILogTextView TextView { get; }

public ExportPresenter( ILogTextView textView )
{
TextView = textView;
}

public async Task HandleAsync( ExportOutputData outputData, CancellationToken cancellationToken = default )
{
var keySwitches = outputData.Value.Result;
var count = outputData.Value.WrittenCount;

var developerName = outputData.Value.Input.DeveloperName;
var productName = outputData.Value.Input.ProductName;
var instrumentName = outputData.Value.Input.InstrumentName;

if( !keySwitches.Any() )
{
TextView.Append( $"No keyswitch(es) found. ({nameof( developerName )}={developerName}, {nameof( productName )}={productName}, {nameof( instrumentName )}={instrumentName})" );
}

TextView.Append( $"{count} exported" );

await Task.CompletedTask;
}

public async Task HandleExportedAsync( KeySwitch exported, CancellationToken cancellationToken = default )
{
TextView.Append( $"Exported: {exported}" );
await Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private async void OnDoCreateNewDefinitionButtonClicked( object sender, RoutedEv
return;
}

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

await ExecuteControllerAsync( () => factory.Create( path, presenter ) );
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace KeySwitchManager.Xamarin.Mac
[Register( "AppDelegate" )]
public class AppDelegate : NSApplicationDelegate
{
// ReSharper disable once EmptyConstructor
public AppDelegate()
{
/*caret*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async partial void OnOpenNewFileButtonClicked( NSObject sender )
return;
}

ICreateControllerFactory factory = new CreateFileControllerFactory();
ICreateFileControllerFactory factory = new CreateFileControllerFactory();
var presenter = new CreatePresenter( LogView );

await ExecuteControllerAsync( () => factory.Create( path, presenter ) );
Expand Down

This file was deleted.

Loading

0 comments on commit 542d098

Please sign in to comment.