|
|
@ -5,42 +5,62 @@ using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using cli.Services;
|
|
|
|
using cli.Services;
|
|
|
|
using cli.Model;
|
|
|
|
using cli.Model;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using Yavsc.Models;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace cli {
|
|
|
|
namespace cli
|
|
|
|
|
|
|
|
{
|
|
|
|
public class SendMailCommandProvider : ICommander {
|
|
|
|
public class SendMailCommandProvider : ICommander
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
readonly Dictionary<string, Func<ApplicationUser, bool>> Criterias =
|
|
|
|
|
|
|
|
new Dictionary<string, Func<ApplicationUser, bool>>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{"allow-monthly", u => u.AllowMonthlyEmail },
|
|
|
|
|
|
|
|
{ "email-not-confirmed", u => !u.EmailConfirmed }
|
|
|
|
|
|
|
|
};
|
|
|
|
public CommandLineApplication Integrate(CommandLineApplication rootApp)
|
|
|
|
public CommandLineApplication Integrate(CommandLineApplication rootApp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CommandArgument sendMailCommandArg = null;
|
|
|
|
|
|
|
|
CommandOption sendHelpOption = null;
|
|
|
|
CommandArgument codeCommandArg = null;
|
|
|
|
CommandLineApplication sendMailCommandApp
|
|
|
|
CommandArgument critCommandArg = null;
|
|
|
|
= rootApp.Command("send",
|
|
|
|
CommandOption sendHelpOption = null;
|
|
|
|
(target) =>
|
|
|
|
CommandLineApplication sendMailCommandApp
|
|
|
|
{
|
|
|
|
= rootApp.Command("send-monthly",
|
|
|
|
target.FullName = "Send email";
|
|
|
|
(target) =>
|
|
|
|
target.Description = "Sends emails using given template";
|
|
|
|
{
|
|
|
|
sendHelpOption = target.HelpOption("-? | -h | --help");
|
|
|
|
target.FullName = "Send email";
|
|
|
|
sendMailCommandArg = target.Argument(
|
|
|
|
target.Description = "Sends monthly emails using given template from code";
|
|
|
|
"class",
|
|
|
|
sendHelpOption = target.HelpOption("-? | -h | --help");
|
|
|
|
"class name of mailling to execute (actually, only 'monthly') .",
|
|
|
|
codeCommandArg = target.Argument(
|
|
|
|
multipleValues: true);
|
|
|
|
"code",
|
|
|
|
}, false);
|
|
|
|
"template code of mailling to execute.");
|
|
|
|
|
|
|
|
critCommandArg = target.Argument(
|
|
|
|
|
|
|
|
"criteria",
|
|
|
|
|
|
|
|
"user selection criteria : 'allow-monthly' or 'email-not-confirmed'");
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
sendMailCommandApp.OnExecute(() =>
|
|
|
|
sendMailCommandApp.OnExecute(() =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (sendMailCommandArg.Value == "monthly")
|
|
|
|
int code;
|
|
|
|
|
|
|
|
bool showhelp = !int.TryParse(codeCommandArg.Value, out code)
|
|
|
|
|
|
|
|
|| Criterias.ContainsKey(critCommandArg.Value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!showhelp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var host = new WebHostBuilder();
|
|
|
|
var host = new WebHostBuilder();
|
|
|
|
var hostengnine = host.UseEnvironment("Development")
|
|
|
|
|
|
|
|
|
|
|
|
var hostengnine = host.UseEnvironment(Program.HostingEnvironment.EnvironmentName)
|
|
|
|
.UseServer("cli")
|
|
|
|
.UseServer("cli")
|
|
|
|
.UseStartup<Startup>()
|
|
|
|
.UseStartup<Startup>()
|
|
|
|
.Build();
|
|
|
|
.Build();
|
|
|
|
var app = hostengnine.Start();
|
|
|
|
var app = hostengnine.Start();
|
|
|
|
var mailer = app.Services.GetService<EMailer>();
|
|
|
|
var mailer = app.Services.GetService<EMailer>();
|
|
|
|
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
|
|
|
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
|
|
|
var logger = loggerFactory.CreateLogger<cli.Program>();
|
|
|
|
var logger = loggerFactory.CreateLogger<Program>();
|
|
|
|
logger.LogInformation("Starting emailling");
|
|
|
|
logger.LogInformation("Starting emailling");
|
|
|
|
mailer.SendMonthlyEmail(1, "UserOrientedTemplate");
|
|
|
|
mailer.SendEmailFromCriteria(code, Criterias[critCommandArg.Value]);
|
|
|
|
logger.LogInformation("Finished emailling");
|
|
|
|
logger.LogInformation("Finished emailling");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -53,4 +73,4 @@ public class SendMailCommandProvider : ICommander {
|
|
|
|
return sendMailCommandApp;
|
|
|
|
return sendMailCommandApp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|