Skip to content

Commit

Permalink
Refactor (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmccall authored Jan 18, 2020
1 parent 84111f5 commit 583b7f7
Show file tree
Hide file tree
Showing 26 changed files with 377 additions and 231 deletions.
53 changes: 0 additions & 53 deletions client-generator-tests/App/Commands/CommandWithConnectedWindow.cs

This file was deleted.

3 changes: 1 addition & 2 deletions client-generator-tests/Helpers/GeneratorAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ namespace client_generator_tests.Helpers
public class GeneratorAccessor : Generator
{

public GeneratorAccessor(ITemplateFactory templateFactory)
public GeneratorAccessor(ITemplateFactory templateFactory) : base(new GeneratorContext(templateFactory))
{
GeneratorSettings.SchemePlace = SchemeGeneratePlace.WithCode;
GeneratorContext = new GeneratorContext(templateFactory);
}

public void AccessParseSchemas(IEnumerable<ISchema> schemas)
Expand Down
19 changes: 8 additions & 11 deletions client-generator/App/AppController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using client_generator.Generators;
using logger;
using logger.LogStrategies;
using Terminal.Gui;

namespace client_generator.App
Expand All @@ -11,11 +10,7 @@ public class AppController : IAppController

private static readonly AppController AppControllerInstance = new AppController();

private readonly ILogger _logger = new LoggerFacade<RawLogger>(new LoggerSettings
{
LogLevel = LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal,
DefaultLogStrategy = new FileLogStrategy("logs.log")
});
private ILogger _logger;

private Window _currentWindow;

Expand All @@ -25,7 +20,7 @@ private AppController()
{
}

public GeneratorTemplate Generator { get; } = new Generator();
public GeneratorTemplate Generator { get; private set; }

public static AppController Instance()
{
Expand All @@ -37,10 +32,12 @@ public static ILogger GetLogger()
return AppControllerInstance._logger;
}

public void InitApp<T>() where T : Window, new()
public void StartWindow(Window window, GeneratorTemplate generator, ILogger logger)
{
_logger.Info("Initialization...");
Application.Init();
_logger = logger;
Generator = generator;

_logger.Info("Initialization gui...");
_toplevel = new Toplevel
{
X = 0,
Expand All @@ -49,7 +46,7 @@ public static ILogger GetLogger()
Height = Dim.Fill()
};

_currentWindow = new T();
_currentWindow = window;
_toplevel.Add(_currentWindow);

_logger.Info("Star up...");
Expand Down
68 changes: 68 additions & 0 deletions client-generator/App/Commands/CommandsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using client_generator.App.Windows.MenuWindowStates;
using client_generator.Models;
using logger;
using Newtonsoft.Json;
using Terminal.Gui;

namespace client_generator.App.Commands
{
public class CommandsProvider : ICommandsProvider
{

private readonly AppController _appController;

private readonly ILogger _logger;

public CommandsProvider(AppController appController, ILogger logger)
{
_appController = appController;
_logger = logger;
}

public ICommand ExitCommand()
{
return new ExitAppCommand(_appController);
}

public ICommand ChangeWindowCommand(Window to)
{
return new ChangeWindowCommand(_appController, to);
}

public ICommand DeserializationCommand(
FileSystemEntry file,
JsonSerializerSettings deserializationSettings,
Action<OpenApiModel> onDeserialization,
Action<Exception> onError
)
{
return new DeserializationCommand(file, deserializationSettings, onDeserialization, onError);
}

public ICommand ShowPopupWindowCommand(
PopupWindow popupWindow,
Action<object> receiver,
Window current
)
{
var returnCommand = ChangeWindowCommand(current);
popupWindow.SetActionReceiver(o =>
{
receiver?.Invoke(o);
returnCommand.Execute();
});

return ChangeWindowCommand(popupWindow);
}

public ICommand GeneratorCommand(
OpenApiModel openApiModel, Action onSuccess,
Action<Exception> onError
)
{
return new GenerateCommand(_appController, _logger, openApiModel, onSuccess, onError);
}

}
}
30 changes: 0 additions & 30 deletions client-generator/App/Commands/EditGeneratorSettingsCommand.cs

This file was deleted.

This file was deleted.

13 changes: 10 additions & 3 deletions client-generator/App/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using client_generator.Models;
using logger;

namespace client_generator.App.Commands
{
Expand All @@ -10,11 +11,17 @@ internal class GenerateCommand : ICommand

private readonly Action _onSuccess;

private readonly AppController _controller;

private readonly ILogger _logger;

private readonly OpenApiModel _openApiModel;

public GenerateCommand(OpenApiModel openApiModel, Action onSuccess,
public GenerateCommand(AppController controller, ILogger logger,OpenApiModel openApiModel, Action onSuccess,
Action<Exception> onError)
{
_controller = controller;
_logger = logger;
_openApiModel = openApiModel;
_onSuccess = onSuccess;
_onError = onError;
Expand All @@ -24,8 +31,8 @@ public void Execute()
{
try
{
AppController.GetLogger().Info("Generate client.");
AppController.Instance().Generator.Generate(_openApiModel);
_logger.Info("Generate client.");
_controller.Generator.Generate(_openApiModel);
_onSuccess.Invoke();
}
catch (Exception e)
Expand Down
33 changes: 33 additions & 0 deletions client-generator/App/Commands/ICommandsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using client_generator.App.Windows.MenuWindowStates;
using client_generator.Models;
using Newtonsoft.Json;
using Terminal.Gui;

namespace client_generator.App.Commands
{
public interface ICommandsProvider
{

ICommand ExitCommand();

ICommand DeserializationCommand(
FileSystemEntry file,
JsonSerializerSettings deserializationSettings,
Action<OpenApiModel> onDeserialization,
Action<Exception> onError
);

ICommand ShowPopupWindowCommand(
PopupWindow popupWindow,
Action<object> receiver,
Window current
);

ICommand GeneratorCommand(
OpenApiModel openApiModel, Action onSuccess,
Action<Exception> onError
);

}
}
31 changes: 0 additions & 31 deletions client-generator/App/Commands/SelectFileCommand.cs

This file was deleted.

Loading

0 comments on commit 583b7f7

Please sign in to comment.