2025-07-16 00:47:50 +01:00
|
|
|
using cli.Model;
|
2018-07-28 01:55:13 +02:00
|
|
|
using Microsoft.Extensions.CommandLineUtils;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-07-16 00:47:50 +01:00
|
|
|
using Yavsc.Services;
|
2018-07-28 01:55:13 +02:00
|
|
|
|
2021-05-30 12:30:39 +01:00
|
|
|
namespace cli
|
|
|
|
|
{
|
|
|
|
|
public class SendMailCommandProvider : ICommander
|
|
|
|
|
{
|
2025-07-16 00:47:50 +01:00
|
|
|
MailSender emailer;
|
2025-06-08 14:41:50 +01:00
|
|
|
private ILogger<SendMailCommandProvider> logger;
|
2025-07-16 00:47:50 +01:00
|
|
|
public SendMailCommandProvider(MailSender emailer, ILoggerFactory loggerFactory)
|
2025-06-08 14:41:50 +01:00
|
|
|
{
|
|
|
|
|
this.emailer = emailer;
|
|
|
|
|
this.logger = loggerFactory.CreateLogger<SendMailCommandProvider>();
|
|
|
|
|
}
|
2018-08-05 04:16:21 +02:00
|
|
|
public CommandLineApplication Integrate(CommandLineApplication rootApp)
|
2018-07-28 01:55:13 +02:00
|
|
|
{
|
2021-05-30 12:30:39 +01:00
|
|
|
CommandOption sendHelpOption = null;
|
|
|
|
|
CommandLineApplication sendMailCommandApp
|
2021-06-03 18:21:31 +01:00
|
|
|
= rootApp.Command("send-email",
|
2021-05-30 12:30:39 +01:00
|
|
|
(target) =>
|
|
|
|
|
{
|
|
|
|
|
target.FullName = "Send email";
|
2021-06-03 18:21:31 +01:00
|
|
|
target.Description = "Sends emails using given template from code";
|
2021-05-30 12:30:39 +01:00
|
|
|
sendHelpOption = target.HelpOption("-? | -h | --help");
|
|
|
|
|
}, false);
|
2018-07-28 01:55:13 +02:00
|
|
|
|
|
|
|
|
sendMailCommandApp.OnExecute(() =>
|
|
|
|
|
{
|
2025-07-16 00:47:50 +01:00
|
|
|
bool showhelp = sendHelpOption.HasValue();
|
2021-05-30 12:30:39 +01:00
|
|
|
|
|
|
|
|
if (!showhelp)
|
2018-07-28 01:55:13 +02:00
|
|
|
{
|
|
|
|
|
logger.LogInformation("Starting emailling");
|
2025-07-16 00:47:50 +01:00
|
|
|
emailer.SendEmailFromCriteria("allow-monthly");
|
2018-07-28 01:55:13 +02:00
|
|
|
logger.LogInformation("Finished emailling");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendMailCommandApp.ShowHelp();
|
2019-01-08 15:00:58 +00:00
|
|
|
return 1;
|
2018-07-28 01:55:13 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
return sendMailCommandApp;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-30 12:30:39 +01:00
|
|
|
}
|