Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/202410 code smell 18 #1776

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 100 additions & 88 deletions starsky/starsky.feature.webhtmlpublish/Helpers/PublishCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,112 @@
using starsky.foundation.storage.Models;
using starsky.foundation.storage.Storage;

namespace starsky.feature.webhtmlpublish.Helpers
namespace starsky.feature.webhtmlpublish.Helpers;

public class PublishCli
{
public class PublishCli
private readonly AppSettings _appSettings;
private readonly ArgsHelper _argsHelper;
private readonly IConsole _console;
private readonly IStorage _hostFileSystemStorage;
private readonly IWebLogger _logger;
private readonly IPublishPreflight _publishPreflight;
private readonly IWebHtmlPublishService _publishService;
private readonly ISelectorStorage _storageSelector;
private readonly IStorage _subPathStorage;

public PublishCli(ISelectorStorage storageSelector, IPublishPreflight publishPreflight,
IWebHtmlPublishService publishService, AppSettings appSettings, IConsole console,
IWebLogger logger)
{
private readonly IPublishPreflight _publishPreflight;
private readonly IWebHtmlPublishService _publishService;
private readonly AppSettings _appSettings;
private readonly IConsole _console;
private readonly ArgsHelper _argsHelper;
private readonly IStorage _hostFileSystemStorage;
private readonly IStorage _subPathStorage;
private readonly IWebLogger _logger;
private readonly ISelectorStorage _storageSelector;

public PublishCli(ISelectorStorage storageSelector, IPublishPreflight publishPreflight,
IWebHtmlPublishService publishService, AppSettings appSettings, IConsole console, IWebLogger logger)
_publishPreflight = publishPreflight;
_publishService = publishService;
_appSettings = appSettings;
_console = console;
_argsHelper = new ArgsHelper(appSettings, console);
_hostFileSystemStorage =
storageSelector.Get(SelectorStorage.StorageServices.HostFilesystem);
_subPathStorage = storageSelector.Get(SelectorStorage.StorageServices.SubPath);
_storageSelector = storageSelector;
_logger = logger;
}

/// <summary>
/// Command Line Helper to server WebHtml Content
/// </summary>
/// <param name="args">arguments to adjust settings, see starskywebhtml/readme.md for more details</param>
/// <returns>void</returns>
public async Task Publisher(string[] args)
{
_appSettings.Verbose = ArgsHelper.NeedVerbose(args);

if ( ArgsHelper.NeedHelp(args) )
{
_appSettings.ApplicationType = AppSettings.StarskyAppType.WebHtml;
_argsHelper.NeedHelpShowDialog();
return;
}

var inputFullPath = _argsHelper.GetPathFormArgs(args, false);
if ( string.IsNullOrWhiteSpace(inputFullPath) )
{
_publishPreflight = publishPreflight;
_publishService = publishService;
_appSettings = appSettings;
_console = console;
_argsHelper = new ArgsHelper(appSettings, console);
_hostFileSystemStorage = storageSelector.Get(SelectorStorage.StorageServices.HostFilesystem);
_subPathStorage = storageSelector.Get(SelectorStorage.StorageServices.SubPath);
_storageSelector = storageSelector;
_logger = logger;
_console.WriteLine("Please use the -p to add a path first");
return;
}

/// <summary>
/// Command Line Helper to server WebHtml Content
/// </summary>
/// <param name="args">arguments to adjust settings, see starskywebhtml/readme.md for more details</param>
/// <returns>void</returns>
public async Task Publisher(string[] args)
if ( _hostFileSystemStorage.IsFolderOrFile(inputFullPath) !=
FolderOrFileModel.FolderOrFileTypeList.Folder )
{
_appSettings.Verbose = ArgsHelper.NeedVerbose(args);

if ( ArgsHelper.NeedHelp(args) )
{
_appSettings.ApplicationType = AppSettings.StarskyAppType.WebHtml;
_argsHelper.NeedHelpShowDialog();
return;
}

var inputFullPath = _argsHelper.GetPathFormArgs(args, false);
if ( string.IsNullOrWhiteSpace(inputFullPath) )
{
_console.WriteLine("Please use the -p to add a path first");
return;
}

if ( _hostFileSystemStorage.IsFolderOrFile(inputFullPath) !=
FolderOrFileModel.FolderOrFileTypeList.Folder )
{
_console.WriteLine("Please add a valid folder: " + inputFullPath + ". " +
"This folder is not found");
return;
}

var settingsFullFilePath = Path.Combine(inputFullPath, "_settings.json");
if ( _hostFileSystemStorage.ExistFile(settingsFullFilePath) )
{
_console.WriteLine($"You have already run this program for this folder remove the " +
$"_settings.json first and try it again");
return;
}

var itemName = _publishPreflight.GetNameConsole(inputFullPath, args);

if ( _appSettings.IsVerbose() )
{
_console.WriteLine("Name: " + itemName);
_console.WriteLine("inputPath " + inputFullPath);
}

// used in this session to find the photos back
// outside the webRoot of iStorage
_appSettings.StorageFolder = inputFullPath;

// use relative to StorageFolder
var listOfFiles = _subPathStorage.GetAllFilesInDirectory("/")
.Where(ExtensionRolesHelper.IsExtensionExifToolSupported).ToList();

var fileIndexList = await new ReadMeta(_subPathStorage, _appSettings, null!, _logger)
.ReadExifAndXmpFromFileAddFilePathHashAsync(listOfFiles);

// todo introduce selector
var profileName = new PublishPreflight(_appSettings, _console, _storageSelector, _logger)
.GetPublishProfileNameByIndex(0);

await _publishService.RenderCopy(fileIndexList, profileName,
itemName, inputFullPath, true);

_console.WriteLine("publish done");
_console.WriteLine("Please add a valid folder: " + inputFullPath + ". " +
"This folder is not found");
return;
}

var settingsFullFilePath = Path.Combine(inputFullPath, "_settings.json");
if ( _hostFileSystemStorage.ExistFile(settingsFullFilePath) )
{
_console.WriteLine($"You have already run this program for this folder remove the " +
$"_settings.json first and try it again");
return;
}

var itemName = _publishPreflight.GetNameConsole(inputFullPath, args);

if ( _appSettings.IsVerbose() )
{
_console.WriteLine("Name: " + itemName);
_console.WriteLine("inputPath " + inputFullPath);
}

// used in this session to find the photos back
// outside the webRoot of iStorage
_appSettings.StorageFolder = inputFullPath;

// use relative to StorageFolder
var listOfFiles = _subPathStorage.GetAllFilesInDirectory("/")
.Where(ExtensionRolesHelper.IsExtensionExifToolSupported).ToList();

var fileIndexList = await new ReadMeta(_subPathStorage, _appSettings, null!, _logger)
.ReadExifAndXmpFromFileAddFilePathHashAsync(listOfFiles);

var publishPreflight =
new PublishPreflight(_appSettings, _console, _storageSelector, _logger);
var profileName = ArgsHelper.GetProfile(args);

if ( publishPreflight.GetPublishProfileKey(profileName) != profileName )
{
profileName = publishPreflight.GetPublishProfileNameByIndex(0);
_console.WriteLine(
$"Profile not found, uses default {profileName} use --profile to select one");
}
else
{
_console.WriteLine("Running profile: " + profileName);
}

await _publishService.RenderCopy(fileIndexList, profileName,
itemName, inputFullPath, true);

_console.WriteLine("publish done");
}
}
Loading