57 lines
2.4 KiB
C#
57 lines
2.4 KiB
C#
using KssSmaPlaLib.AutoTest.Script;
|
|
using Serilog.Core;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using KssSmaPlaLib.Batch.Cleanup;
|
|
using KssSmaPlaLib.Batch.Sftp;
|
|
using KssSmaPlaLib.Batch.Interface;
|
|
using KssSmaPlaLib.Batch.Backup;
|
|
using KssSmaPlaLib.Batch.Exchange;
|
|
using KssSmaPlaLib.Batch.IO;
|
|
|
|
namespace KssSmaPlaLib.Batch.Dispatch
|
|
{
|
|
public class StepDispatcherUxer
|
|
{
|
|
// 利用可能ステップハンドラー
|
|
private readonly Dictionary<string, Func<string, string, IFuncResultDto>> _handlers;
|
|
|
|
public StepDispatcherUxer()
|
|
{
|
|
_handlers = new Dictionary<string, Func<string, string, IFuncResultDto>>()
|
|
{
|
|
{ "Cleanup", (iniPath, section) => new CleanupStepHandlerUxer().TryFuncCleanupByIni(iniPath,section) },
|
|
{ "SFTPUpload", (iniPath, section) => new SftpStepHandlerUxer().TryFuncSftpUploadByIni(iniPath,section) },
|
|
{ "SFTPDownload", (iniPath, section) => new SftpStepHandlerUxer().TryFuncSftpDownloadByIni(iniPath,section) },
|
|
{ "SFTPDelete", (iniPath, section) => new SftpStepHandlerUxer().TryFuncSftpDeleteByIni(iniPath,section) },
|
|
{ "Backup", (iniPath, section) => new BackupStepHandlerUxer().TryFuncBackupByIni(iniPath,section) },
|
|
{ "CsvToDb", (iniPath, section) => new CsvToDbStepHandlerUxer().TryFuncCsvToDbByIni(iniPath,section) },
|
|
{ "Delete", (iniPath, section) => new FileStepHandlerUxer().TryFuncFileDeleteByIni(iniPath,section) },
|
|
};
|
|
}
|
|
|
|
public bool TryDispatch(string stepName, string iniPath, string sectionName, out string resultMessage, out IFuncResultDto funcResultDto)
|
|
{
|
|
resultMessage = string.Empty;
|
|
funcResultDto = null;
|
|
if (_handlers.TryGetValue(stepName, out var func))
|
|
{
|
|
funcResultDto = func(iniPath,sectionName);
|
|
resultMessage = funcResultDto.ResultMessage;
|
|
return funcResultDto.Succeeded;
|
|
}
|
|
resultMessage = $"機能名が登録されていません。[機能名:{stepName}]";
|
|
return false;
|
|
}
|
|
}
|
|
public class TryDispatchResultDto : IFuncResultDto
|
|
{
|
|
public string ResultMessage { get; set; } = string.Empty;
|
|
public int ExitCode { get; set; } = 0;
|
|
public bool Succeeded { get; set; } = false;
|
|
}
|
|
}
|