build cli
This commit is contained in:
parent
b3d565b6d9
commit
5c046dfa88
34 changed files with 7153 additions and 1231 deletions
|
|
@ -1,26 +1,21 @@
|
|||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using cli.Services;
|
||||
using cli.Model;
|
||||
using Yavsc.Server.Settings;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Services;
|
||||
|
||||
namespace cli
|
||||
{
|
||||
public class SendMailCommandProvider : ICommander
|
||||
{
|
||||
EMailer emailer;
|
||||
MailSender emailer;
|
||||
private ILogger<SendMailCommandProvider> logger;
|
||||
public SendMailCommandProvider(EMailer emailer, ILoggerFactory loggerFactory)
|
||||
public SendMailCommandProvider(MailSender emailer, ILoggerFactory loggerFactory)
|
||||
{
|
||||
this.emailer = emailer;
|
||||
this.logger = loggerFactory.CreateLogger<SendMailCommandProvider>();
|
||||
}
|
||||
public CommandLineApplication Integrate(CommandLineApplication rootApp)
|
||||
{
|
||||
CommandArgument critCommandArg = null;
|
||||
CommandOption sendHelpOption = null;
|
||||
CommandLineApplication sendMailCommandApp
|
||||
= rootApp.Command("send-email",
|
||||
|
|
@ -29,28 +24,16 @@ namespace cli
|
|||
target.FullName = "Send email";
|
||||
target.Description = "Sends emails using given template from code";
|
||||
sendHelpOption = target.HelpOption("-? | -h | --help");
|
||||
critCommandArg = target.Argument(
|
||||
"criteria",
|
||||
"user selection criteria : 'allow-monthly' or 'email-not-confirmed'");
|
||||
}, false);
|
||||
|
||||
sendMailCommandApp.OnExecute(() =>
|
||||
{
|
||||
bool showhelp = !UserPolicies.Criterias.ContainsKey(critCommandArg.Value)
|
||||
|| sendHelpOption.HasValue();
|
||||
bool showhelp = sendHelpOption.HasValue();
|
||||
|
||||
if (!showhelp)
|
||||
{
|
||||
var host = new WebHostBuilder();
|
||||
|
||||
var hostengnine = host.UseEnvironment(Program.HostingEnvironment.EnvironmentName)
|
||||
.UseServer("cli")
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
|
||||
logger.LogInformation("Starting emailling");
|
||||
emailer.SendEmailFromCriteria(critCommandArg.Value);
|
||||
emailer.SendEmailFromCriteria("allow-monthly");
|
||||
logger.LogInformation("Finished emailling");
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue