principalement du format de code

This commit is contained in:
Paul Schneider 2020-09-12 01:11:30 +01:00
commit ff1444d664
87 changed files with 510 additions and 550 deletions

View file

@ -16,13 +16,12 @@ namespace cli.Commands
private CommandOption _secret;
private CommandOption _scope;
private CommandOption _save;
ILogger _logger;
readonly ILogger _logger;
public AuthCommander(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<AuthCommander>();
}
{
_logger = loggerFactory.CreateLogger<AuthCommander>();
}
public CommandLineApplication Integrate(CommandLineApplication rootApp)
{
@ -32,37 +31,41 @@ namespace cli.Commands
target.FullName = "Authentication methods";
target.Description = "Login, save credentials and get authorized.";
target.HelpOption("-? | -h | --help");
var loginCommand = target.Command("login", app => {
var loginCommand = target.Command("login", app =>
{
_login = app.Argument("login", "login to use", true);
_apiKey = app.Option("-a | --api", "API key to use against authorization server", CommandOptionType.SingleValue);
_secret = app.Option( "-e | --secret", "Secret phrase associated to API key", CommandOptionType.SingleValue);
_scope = app.Option( "-c | --scope", "invoked scope asking for a security token", CommandOptionType.SingleValue);
_save = app.Option( "-s | --save", "Save authentication token to given file", CommandOptionType.SingleValue);
_secret = app.Option("-e | --secret", "Secret phrase associated to API key", CommandOptionType.SingleValue);
_scope = app.Option("-c | --scope", "invoked scope asking for a security token", CommandOptionType.SingleValue);
_save = app.Option("-s | --save", "Save authentication token to given file", CommandOptionType.SingleValue);
app.HelpOption("-? | -h | --help");
} );
loginCommand.OnExecute(async ()=>
});
loginCommand.OnExecute(async () =>
{
var authUrl = Startup.ConnectionSettings.AuthorizeUrl;
var redirect = Startup.ConnectionSettings.RedirectUrl;
var tokenUrl = Startup.ConnectionSettings.AccessTokenUrl;
string authUrl = Startup.ConnectionSettings.AuthorizeUrl;
string redirect = Startup.ConnectionSettings.RedirectUrl;
string tokenUrl = Startup.ConnectionSettings.AccessTokenUrl;
var oauthor = new OAuthenticator(_apiKey.HasValue() ? _apiKey.Value() : Startup.ConnectionSettings.ClientId,
_secret.HasValue() ? _secret.Value() : Startup.ConnectionSettings.ClientSecret,
_scope.HasValue() ? _scope.Value() : Startup.ConnectionSettings.Scope,
new Uri(authUrl), new Uri(redirect), new Uri(tokenUrl));
var query = new Dictionary<string, string>();
query["username"] = _login.Value;
query["password"] = GetPassword(_login.Value);
query["grant_type"] = "password";
try {
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,
new Uri(authUrl), new Uri(redirect), new Uri(tokenUrl));
Dictionary<string, string> query = new Dictionary<string, string>
{
["username"] = _login.Value,
["password"] = GetPassword(_login.Value),
["grant_type"] = "password"
};
try
{
var result = await oauthor.RequestAccessTokenAsync(query);
Startup.UserConnectionSettings.AccessToken = result["access_token"];
Startup.UserConnectionSettings.ExpiresIn = result["expires_in"];
Startup.UserConnectionSettings.RefreshToken = result["refresh_token"];
Startup.UserConnectionSettings.TokenType = result["token_type"];
Startup.UserConnectionSettings.UserName = _login.Value;
Startup.SaveCredentials(_save.HasValue() ? _save.Value() : Startup.UserConnectionsettingsFileName);
Startup.SaveCredentials(_save.HasValue() ? _save.Value() : Startup.UserConnectionsettingsFileName);
}
catch (Exception ex)
{
@ -112,6 +115,6 @@ namespace cli.Commands
Console.WriteLine();
return pwd.ToString();
}
}
}
}

View file

@ -2,9 +2,10 @@ using System.IO;
using Yavsc.Server.Models.IT;
using Yavsc.Server.Models.IT.SourceCode;
public class Builder {
string _gitRepository;
private Project _projectInfo;
public class Builder
{
readonly string _gitRepository;
private readonly Project _projectInfo;
public Builder()
{
@ -21,4 +22,4 @@ public class Builder {
clone.Launch(_projectInfo);
}
}
}

View file

@ -58,7 +58,6 @@ namespace cli.Commands
logger.LogInformation($"Using parameters : modelFullName:{modelFullName} nameSpace:{nameSpace} dbContext:{dbContext} controllerName:{controllerName} relativePath:{relativePath}");
generator.Generate(modelFullName,
nameSpace,
dbContext,
controllerName,
relativePath);
@ -70,4 +69,4 @@ namespace cli.Commands
return cmd;
}
}
}
}

View file

@ -12,10 +12,10 @@ using Yavsc.Abstract;
namespace cli {
public class Streamer: ICommander {
private ClientWebSocket _client;
private ILogger _logger;
private ConnectionSettings _cxSettings;
private UserConnectionSettings _userCxSettings;
private readonly ClientWebSocket _client;
private readonly ILogger _logger;
private readonly ConnectionSettings _cxSettings;
private readonly UserConnectionSettings _userCxSettings;
private CommandOption _fileOption;
private CommandArgument _flowIdArg;
private CancellationTokenSource _tokenSource;
@ -83,42 +83,22 @@ namespace cli {
await _client.ConnectAsync(new Uri(url), _tokenSource.Token);
_logger.LogInformation("Connected");
const int bufLen = Yavsc.Constants.WebSocketsMaxBufLen;
byte [] buffer = new byte[bufLen+4*sizeof(int)];
byte [] buffer = new byte[bufLen];
const int offset=0;
int read = 0;
/*
var reciving = Task.Run(async ()=> {
byte [] readbuffer = new byte[bufLen];
var rb = new ArraySegment<byte>(readbuffer, 0, bufLen);
bool continueReading = false;
do {
var result = await _client.ReceiveAsync(rb, _tokenSource.Token);
_logger.LogInformation($"received {result.Count} bytes");
continueReading = !result.CloseStatus.HasValue;
} while (continueReading);
} ); */
int read;
bool lastFrame;
do {
read = await stream.ReadAsync(buffer, offset + sizeof(int), bufLen);
if (read>0) {
// assert sizeof(int)==4
buffer[3]= (byte) (read % 256);
var left = read / 256;
buffer[2]= (byte) (left % 256);
left = left / 256;
buffer[1] = (byte) (left % 256);
left = left /256;
buffer[0]=(byte) (byte) (left % 256);
var segment = new ArraySegment<byte>(buffer, offset, read+4);
await _client.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Binary, false, _tokenSource.Token);
_logger.LogInformation($"sent {segment.Count} ");
}
} while (read>0);
// reciving.Wait();
await _client.CloseAsync(WebSocketCloseStatus.NormalClosure, "EOF", _tokenSource.Token);
WebSocketMessageType pckType = WebSocketMessageType.Binary;
do
{
read = await stream.ReadAsync(buffer, offset, bufLen);
lastFrame = read < Yavsc.Constants.WebSocketsMaxBufLen;
ArraySegment<byte> segment = new ArraySegment<byte>(buffer, offset, read);
await _client.SendAsync(new ArraySegment<byte>(buffer), pckType, lastFrame, _tokenSource.Token);
_logger.LogInformation($"sent {segment.Count} ");
} while (!lastFrame);
_logger.LogInformation($"Closing socket");
await _client.CloseAsync(WebSocketCloseStatus.NormalClosure, "EOF", _tokenSource.Token);
}
}
}
}

View file

@ -13,15 +13,9 @@ namespace cli.Helpers
return commander.Integrate(rootApp);
}
static OAuthenticator OAuthorInstance { get; set; }
public static OAuthenticator OAuthorInstance { get; private set; }
public static OAuthenticator InitAuthor(
this ConnectionSettings settings,
string clientId,
string clientSecret,
string scope,
string authorizeUrl,
string redirectUrl,
string accessTokenUrl)
this ConnectionSettings settings)
{
return OAuthorInstance = new OAuthenticator(settings.ClientId,
settings.ClientSecret,
@ -71,4 +65,4 @@ namespace cli.Helpers
}
}
}

View file

@ -6,7 +6,7 @@ using Microsoft.Extensions.Configuration;
namespace Yavsc.Server
{
public class cliServerFactory : IServerFactory
public class CliServerFactory : IServerFactory
{
public IFeatureCollection Initialize(IConfiguration configuration)
{

View file

@ -65,23 +65,27 @@ namespace cli
var services = new ServiceCollection();
// create a service provider with the HostEnvironment.
HostingEnvironment = new HostingEnvironment();
HostingEnvironment.EnvironmentName = appEnv.Configuration;
HostingEnvironment = new HostingEnvironment
{
EnvironmentName = appEnv.Configuration
};
var startup = new Startup(HostingEnvironment, appEnv);
startup.ConfigureServices(services);
services.AddInstance<IHostingEnvironment>(HostingEnvironment);
var serviceProvider = services.BuildServiceProvider();
var app = new ApplicationBuilder(serviceProvider);
app.ApplicationServices = serviceProvider;
var app = new ApplicationBuilder(serviceProvider)
{
ApplicationServices = serviceProvider
};
var siteSettings = serviceProvider.GetRequiredService<IOptions<SiteSettings>>();
var cxSettings = serviceProvider.GetRequiredService<IOptions<ConnectionSettings>>();
var userCxSettings = serviceProvider.GetRequiredService<IOptions<UserConnectionSettings>>();
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
startup.Configure(app, HostingEnvironment, siteSettings, cxSettings, userCxSettings, loggerFactory);
startup.Configure(cxSettings, userCxSettings, loggerFactory);
return app;
}
@ -95,12 +99,14 @@ namespace cli
[STAThread]
public static int Main(string[] args)
{
CommandLineApplication cliapp = new CommandLineApplication(false);
cliapp.Name = "cli";
cliapp.FullName = "Yavsc command line interface";
cliapp.Description = "Dnx console app for yavsc server side";
cliapp.ShortVersionGetter = () => "v1.0";
cliapp.LongVersionGetter = () => "version 1.0 (stable)";
CommandLineApplication cliapp = new CommandLineApplication(false)
{
Name = "cli",
FullName = "Yavsc command line interface",
Description = "Dnx console app for yavsc server side",
ShortVersionGetter = () => "v1.0",
LongVersionGetter = () => "version 1.0 (stable)"
};
// calling a Startup sequence
var appBuilder = ConfigureApplication();

View file

@ -26,13 +26,12 @@ namespace cli.Services
const string DefaultBaseClassName = "ATemplate";
const string DefaultBaseClass = nameof(UserOrientedTemplate);
const string DefaultNamespace = "CompiledRazorTemplates";
RazorTemplateEngine razorEngine;
IStringLocalizer<EMailer> stringLocalizer;
ILogger logger;
ApplicationDbContext dbContext;
IEmailSender mailSender;
RazorEngineHost host;
readonly RazorTemplateEngine razorEngine;
readonly IStringLocalizer<EMailer> stringLocalizer;
readonly ILogger logger;
readonly ApplicationDbContext dbContext;
readonly IEmailSender mailSender;
readonly RazorEngineHost host;
public EMailer(ApplicationDbContext context, IEmailSender sender, IStringLocalizer<EMailer> localizer, ILoggerFactory loggerFactory)
{

View file

@ -7,9 +7,9 @@ namespace cli.Services
public class MvcGenerator : CommandLineGenerator
{
CommandLineGeneratorModel _model;
ILogger _logger;
public MvcGenerator (IServiceProvider services, ILoggerFactory loggerFactory): base (services)
readonly CommandLineGeneratorModel _model;
readonly ILogger _logger;
public MvcGenerator(IServiceProvider services, ILoggerFactory loggerFactory) : base(services)
{
_model = new CommandLineGeneratorModel();
_logger = loggerFactory.CreateLogger<MvcGenerator>();
@ -17,7 +17,6 @@ namespace cli.Services
public async void Generate(
string modelClass,
string ns,
string dbContextFullName,
string controllerName,
string relativeFolderPath
@ -33,4 +32,4 @@ namespace cli.Services
await GenerateCode(_model);
}
}
}
}

View file

@ -250,8 +250,7 @@ Microsoft.Extensions.CodeGeneration.ICodeGeneratorActionsService),
Services = services;
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
IOptions<SiteSettings> siteSettings,
public void Configure(
IOptions<ConnectionSettings> cxSettings,
IOptions<UserConnectionSettings> useCxSettings,
ILoggerFactory loggerFactory)

View file

@ -45,7 +45,7 @@
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-rc1-final",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
"Newtonsoft.Json": "6.0.1-beta1",
"Newtonsoft.Json": "7.0.1",
"NJsonSchema.CodeGeneration.CSharp": "10.0.27",
"Yavsc": {
"target": "project"