refactoring + [WIP/ci]
This commit is contained in:
12
cli/Commands/CiBuildCommand.cs
Normal file
12
cli/Commands/CiBuildCommand.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using cli.Services;
|
||||||
|
|
||||||
|
namespace cli {
|
||||||
|
|
||||||
|
public class CiBuildCommand {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
54
cli/Commands/SendMailCommand.cs
Normal file
54
cli/Commands/SendMailCommand.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
using Microsoft.AspNet.Hosting;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using cli.Services;
|
||||||
|
|
||||||
|
namespace cli {
|
||||||
|
|
||||||
|
public class SendMailCommandProvider {
|
||||||
|
public static CommandLineApplication Handle(CommandLineApplication rootApp)
|
||||||
|
{
|
||||||
|
CommandArgument _sendMailCommandArg = null;
|
||||||
|
CommandOption _sendHelpOption = null;
|
||||||
|
CommandLineApplication sendMailCommandApp
|
||||||
|
= rootApp.Command("send",
|
||||||
|
(target) =>
|
||||||
|
{
|
||||||
|
target.FullName = "Send email";
|
||||||
|
target.Description = "Sends emails using given template";
|
||||||
|
_sendHelpOption = target.HelpOption("-? | -h | --help");
|
||||||
|
_sendMailCommandArg = target.Argument(
|
||||||
|
"class",
|
||||||
|
"class name of mailling to execute (actually, only 'monthly') .",
|
||||||
|
multipleValues: true);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
sendMailCommandApp.OnExecute(() =>
|
||||||
|
{
|
||||||
|
if (_sendMailCommandArg.Value == "monthly")
|
||||||
|
{
|
||||||
|
var host = new WebHostBuilder();
|
||||||
|
var hostengnine = host.UseEnvironment("Development")
|
||||||
|
.UseServer("cli")
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.Build();
|
||||||
|
var app = hostengnine.Start();
|
||||||
|
var mailer = app.Services.GetService<EMailer>();
|
||||||
|
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
||||||
|
var logger = loggerFactory.CreateLogger<cli.Program>();
|
||||||
|
logger.LogInformation("Starting emailling");
|
||||||
|
mailer.SendMonthlyEmail(1, "UserOrientedTemplate");
|
||||||
|
logger.LogInformation("Finished emailling");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendMailCommandApp.ShowHelp();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
return sendMailCommandApp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
cli/Misc/ICliCommander.cs
Normal file
4
cli/Misc/ICliCommander.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
public interface ICliTAsk
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
38
cli/Program.cs
Normal file
38
cli/Program.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
|
namespace cli
|
||||||
|
{
|
||||||
|
public partial class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
CommandOption rootCommandHelpOption = null;
|
||||||
|
|
||||||
|
CommandLineApplication cliapp = new CommandLineApplication(false);
|
||||||
|
cliapp.Name = "cli";
|
||||||
|
cliapp.FullName = "Yavsc command line interface";
|
||||||
|
cliapp.Description = "Dnx console for yavsc server side";
|
||||||
|
cliapp.ShortVersionGetter = () => "v1.0";
|
||||||
|
cliapp.LongVersionGetter = () => "version 1.0 (stable)";
|
||||||
|
rootCommandHelpOption = cliapp.HelpOption("-? | -h | --help");
|
||||||
|
|
||||||
|
var sb = SendMailCommandProvider.Handle(cliapp);
|
||||||
|
if (args.Length == 0)
|
||||||
|
{
|
||||||
|
cliapp.ShowHint();
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cliapp.Execute(args);
|
||||||
|
|
||||||
|
if (cliapp.RemainingArguments.Count > 0)
|
||||||
|
{
|
||||||
|
cliapp.ShowHint();
|
||||||
|
Environment.Exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
cli/Settings/CiBuildSettings.cs
Normal file
58
cli/Settings/CiBuildSettings.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
public class CiBuildSettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A command specification (a system command),
|
||||||
|
/// in order to reference some trusted server-side process
|
||||||
|
/// </summary>
|
||||||
|
public class Command
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Path { get; set; }
|
||||||
|
public string[] Args { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specific variables to this process
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public string[] Environment { get; set; }
|
||||||
|
public string WorkingDir { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The global process environment variables
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public string[] Environment { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The required building command.
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
[Required]
|
||||||
|
public Command Build { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A preparing command.
|
||||||
|
/// It is optional, but when specified,
|
||||||
|
/// must end ok in order to launch the build.
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public Command Prepare { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A post-production command,
|
||||||
|
/// for an example, some publishing,
|
||||||
|
/// push in prod env ...
|
||||||
|
/// only fired on successful build.
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public Command PostProduction { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Additional emails, as dest of notifications
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public string[] Emails { get; set; }
|
||||||
|
|
||||||
|
}
|
@ -24,6 +24,7 @@
|
|||||||
"Microsoft.AspNet.Identity": "3.0.0-rc1-*",
|
"Microsoft.AspNet.Identity": "3.0.0-rc1-*",
|
||||||
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
|
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
|
||||||
"Microsoft.AspNet.Mvc": "6.0.0-rc1-*",
|
"Microsoft.AspNet.Mvc": "6.0.0-rc1-*",
|
||||||
|
"Microsoft.AspNet.SignalR.Client": "2.2.1",
|
||||||
"Microsoft.CodeAnalysis": "1.1.0-rc1-20151109-01",
|
"Microsoft.CodeAnalysis": "1.1.0-rc1-20151109-01",
|
||||||
"Microsoft.Extensions.CodeGeneration": "1.0.0-rc1-final",
|
"Microsoft.Extensions.CodeGeneration": "1.0.0-rc1-final",
|
||||||
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final",
|
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final",
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
// using Microsoft.AspNet.Authorization;
|
|
||||||
// using Microsoft.AspNet.Diagnostics;
|
|
||||||
using Microsoft.AspNet.Hosting;
|
|
||||||
using cli.Services;
|
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace cli
|
|
||||||
{
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
|
|
||||||
CommandArgument sendMailCommandArg=null;
|
|
||||||
CommandLineApplication sendMailCommand=null;
|
|
||||||
CommandOption sendHelpOption=null;
|
|
||||||
CommandOption rootCommandHelpOption = null;
|
|
||||||
|
|
||||||
CommandLineApplication cliapp = new CommandLineApplication(false);
|
|
||||||
cliapp.Name = "cli";
|
|
||||||
cliapp.FullName = "Yavsc command line interface";
|
|
||||||
cliapp.Description = "Dnx console for yavsc server side";
|
|
||||||
cliapp.ShortVersionGetter = () => "v1.0";
|
|
||||||
cliapp.LongVersionGetter = () => "version 1.0 (stable)";
|
|
||||||
rootCommandHelpOption = cliapp.HelpOption("-? | -h | --help");
|
|
||||||
|
|
||||||
sendMailCommand = cliapp.Command("send",
|
|
||||||
(target) => {
|
|
||||||
target.FullName="Send email";
|
|
||||||
target.Description="Sends emails using given template";
|
|
||||||
sendHelpOption = target.HelpOption("-? | -h | --help");
|
|
||||||
sendMailCommandArg = target.Argument(
|
|
||||||
"class",
|
|
||||||
"class name of mailling to execute (actually, only 'monthly') .",
|
|
||||||
multipleValues: true);
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
sendMailCommand.OnExecute(() =>
|
|
||||||
{
|
|
||||||
if (sendMailCommandArg.Value == "monthly")
|
|
||||||
{
|
|
||||||
var host = new WebHostBuilder();
|
|
||||||
var hostengnine = host.UseEnvironment("Development")
|
|
||||||
.UseServer("cli")
|
|
||||||
.UseStartup<Startup>()
|
|
||||||
.Build();
|
|
||||||
var app = hostengnine.Start();
|
|
||||||
var mailer = app.Services.GetService<EMailer>();
|
|
||||||
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
|
||||||
var logger = loggerFactory.CreateLogger<Program>();
|
|
||||||
logger.LogInformation("Starting emailling");
|
|
||||||
mailer.SendMonthlyEmail(1, "UserOrientedTemplate");
|
|
||||||
logger.LogInformation("Finished emailling");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sendMailCommand.ShowHelp();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
cliapp.Execute(args);
|
|
||||||
|
|
||||||
if (args.Length==0 || cliapp.RemainingArguments.Count>0)
|
|
||||||
cliapp.ShowHint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user