diff --git a/cli/Commands/CiBuildCommand.cs b/cli/Commands/CiBuildCommand.cs new file mode 100644 index 00000000..c12ee3aa --- /dev/null +++ b/cli/Commands/CiBuildCommand.cs @@ -0,0 +1,12 @@ + +using Microsoft.Extensions.CommandLineUtils; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using cli.Services; + +namespace cli { + + public class CiBuildCommand { + + } +} \ No newline at end of file diff --git a/cli/Commands/SendMailCommand.cs b/cli/Commands/SendMailCommand.cs new file mode 100644 index 00000000..b03d412a --- /dev/null +++ b/cli/Commands/SendMailCommand.cs @@ -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() + .Build(); + var app = hostengnine.Start(); + var mailer = app.Services.GetService(); + var loggerFactory = app.Services.GetService(); + var logger = loggerFactory.CreateLogger(); + logger.LogInformation("Starting emailling"); + mailer.SendMonthlyEmail(1, "UserOrientedTemplate"); + logger.LogInformation("Finished emailling"); + } + else + { + sendMailCommandApp.ShowHelp(); + } + return 0; + }); + return sendMailCommandApp; + } + } +} \ No newline at end of file diff --git a/cli/Misc/ICliCommander.cs b/cli/Misc/ICliCommander.cs new file mode 100644 index 00000000..38580618 --- /dev/null +++ b/cli/Misc/ICliCommander.cs @@ -0,0 +1,4 @@ +public interface ICliTAsk +{ + +} \ No newline at end of file diff --git a/cli/src/YavscServerFactory.cs b/cli/Misc/YavscServerFactory.cs similarity index 100% rename from cli/src/YavscServerFactory.cs rename to cli/Misc/YavscServerFactory.cs diff --git a/cli/Program.cs b/cli/Program.cs new file mode 100644 index 00000000..8739ca21 --- /dev/null +++ b/cli/Program.cs @@ -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); + } + + } + } +} diff --git a/cli/src/Services/EMailer.cs b/cli/Services/EMailer.cs similarity index 100% rename from cli/src/Services/EMailer.cs rename to cli/Services/EMailer.cs diff --git a/cli/src/Services/YaRazorEngineHost.cs b/cli/Services/YaRazorEngineHost.cs similarity index 100% rename from cli/src/Services/YaRazorEngineHost.cs rename to cli/Services/YaRazorEngineHost.cs diff --git a/cli/Settings/CiBuildSettings.cs b/cli/Settings/CiBuildSettings.cs new file mode 100644 index 00000000..85f12608 --- /dev/null +++ b/cli/Settings/CiBuildSettings.cs @@ -0,0 +1,58 @@ +using System.ComponentModel.DataAnnotations; + +public class CiBuildSettings +{ + /// + /// A command specification (a system command), + /// in order to reference some trusted server-side process + /// + public class Command + { + [Required] + public string Path { get; set; } + public string[] Args { get; set; } + + /// + /// Specific variables to this process + /// + /// + public string[] Environment { get; set; } + public string WorkingDir { get; set; } + } + /// + /// The global process environment variables + /// + /// + public string[] Environment { get; set; } + + /// + /// The required building command. + /// + /// + [Required] + public Command Build { get; set; } + + /// + /// A preparing command. + /// It is optional, but when specified, + /// must end ok in order to launch the build. + /// + /// + public Command Prepare { get; set; } + + /// + /// A post-production command, + /// for an example, some publishing, + /// push in prod env ... + /// only fired on successful build. + /// + /// + public Command PostProduction { get; set; } + + /// + /// Additional emails, as dest of notifications + /// + /// + public string[] Emails { get; set; } + +} \ No newline at end of file diff --git a/cli/src/ConnectionSettings.cs b/cli/Settings/ConnectionSettings.cs similarity index 100% rename from cli/src/ConnectionSettings.cs rename to cli/Settings/ConnectionSettings.cs diff --git a/cli/src/Startup.cs b/cli/Startup.cs similarity index 100% rename from cli/src/Startup.cs rename to cli/Startup.cs diff --git a/cli/project.json b/cli/project.json index e53d656f..d29c65a9 100644 --- a/cli/project.json +++ b/cli/project.json @@ -24,6 +24,7 @@ "Microsoft.AspNet.Identity": "3.0.0-rc1-*", "Microsoft.AspNet.Identity.EntityFramework": "3.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.Extensions.CodeGeneration": "1.0.0-rc1-final", "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final", diff --git a/cli/src/Program.cs b/cli/src/Program.cs deleted file mode 100644 index fa052afa..00000000 --- a/cli/src/Program.cs +++ /dev/null @@ -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() - .Build(); - var app = hostengnine.Start(); - var mailer = app.Services.GetService(); - var loggerFactory = app.Services.GetService(); - var logger = loggerFactory.CreateLogger(); - 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(); - } - } -}