files tree made better.

This commit is contained in:
Paul Schneider 2019-01-01 16:28:47 +00:00
commit ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions

5
src/cli/.paul-ci.json Normal file
View file

@ -0,0 +1,5 @@
{
"build": {
}
}

View file

@ -0,0 +1,31 @@
using cli.Model;
using Microsoft.Extensions.CommandLineUtils;
namespace cli.Commands
{
public class AuthCommander : ICommander
{
public CommandLineApplication Integrate(CommandLineApplication rootApp)
{
CommandLineApplication authApp = rootApp.Command("auth",
(target) =>
{
target.FullName = "Authentication methods";
target.Description = "Login, save credentials and get authorized.";
target.HelpOption("-? | -h | --help");
var loginCommand = target.Command("login", app => {
var loginarg = app.Argument("login", "login to use", true);
app.Option( "-s | --save", "Save authentication token to file", CommandOptionType.NoValue);
app.HelpOption("-? | -h | --help");
} );
}, false);
authApp.OnExecute(()=>
{
return 0;
});
return authApp;
}
}
}

View file

@ -0,0 +1,28 @@
using cli.Model;
using Microsoft.Extensions.CommandLineUtils;
namespace cli
{
public class CiBuildCommand : ICommander
{
public CommandLineApplication Integrate(CommandLineApplication rootApp)
{
CommandLineApplication ciBuildApp = rootApp.Command("build",
(target) =>
{
target.FullName = "Build this project.";
target.Description = "Build this project, as specified in .paul-ci.json";
target.HelpOption("-? | -h | --help");
}, false);
ciBuildApp.OnExecute(()=>
{
return 0;
});
return ciBuildApp;
}
}
}

View file

@ -0,0 +1,69 @@
using Microsoft.Extensions.CommandLineUtils;
using System.Threading.Tasks;
using NJsonSchema;
using System.IO;
using cli.Model;
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 to generate a schema for.",
multipleValues: false);
}, false);
cmd.OnExecute(
async () => {
if (genargjson.Value == "jsonSchema") {
if (genargjson.Value == null)
await GenerateCiBuildSettingsSchema();
else
await GenerateCiBuildSettingsSchema(genargjson.Value);
} else {
cmd.ShowHint();
return 1;
}
return 0;
}
);
return cmd;
}
public static async Task GenerateCiBuildSettingsSchema(string outputFileName = "pauls-ci-schema.json")
{
var schema = await JsonSchema4.FromTypeAsync<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();
/* var errors = schema.Validate("{...}");
foreach (var error in errors)
Console.WriteLine(error.Path + ": " + error.Kind);
schema = await JsonSchema4.FromJsonAsync(schemaData); */
}
}
}

View file

@ -0,0 +1,55 @@
using Microsoft.AspNet.Hosting;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using cli.Services;
using cli.Model;
namespace cli {
public class SendMailCommandProvider : ICommander {
public CommandLineApplication Integrate(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;
}
}
}

View file

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using cli.Model;
using Microsoft.Extensions.CommandLineUtils;
using Yavsc.Authentication;
using static OAuth.AspNet.AuthServer.Constants;
namespace cli.Helpers
{
public static class ConsoleHelpers
{
public static CommandLineApplication Integrate(this CommandLineApplication rootApp, ICommander commander)
{
return commander.Integrate(rootApp);
}
static OAuthenticator OAuthorInstance { get; set; }
public static OAuthenticator InitAuthor(
this ConnectionSettings settings,
string clientId,
string clientSecret,
string scope,
string authorizeUrl,
string redirectUrl,
string accessTokenUrl)
{
return OAuthorInstance = new OAuthenticator(settings.ClientId,
settings.ClientSecret,
settings.Scope,
new Uri(settings.AuthorizeUrl), new Uri(settings.RedirectUrl), new Uri(settings.AccessTokenUrl));
}
public static async Task<IDictionary<string, string>> GetAuthFromPass(
string login,
string pass)
{
var query = new Dictionary<string, string>();
query[Parameters.Username] = login;
query[Parameters.Password] = pass;
query[Parameters.GrantType] = GrantTypes.Password;
return await OAuthorInstance.RequestAccessTokenAsync(query);
}
public static string GetPassword()
{
var pwd = new StringBuilder();
while (true)
{
var len = pwd.ToString().Length;
ConsoleKeyInfo i = Console.ReadKey(true);
if (i.Key == ConsoleKey.Enter)
{
break;
}
else if (i.Key == ConsoleKey.Backspace)
{
if (pwd.Length > 0)
{
pwd.Remove(len - 1, 1);
Console.Write("\b \b");
}
}
else
{
pwd.Append(i.KeyChar);
Console.Write("*");
}
}
return pwd.ToString();
}
}
}

26
src/cli/Makefile Normal file
View file

@ -0,0 +1,26 @@
SOURCE_DIR=$(HOME)/workspace/yavsc
MAKEFILE_DIR=$(SOURCE_DIR)/scripts/build/make
include $(MAKEFILE_DIR)/versioning.mk
include $(MAKEFILE_DIR)/dnx.mk
MSBUILD=msbuild
all: $(BINTARGETPATH)
msbuild-restore:
$(MSBUILD) cli.csproj /t:Restore
check: run
project.lock.json:
@# fixing package id reference case, to System.Xml, from package NJsonSchema.CodeGeneration.CSharp
sed 's/System.XML/System.Xml/' project.lock.json > project.lock.json.new && mv project.lock.json.new project.lock.json
run: $(BINTARGETPATH)
ASPNET_ENV=$(ASPNET_ENV) dnx --configuration=$(CONFIGURATION) run send monthly
info:
@echo $(PRJNAME)
# Due to NJsonSchema.CodeGeneration.CSharp package:
.PHONY: project.lock.json

View file

@ -0,0 +1,23 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Http.Features;
using Microsoft.Extensions.Configuration;
namespace Yavsc.Server
{
public class cliServerFactory : IServerFactory
{
public IFeatureCollection Initialize(IConfiguration configuration)
{
FeatureCollection featureCollection = new FeatureCollection();
return featureCollection;
}
public IDisposable Start(IFeatureCollection serverFeatures, Func<IFeatureCollection, Task> application)
{
var task = application(serverFeatures);
return task;
}
}
}

View file

@ -0,0 +1,9 @@
using Microsoft.Extensions.CommandLineUtils;
namespace cli.Model
{
public interface ICommander
{
CommandLineApplication Integrate(CommandLineApplication rootApp);
}
}

44
src/cli/Program.cs Normal file
View file

@ -0,0 +1,44 @@

using System;
using cli.Commands;
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 app for yavsc server side";
cliapp.ShortVersionGetter = () => "v1.0";
cliapp.LongVersionGetter = () => "version 1.0 (stable)";
rootCommandHelpOption = cliapp.HelpOption("-? | -h | --help");
(new SendMailCommandProvider()).Integrate(cliapp);
(new GenerateJsonSchema()).Integrate(cliapp);
(new AuthCommander()).Integrate(cliapp);
(new CiBuildCommand()).Integrate(cliapp);
if (args.Length == 0)
{
cliapp.ShowHint();
Environment.Exit(1);
}
cliapp.Execute(args);
if (cliapp.RemainingArguments.Count > 0)
{
cliapp.ShowHint();
Environment.Exit(2);
}
}
}
}

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="MonthlySubjectTemplate"><value>[{0} Monthly] {1}</value></data>
</root>

187
src/cli/Services/EMailer.cs Normal file
View file

@ -0,0 +1,187 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.AspNet.Razor;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.AspNet.Identity.EntityFramework;
using Yavsc.Models;
using Yavsc.Templates;
using Yavsc.Abstract.Templates;
using Yavsc.Services;
using Yavsc.Abstract.Manage;
namespace cli.Services
{
public class EMailer
{
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;
public EMailer(ApplicationDbContext context, IEmailSender sender, IStringLocalizer<EMailer> localizer, ILoggerFactory loggerFactory)
{
stringLocalizer = localizer;
mailSender = sender;
logger = loggerFactory.CreateLogger<EMailer>();
var language = new CSharpRazorCodeLanguage();
host = new RazorEngineHost(language)
{
DefaultBaseClass = DefaultBaseClass,
DefaultClassName = DefaultBaseClassName,
DefaultNamespace = DefaultNamespace
};
host.NamespaceImports.Add("System");
host.NamespaceImports.Add("Yavsc.Templates");
host.NamespaceImports.Add("Yavsc.Models");
host.NamespaceImports.Add("Yavsc.Models.Identity");
host.NamespaceImports.Add("Microsoft.AspNet.Identity.EntityFramework");
host.InstrumentedSourceFilePath = ".";
host.StaticHelpers = true;
dbContext = context;
razorEngine = new RazorTemplateEngine(host);
}
public void SendMonthlyEmail(long templateCode, string baseclassName = DefaultBaseClassName)
{
string className = "Generated" + baseclassName;
string subtemp = stringLocalizer["MonthlySubjectTemplate"].Value;
logger.LogInformation($"Generating {subtemp}[{className}]");
var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode);
if (templateInfo==null) throw new Exception($"No template found under id {templateCode}.");
logger.LogInformation($"Using code: {templateCode}, subject: {subtemp} ");
logger.LogInformation("And body:\n"+templateInfo.Body);
using (StringReader reader = new StringReader(templateInfo.Body))
{
// Generate code for the template
var razorResult = razorEngine.GenerateCode(reader, className, DefaultNamespace, DefaultNamespace+".cs");
logger.LogInformation("Razor exited " + (razorResult.Success ? "Ok" : "Ko") + ".");
logger.LogInformation(razorResult.GeneratedCode);
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(razorResult.GeneratedCode);
logger.LogInformation("CSharp parsed");
List<MetadataReference> references = new List<MetadataReference>();
foreach (var type in new Type[] {
typeof(object),
typeof(Enumerable),
typeof(IdentityUser),
typeof(ApplicationUser),
typeof(Template),
typeof(UserOrientedTemplate),
typeof(System.Threading.Tasks.TaskExtensions)
} )
{
var location = type.Assembly.Location;
if (!string.IsNullOrWhiteSpace(location)) {
references.Add(
MetadataReference.CreateFromFile(location)
);
logger.LogInformation($"Assembly for {type.Name} found at {location}");
} else logger.LogWarning($"Assembly Not found for {type.Name}");
}
logger.LogInformation("Compilation creation ...");
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
.WithAllowUnsafe(true).WithOptimizationLevel(OptimizationLevel.Debug)
.WithOutputKind(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.AnyCpu)
.WithUsings("Yavsc.Templates")
;
string assemblyName = DefaultNamespace;
CSharpCompilation compilation = CSharpCompilation.Create(
assemblyName,
syntaxTrees: new[] { syntaxTree },
references: references,
options: compilationOptions
);
using (var ms = new MemoryStream())
{
logger.LogInformation("Emitting result ...");
EmitResult result = compilation.Emit(ms);
foreach (Diagnostic diagnostic in result.Diagnostics.Where(diagnostic =>
diagnostic.Severity < DiagnosticSeverity.Error && !diagnostic.IsWarningAsError))
{
logger.LogWarning("{0}: {1}", diagnostic.Id, diagnostic.GetMessage());
logger.LogWarning("{0}: {1}", diagnostic.Id, diagnostic.Location.GetLineSpan());
}
if (!result.Success)
{
logger.LogInformation(razorResult.GeneratedCode);
IEnumerable<Diagnostic> failures = result.Diagnostics.Where(diagnostic =>
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error);
foreach (Diagnostic diagnostic in failures)
{
logger.LogCritical("{0}: {1}", diagnostic.Id, diagnostic.GetMessage());
logger.LogCritical("{0}: {1}", diagnostic.Id, diagnostic.Location.GetLineSpan());
}
}
else
{
logger.LogInformation(razorResult.GeneratedCode);
ms.Seek(0, SeekOrigin.Begin);
Assembly assembly = Assembly.Load(ms.ToArray());
Type type = assembly.GetType(DefaultNamespace + "." + className);
var generatedtemplate = (UserOrientedTemplate) Activator.CreateInstance(type);
if (generatedtemplate==null) {
logger.LogError("No generated template ... exiting.");
throw new InvalidOperationException("No generated template");
}
foreach (var user in dbContext.ApplicationUser.Where(
u => u.AllowMonthlyEmail
))
{
logger.LogInformation("Generation for " + user.UserName);
generatedtemplate.Init();
generatedtemplate.User = user;
generatedtemplate.ExecuteAsync();
logger.LogInformation(generatedtemplate.GeneratedText);
EmailSentViewModel mailSentInfo = this.mailSender.SendEmailAsync
(user.UserName, user.Email, $"monthly email", generatedtemplate.GeneratedText).Result;
if (mailSentInfo==null)
logger.LogError("No info on sending");
else if (!mailSentInfo.Sent)
logger.LogError($"{mailSentInfo.ErrorMessage}");
else
logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{user.UserName}");
}
}
}
}
}
}
}

View file

@ -0,0 +1,11 @@
using Microsoft.AspNet.Razor;
namespace cli
{
public class YaRazorEngineHost: RazorEngineHost
{
public YaRazorEngineHost(): base()
{
}
}
}

View file

@ -0,0 +1,71 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
public class CiBuildSettings
{
/// <summary>
/// A command specification (a system command),
/// in order to reference some trusted server-side process
/// </summary>
public class Command
{
[Required]
[JsonPropertyAttribute("path")]
public string Path { get; set; }
[JsonPropertyAttribute("args")]
public string[] Args { get; set; }
/// <summary>
/// Specific variables to this process
/// </summary>
/// <value></value>
///
[JsonPropertyAttribute("env")]
public string[] Environment { get; set; }
[JsonPropertyAttribute("working_dir")]
public string WorkingDir { get; set; }
}
/// <summary>
/// The global process environment variables
/// </summary>
/// <value></value>
[JsonPropertyAttribute("env")]
public string[] Environment { get; set; }
/// <summary>
/// The required building command.
/// </summary>
/// <value></value>
[Required]
[JsonPropertyAttribute("build")]
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>
[JsonPropertyAttribute("prepare")]
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>
[JsonPropertyAttribute("post_build")]
public Command PostBuild { get; set; }
/// <summary>
/// Additional emails, as dest of notifications
/// </summary>
/// <value></value>
[JsonPropertyAttribute("emails")]
public string[] Emails { get; set; }
}

View file

@ -0,0 +1,34 @@
namespace cli
{
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
public class ConnectionSettings
{
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string Authority { get; set; }
public string Audience { get; set; }
public string SiteAccessSheme { get; set; } = "http";
public string Scope { get; set; } = "profile";
[NotMapped]
[JsonIgnore]
public string AuthorizeUrl {get {
return $"{SiteAccessSheme}://{Authority}/authorize";
} }
[NotMapped]
[JsonIgnore]
public string RedirectUrl {get {
return $"{SiteAccessSheme}://{Authority}/oauth/success";
} }
[NotMapped]
[JsonIgnore]
public string AccessTokenUrl {get {
return $"{SiteAccessSheme}://{Authority}/token";
} }
}
}

100
src/cli/Startup.cs Normal file
View file

@ -0,0 +1,100 @@
using Microsoft.AspNet.Authentication;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Razor;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.WebEncoders;
using Yavsc;
using Yavsc.Models;
using Yavsc.Services;
using cli.Services;
namespace cli
{
public class Startup
{
public string ConnectionString
{
get ; set;
}
public static ConnectionSettings Settings { get; private set; }
public static IConfiguration Configuration { get; set; }
public static string HostingFullName { get; private set; }
ILogger logger;
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var devtag = env.IsDevelopment()?"D":"";
var prodtag = env.IsProduction()?"P":"";
var stagetag = env.IsStaging()?"S":"";
HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]";
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
Configuration = builder.Build();
ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"];
}
public void ConfigureServices (IServiceCollection services)
{
services.AddOptions();
var cxSettings = Configuration.GetSection("Connection");
services.Configure<ConnectionSettings>(cxSettings);
var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf);
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
services.AddTransient(typeof(IEmailSender), typeof(MailSender));
services.AddTransient(typeof(RazorEngineHost), typeof(YaRazorEngineHost));
services.AddEntityFramework().AddNpgsql().AddDbContext<ApplicationDbContext>();
services.AddTransient((s) => new RazorTemplateEngine(s.GetService<RazorEngineHost>()));
services.AddLogging();
services.AddTransient<EMailer>();
services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<ApplicationDbContext>(
db => db.UseNpgsql(ConnectionString)
);
services.Configure<SharedAuthenticationOptions>(options =>
{
options.SignInScheme = "Bearer";
});
services.AddTransient<Microsoft.Extensions.WebEncoders.UrlEncoder, UrlEncoder>();
services.AddAuthentication();
}
public void Configure (IApplicationBuilder app, IHostingEnvironment env,
IOptions<SiteSettings> siteSettings, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
logger = loggerFactory.CreateLogger<Startup>();
logger.LogInformation(env.EnvironmentName);
var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc");
var clientId = authConf.GetSection("ClientId").Value;
var clientSecret = authConf.GetSection("ClientSecret").Value;
}
}
}

7
src/cli/TODO.md Normal file
View file

@ -0,0 +1,7 @@
# TODO
## Refabrications
* Créer Yavsc.Client.Console et Yavsc.Client.Gui (Eto.Platform.Gtk3), en laissant un Yavsc.Client en lieu et place de ce projet

View file

@ -0,0 +1,26 @@
{
"Connection": {
"Authority": "dev.pschneider.fr",
"ClientId": "53f4d5da-93a9-4584-82f9-b8fdf243b002",
"ClientSecret": "blouh",
"Audience": "dev.pschneider.fr"
},
"Smtp": {
"Host": "127.0.0.1",
"Port": 25,
"EnableSSL": false
},
"Logging": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Debug",
"System": "Warning",
"Microsoft": "Warning"
}
},
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=localhost;Port=5432;Database=YavscDev;Username=yavscdev;Password=admin;"
}
}
}

30
src/cli/appsettings.json Normal file
View file

@ -0,0 +1,30 @@
{
"ConnectionSettings" : {
"Site": {
"Authority": "oauth.server-example.com",
"Title": "[Site title]",
"Slogan": "[Site Slogan]",
"Banner": "/images/[bannerAsset]",
"HomeViewName": "Home",
"FavIcon": "/favicon.ico",
"Icon": "/images/[Site Icon]"
},
"ServerApiKey": {
"ClientId": "[OAuth2NativeClientId]",
"ClientSecret": "[OAuth2ClientSecret]"
}
},
"Logging": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Debug",
"System": "Warning",
"Microsoft": "Warning"
}
},
"Data": {
"DefaultConnection": {
"ConnectionString": "[sbConStr]"
}
}
}

26
src/cli/cli.nuspec Normal file
View file

@ -0,0 +1,26 @@
<?xml version="1.0"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>cli</id>
<title>Yavsc - cli</title>
<version>$version$</version>
<authors>Paul Schneider</authors>
<owners>Paul Schneider</owners>
<licenseUrl>https://github.com/pazof/yavsc/blob/vnext/Yavsc/License.md</licenseUrl>
<projectUrl>https://github.com/pazof/yavsc/README.md</projectUrl>
<iconUrl>https://github.com/pazof/yavsc/blob/vnext/Yavsc/wwwroot/images/yavsc.png</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>
A command line interface to Yavsc server runtime
</description>
<summary>
</summary>
<tags>Blog, POS, Web API</tags>
<dependencies>
<dependency id="Yavsc.Server" version="$version$"></dependency>
</dependencies>
</metadata>
<files>
<file src="bin/$config$/dnx451/cli.dll" target="lib/portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />
</files>
</package>

64
src/cli/packages.config Normal file
View file

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.Server.Kestrel" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.Relational.Design" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.AspNet.Hosting" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.AspNet.Hosting.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.Core" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="EntityFramework.Relational" version="7.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="3.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc" version="6.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc.Razor" version="6.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.AspNet.Mvc.Razor.Host" version="6.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Localization" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Localization.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.CodeAnalysis.Common" version="1.1.0-rc1" targetFramework="net451" />
<package id="Microsoft.CodeAnalysis.CSharp" version="1.1.0-rc1" targetFramework="net451" />
<package id="Microsoft.Dnx.Compilation.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Dnx.Compilation.CSharp.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Dnx.Compilation.CSharp.Common" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Caching.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Caching.Memory" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.FileExtensions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.Json" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Logging" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.MemoryPool" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.OptionsModel" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.PlatformAbstractions" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Extensions.Primitives" version="1.0.0-rc1-final" targetFramework="net451" />
<package id="Microsoft.Framework.ConfigurationModel" version="1.0.0-beta4" targetFramework="net451" />
<package id="Microsoft.Framework.ConfigurationModel.Interfaces" version="1.0.0-beta4" targetFramework="net451" />
<package id="Microsoft.Framework.ConfigurationModel.Json" version="1.0.0-beta4" targetFramework="net451" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
<package id="Remotion.Linq" version="2.0.1" targetFramework="net451" />
<package id="System.Collections" version="4.0.11" targetFramework="net451" />
<package id="System.Collections.Immutable" version="1.1.37" targetFramework="net451" />
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net451" />
<package id="System.Diagnostics.DiagnosticSource" version="4.0.0-beta-23516" targetFramework="net451" />
<package id="System.Diagnostics.Tracing" version="4.0.0" targetFramework="net451" />
<package id="System.Globalization" version="4.0.11" targetFramework="net451" />
<package id="System.IO" version="4.0.0" targetFramework="net451" />
<package id="System.Linq" version="4.1.0" targetFramework="net451" />
<package id="System.Reflection" version="4.1.0" targetFramework="net451" />
<package id="System.Reflection.Extensions" version="4.0.0" targetFramework="net451" />
<package id="System.Reflection.Metadata" version="1.1.0" targetFramework="net451" />
<package id="System.Reflection.Primitives" version="4.0.0" targetFramework="net451" />
<package id="System.Resources.ResourceManager" version="4.0.1" targetFramework="net451" />
<package id="System.Runtime" version="4.0.0" targetFramework="net451" />
<package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net451" />
<package id="System.Runtime.InteropServices" version="4.1.0" targetFramework="net451" />
<package id="System.Text.Encoding" version="4.0.0" targetFramework="net451" />
<package id="System.Text.Encoding.Extensions" version="4.0.0" targetFramework="net451" />
<package id="System.Threading" version="4.0.0" targetFramework="net451" />
<package id="Yavsc.Abstract" version="1.0.5-rc9" targetFramework="net451" />
<package id="Yavsc.Server" version="1.0.5-rc9" targetFramework="net451" />
</packages>

69
src/cli/project.json Normal file
View file

@ -0,0 +1,69 @@
{
"version": "1.0.5-*",
"commands": {
"run": "run"
},
"resource": "Resources/**/*.resx",
"buildOptions": {
"debugType": "full",
"emitEntryPoint": true,
"compile": {
"include": "*.cs",
"exclude": [
"contrib"
]
},
"embed": [
"Resources/**/*.resx"
]
},
"dependencies": {
"EntityFramework7.Npgsql": "3.1.0-rc1-3",
"MailKit": "1.12.0",
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
"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",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
"Microsoft.Extensions.CommandLineUtils": "1.1.1",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.Globalization.CultureInfoCache": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.Extensions.Localization": "1.0.0-rc1-final",
"Microsoft.Extensions.Localization.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.Options": "0.0.1-alpha",
"Microsoft.Extensions.WebEncoders": "1.0.0-rc1-final",
"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": "9.0.1",
"NJsonSchema.CodeGeneration.CSharp": "9.10.65",
"Yavsc": {
"version": "1.0.5-rc22",
"target": "package"
},
"Yavsc.Abstract": {
"version": "1.0.5-rc22",
"target": "package"
},
"Yavsc.Server": {
"version": "1.0.5-rc22",
"target": "package"
},
"Yavsc.Lib.Portable": "1.0.2",
"OAuth.AspNet.AuthServer": { "target": "project" }
},
"frameworks": {
"dnx451": {
"System.Net": "4.0.0"
}
}
}