build cli

This commit is contained in:
Paul Schneider 2025-07-16 00:47:50 +01:00
commit 5c046dfa88
34 changed files with 7153 additions and 1231 deletions

View file

@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
using cli.Model;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Yavsc.Authentication;
namespace cli.Commands
{
@ -42,10 +40,10 @@ namespace cli.Commands
});
loginCommand.OnExecute(async () =>
{
string authUrl = Startup.ConnectionSettings.AuthorizeUrl;
string redirect = Startup.ConnectionSettings.RedirectUrl;
string tokenUrl = Startup.ConnectionSettings.AccessTokenUrl;
string? authUrl = Program.AppConfiguration.GetValue<String>("ConnectionSettings:ServerApi:Authority");
throw new NotImplementedException();
/*
OAuthenticator oauthor = new OAuthenticator(_apiKey.HasValue() ? _apiKey.Value() : Startup.ConnectionSettings.ClientId,
_secret.HasValue() ? _secret.Value() : Startup.ConnectionSettings.ClientSecret,
_scope.HasValue() ? _scope.Value() : Startup.ConnectionSettings.Scope,
@ -72,11 +70,11 @@ namespace cli.Commands
_logger.LogError(ex.Message);
}
return 0;
return 0; */
});
}, false);
return authApp;
return authApp;
}
public static string GetPassword(string userName)

View file

@ -1,61 +0,0 @@
using Microsoft.Extensions.CommandLineUtils;
using System.Threading.Tasks;
using NJsonSchema;
using System.IO;
using cli.Model;
using Yavsc.Abstract.IT;
namespace cli
{
public class GenerateJsonSchema : ICommander
{
public CommandLineApplication Integrate(CommandLineApplication rootApp)
{
CommandArgument genargclass = null;
CommandArgument genargjson = null;
CommandOption genopthelp = null;
var cmd = rootApp.Command("gen",
(target) =>
{
target.FullName = "Generete";
target.Description = "generates some objects ...";
genopthelp = target.HelpOption("-? | -h | --help");
genargclass = target.Argument(
"class",
"class name of generation to execute (actually, only 'jsonSchema') .",
multipleValues: false);
genargjson = target.Argument(
"json",
"Json file generated",
multipleValues: false);
}, false);
cmd.OnExecute(
() => {
if (genargclass.Value == "jsonSchema") {
GenerateCiBuildSettingsSchema(genargjson.Value);
} else {
cmd.ShowHint();
return 1;
}
return 0;
}
);
return cmd;
}
public static void GenerateCiBuildSettingsSchema(string outputFileName = "pauls-ci-schema.json")
{
var schema = JsonSchema.FromType(typeof(CiBuildSettings));
var schemaData = schema.ToJson();
FileInfo ofi = new FileInfo(outputFileName);
var ostream = ofi.OpenWrite();
var owritter = new StreamWriter(ostream);
owritter.WriteLine(schemaData);
owritter.Close();
ostream.Close();
}
}
}

View file

@ -1,11 +1,11 @@
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.OptionsModel;
using cli.Model;
using cli.Services;
using cli.Settings;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace cli.Commands
{
@ -34,18 +34,13 @@ namespace cli.Commands
config.HelpOption("-? | -h | --help");
});
cmd.OnExecute(() => {
var host = new WebHostBuilder();
var hostEngine = host.UseEnvironment("Development")
.UseServer("cli")
.UseStartup<Startup>()
.Build();
var app = hostEngine.Start();
var mailer = app.Services.GetService<MvcGenerator>();
var loggerFactory = app.Services.GetService<ILoggerFactory>();
var mailer = Program.AppHost.Services.GetService<MvcGenerator>();
var loggerFactory = Program.AppHost.Services.GetService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger<GenerationCommander>();
var options = app.Services.GetService<IOptions<GenMvcSettings>>();
var options = Program.AppHost.Services.GetService<IOptions<GenMvcSettings>>();
MvcGenerator generator = app.Services.GetService<MvcGenerator>();
MvcGenerator generator = Program.AppHost.Services.GetService<MvcGenerator>();
var modelFullName = mdClass?.Value ?? options?.Value.ModelFullName;
var nameSpace = nameSpaceArg?.Value?? options?.Value.NameSpace;

View file

@ -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

View file

@ -1,13 +1,9 @@
using System;
using System.IO;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using cli.Model;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.Options;
namespace cli {

View file

@ -3,12 +3,10 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using cli.Services;
using Yavsc.Server.Settings;
using Yavsc.Models;
using Microsoft.AspNetCore.Identity;
using System.Linq;
using System;
using Yavsc.Services;
namespace cli.Commands
{
@ -32,19 +30,13 @@ namespace cli.Commands
if (!showhelp)
{
var host = new WebHostBuilder();
var hostengnine = host.UseEnvironment(Program.HostingEnvironment.EnvironmentName)
.UseServer("cli")
.UseStartup<Startup>()
.Build();
var app = hostengnine.Start();
var mailer = app.Services.GetService<EMailer>();
var loggerFactory = app.Services.GetService<ILoggerFactory>();
var mailer = Program.AppHost.Services.GetService<MailSender>();
var loggerFactory = Program.AppHost.Services.GetService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger<Program>();
var userManager = app.Services.GetService<UserManager<ApplicationDbContext>>();
ApplicationDbContext dbContext = app.Services.GetService<ApplicationDbContext>();
var userManager = Program.AppHost.Services.GetService<UserManager<ApplicationUser>>();
ApplicationDbContext dbContext = Program.AppHost.Services.GetService<ApplicationDbContext>();
Func<ApplicationUser, bool> criteria = UserPolicies.Criterias["user-to-remove"];
if (userManager==null)
@ -54,12 +46,14 @@ namespace cli.Commands
}
logger.LogInformation("Starting emailling");
try {
try
{
mailer.SendEmailFromCriteria("user-to-remove");
}
catch (NoMaillingTemplateException ex)
catch (Exception ex)
{
logger.LogWarning(ex.Message);
throw;
}
ApplicationUser [] users = dbContext.ApplicationUser.Where(
u => criteria(u)).ToArray();