From d1b0f5e6d98c7fc4bdc493a5450555795d154b0e Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 8 Jun 2025 14:41:50 +0100 Subject: [PATCH] bump sdk to net-9 --- .vscode/settings.json | 1 + global.json | 6 - src/Yavsc.Abstract/Templates/Template.cs | 2 - .../Models/EMailing/MailingTemplate.cs | 12 +- src/Yavsc.Server/Services/EMailer.cs | 174 ---------------- .../Services/YavscTemplateEngine.cs | 171 ++++++++++++++++ .../Templates/UserOrientedTemplate.cs | 5 +- src/cli/.paul-ci.json | 20 -- src/cli/Commands/SendMailCommand.cs | 15 +- src/cli/Makefile | 27 --- src/cli/Misc/YavscServerFactory.cs | 23 --- src/cli/Program.cs | 143 +------------ src/cli/Program.old.cs | 136 +++++++++++++ src/cli/Services/EMailer.cs | 191 ------------------ src/cli/Services/YaRazorEngineHost.cs | 4 +- src/cli/Startup.cs | 33 +-- src/cli/TODO.md | 7 - src/cli/cli.csproj | 24 +++ src/cli/cli.nuspec | 22 -- src/cli/jsonSchema | 96 --------- src/cli/package.json | 4 - src/cli/packages.config | 64 ------ src/cli/paul-ci.shema.json | 96 --------- src/cli/project.json | 70 ------- src/cli/yarn.lock | 8 - test/yavscTests/BaseTestContext.cs | 11 +- test/yavscTests/Makefile | 41 ---- test/yavscTests/Startup.cs | 2 +- test/yavscTests/YavscServerFactory.cs | 23 --- test/yavscTests/yavscTests.csproj | 8 +- 30 files changed, 372 insertions(+), 1067 deletions(-) delete mode 100644 global.json delete mode 100644 src/Yavsc.Server/Services/EMailer.cs create mode 100644 src/Yavsc.Server/Services/YavscTemplateEngine.cs delete mode 100644 src/cli/.paul-ci.json delete mode 100644 src/cli/Makefile delete mode 100644 src/cli/Misc/YavscServerFactory.cs create mode 100644 src/cli/Program.old.cs delete mode 100644 src/cli/Services/EMailer.cs delete mode 100644 src/cli/TODO.md create mode 100644 src/cli/cli.csproj delete mode 100644 src/cli/cli.nuspec delete mode 100644 src/cli/jsonSchema delete mode 100644 src/cli/package.json delete mode 100644 src/cli/packages.config delete mode 100644 src/cli/paul-ci.shema.json delete mode 100644 src/cli/project.json delete mode 100644 src/cli/yarn.lock delete mode 100644 test/yavscTests/Makefile delete mode 100644 test/yavscTests/YavscServerFactory.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index 32c21b1f..bc1f86d8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "dotnet-test-explorer.testProjectPath": "**/*Tests.@(csproj|vbproj|fsproj)", "sqltools.connections": [ { "previewLimit": 50, diff --git a/global.json b/global.json deleted file mode 100644 index 030b02f6..00000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "sdk": { - "runtime": "dotnet", - "version": "8.0.405" - } -} diff --git a/src/Yavsc.Abstract/Templates/Template.cs b/src/Yavsc.Abstract/Templates/Template.cs index 24377661..ee1a8c8b 100644 --- a/src/Yavsc.Abstract/Templates/Template.cs +++ b/src/Yavsc.Abstract/Templates/Template.cs @@ -26,8 +26,6 @@ namespace Yavsc.Abstract.Templates public virtual void Init() { _buffer = new StringBuilder(); } - - public abstract Task ExecuteAsync(); } } diff --git a/src/Yavsc.Server/Models/EMailing/MailingTemplate.cs b/src/Yavsc.Server/Models/EMailing/MailingTemplate.cs index 956242dd..71e773d8 100644 --- a/src/Yavsc.Server/Models/EMailing/MailingTemplate.cs +++ b/src/Yavsc.Server/Models/EMailing/MailingTemplate.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using RazorEngine.Templating; using Yavsc.Attributes.Validation; using Yavsc.Models; using Yavsc.Models.Calendar; @@ -8,7 +9,7 @@ using Yavsc.Server.Models.Calendar; namespace Yavsc.Server.Models.EMailing { - public class MailingTemplate : ITrackedEntity + public class MailingTemplate : ITrackedEntity, ITemplateSource { /// /// Date Created @@ -41,7 +42,6 @@ namespace Yavsc.Server.Models.EMailing [EmailAddress()] public string ReplyToAddress { get; set; } - public Periodicity ToSend { get; set; } public string UserCreated @@ -55,5 +55,13 @@ namespace Yavsc.Server.Models.EMailing get; set; } + + public string Template => Body; + public string TemplateFile { get => Id; } + + public TextReader GetTemplateReader() + { + return new StringReader(Body); + } } } diff --git a/src/Yavsc.Server/Services/EMailer.cs b/src/Yavsc.Server/Services/EMailer.cs deleted file mode 100644 index 879af225..00000000 --- a/src/Yavsc.Server/Services/EMailer.cs +++ /dev/null @@ -1,174 +0,0 @@ -using System.Text; -// // EMailer.cs -// /* -// paul 26/06/2018 12:18 20182018 6 26 -// */ -using Yavsc.Templates; -using Microsoft.CodeAnalysis; -using Microsoft.Extensions.Localization; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; - -using Yavsc.Models; -using Yavsc.Services; -using System.Reflection; -using Yavsc.Abstract.Templates; -using Microsoft.AspNetCore.Identity; -using RazorEngine.Configuration; -using Yavsc.Interface; -using Microsoft.Extensions.Logging; - -namespace Yavsc.Lib -{ - public class EMailer - { - const string DefaultBaseClassName = "ATemplate"; - const string DefaultBaseClass = nameof(UserOrientedTemplate); - ISet Namespaces = new System.Collections.Generic.HashSet { - "System", - "Yavsc.Templates" , - "Yavsc.Models", - "Yavsc.Models.Identity"}; - - readonly IStringLocalizer stringLocalizer; - readonly ApplicationDbContext dbContext; - - readonly ILogger logger; - - public EMailer(ApplicationDbContext context, - IStringLocalizer localizer, - ILoggerFactory loggerFactory) - { - stringLocalizer = localizer; - - logger = loggerFactory.CreateLogger(); - - - var templateServiceConfig = new TemplateServiceConfiguration() - { - BaseTemplateType = typeof(UserOrientedTemplate), - Language = RazorEngine.Language.CSharp, - Namespaces = Namespaces - - }; - - } - - public void SendMonthlyEmail(string 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); - var templatekey = RazorEngine.Engine.Razor.GetKey(templateInfo.Id); - - - 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 - using (var rzcode = new MemoryStream()) - { - using (var writter = new StreamWriter(rzcode)) - { - RazorEngine.Engine.Razor.Run(templatekey, writter); - rzcode.Seek(0, SeekOrigin.Begin); - - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(Encoding.Default.GetString(rzcode.ToArray())); - - - logger.LogInformation("CSharp parsed"); - List references = new List(); - - 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 = "EMailSenderTemplate"; - 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) - { - - IEnumerable 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 - { - - ms.Seek(0, SeekOrigin.Begin); - Assembly assembly = Assembly.Load(ms.ToArray()); - - Type type = assembly.GetType(Namespaces + "." + className); - var generatedtemplate = (UserOrientedTemplate)Activator.CreateInstance(type); - 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); - } - - } - } - } - - } - } - } - } -} diff --git a/src/Yavsc.Server/Services/YavscTemplateEngine.cs b/src/Yavsc.Server/Services/YavscTemplateEngine.cs new file mode 100644 index 00000000..9b29d853 --- /dev/null +++ b/src/Yavsc.Server/Services/YavscTemplateEngine.cs @@ -0,0 +1,171 @@ +using System.Text; +// // EMailer.cs +// /* +// paul 26/06/2018 12:18 20182018 6 26 +// */ +using Yavsc.Templates; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.Localization; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Emit; + +using Yavsc.Models; +using Yavsc.Services; +using System.Reflection; +using Yavsc.Abstract.Templates; +using Microsoft.AspNetCore.Identity; +using RazorEngine.Configuration; +using Yavsc.Interface; +using Microsoft.Extensions.Logging; +using System.Diagnostics; +using RazorEngine.Compilation.ImpromptuInterface.Optimization; +using RazorEngine.Compilation.ImpromptuInterface; + +namespace Yavsc.Lib +{ + public class YavscTemplateEngine + { + ISet Namespaces = new System.Collections.Generic.HashSet { + "System", + "Yavsc.Templates" , + "Yavsc.Models", + "Yavsc.Models.Identity"}; + + readonly IStringLocalizer stringLocalizer; + readonly ApplicationDbContext dbContext; + + readonly ILogger logger; + + public YavscTemplateEngine(ApplicationDbContext dbContext, + IStringLocalizer localizer, + ILoggerFactory loggerFactory) + { + stringLocalizer = localizer; + this.dbContext = dbContext; + + logger = loggerFactory.CreateLogger(); + } + + public string RunUserTemplate(string templateCode) + { + + string subtemp = stringLocalizer["MonthlySubjectTemplate"].Value; + + logger.LogInformation($"Generating SendMonthlyEmail {templateCode}"); + + + var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode); + Debug.Assert (templateInfo != null); + var templatekey = RazorEngine.Engine.Razor.GetKey(templateInfo.Id); + + logger.LogInformation($"Using code: {templateCode}, subject: {subtemp} "); + logger.LogInformation("And body:\n" + templateInfo.Body); + + + // Generate code for the template + using (var inMemoryCsharpCode = new MemoryStream()) + { + using (var writter = new StreamWriter(inMemoryCsharpCode)) + { + RazorEngine.Engine.Razor.Run(templatekey, writter); + inMemoryCsharpCode.Seek(0, SeekOrigin.Begin); + + SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(Encoding.Default.GetString(inMemoryCsharpCode.ToArray())); + + logger.LogInformation("CSharp parsed"); + List references = new List(); + + 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 = "EMailSenderTemplate"; + CSharpCompilation compilation = CSharpCompilation.Create( + assemblyName, + syntaxTrees: new[] { syntaxTree }, + references: references, + options: compilationOptions + ); + + using (var inMemoryAssembly = new MemoryStream()) + { + logger.LogInformation("Emitting result ..."); + EmitResult result = compilation.Emit(inMemoryAssembly); + 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) + { + + IEnumerable 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()); + } + return null; + } + else + { + foreach (var user in dbContext.ApplicationUser.Where( + u => u.AllowMonthlyEmail + )) + { + + var template = result.CallActLike(user); + return template.GeneratedText; + } + +/* result.CallActLike<> + + inMemoryAssembly.Seek(0, SeekOrigin.Begin); + Assembly assembly = Assembly.Load(inMemoryAssembly.ToArray()); + // UserOrientedTemplate userOrientedTemplate = (UserOrientedTemplate) + // FIXME Activator.CreateInstance(Type.GetType(templateInfo.TemplateType)); + + foreach (var user in dbContext.ApplicationUser.Where( + u => u.AllowMonthlyEmail + )) + { + logger.LogInformation("Generation for " + user.UserName); + userOrientedTemplate.Init(); + userOrientedTemplate.User = user; */ + throw new NotImplementedException(); + + } + } + } + } + return null; + } + } +} diff --git a/src/Yavsc.Server/Templates/UserOrientedTemplate.cs b/src/Yavsc.Server/Templates/UserOrientedTemplate.cs index 6d3f50d4..43ceb532 100644 --- a/src/Yavsc.Server/Templates/UserOrientedTemplate.cs +++ b/src/Yavsc.Server/Templates/UserOrientedTemplate.cs @@ -5,8 +5,11 @@ using Yavsc.Models; namespace Yavsc.Templates { - public abstract class UserOrientedTemplate: Template + public class UserOrientedTemplate: Template { public ApplicationUser User { get; set; } + } + + } diff --git a/src/cli/.paul-ci.json b/src/cli/.paul-ci.json deleted file mode 100644 index b28431a2..00000000 --- a/src/cli/.paul-ci.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "env": [], - "build" :{ - - }, - "prepare": { - "make": {} - }, - "post_build": { - "yavsc": { - "type": "make", - "source" : { - "github": "pazof/yavsc", - "branch": "vnext" - }, - "args": [] - } - }, - "emails": [] -} diff --git a/src/cli/Commands/SendMailCommand.cs b/src/cli/Commands/SendMailCommand.cs index 80c3ab75..3002ddaf 100644 --- a/src/cli/Commands/SendMailCommand.cs +++ b/src/cli/Commands/SendMailCommand.cs @@ -11,6 +11,13 @@ namespace cli { public class SendMailCommandProvider : ICommander { + EMailer emailer; + private ILogger logger; + public SendMailCommandProvider(EMailer emailer, ILoggerFactory loggerFactory) + { + this.emailer = emailer; + this.logger = loggerFactory.CreateLogger(); + } public CommandLineApplication Integrate(CommandLineApplication rootApp) { CommandArgument critCommandArg = null; @@ -40,12 +47,10 @@ namespace cli .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.SendEmailFromCriteria(critCommandArg.Value); + emailer.SendEmailFromCriteria(critCommandArg.Value); logger.LogInformation("Finished emailling"); } else diff --git a/src/cli/Makefile b/src/cli/Makefile deleted file mode 100644 index 4c3765e5..00000000 --- a/src/cli/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -SOURCE_DIR=../.. -MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make -MSBUILD=msbuild - -all: $(BINTARGETPATH) - -include $(MAKEFILE_DIR)/dnx.mk - -# makes version -include $(MAKEFILE_DIR)/versioning.mk - -msbuild-restore: - $(MSBUILD) $(PRJNAME).csproj /t:Restore - -check: run - -: project.lock.json - @dnu build --configuration=$(CONFIGURATION) - -run: $(BINTARGETPATH) - ASPNET_ENV=$(ASPNET_ENV) dnx --configuration=$(CONFIGURATION) run send monthly - -info: - @echo $(PRJNAME) : $(BINTARGETPATH) $(version) - -# Due to NJsonSchema.CodeGeneration.CSharp package: -.PHONY: $(BINTARGETPATH) diff --git a/src/cli/Misc/YavscServerFactory.cs b/src/cli/Misc/YavscServerFactory.cs deleted file mode 100644 index 06d2a31a..00000000 --- a/src/cli/Misc/YavscServerFactory.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.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 application) - { - var task = application(serverFeatures); - return task; - } - } -} diff --git a/src/cli/Program.cs b/src/cli/Program.cs index dff12e13..3751555c 100644 --- a/src/cli/Program.cs +++ b/src/cli/Program.cs @@ -1,141 +1,2 @@ - -using System; -using System.Runtime.Versioning; -using cli.Commands; -using Microsoft.AspNetCore.Builder.Internal; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Dnx.Runtime; -using Microsoft.Extensions.CommandLineUtils; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.OptionsModel; -using Microsoft.Extensions.PlatformAbstractions; -using Newtonsoft.Json; -using Yavsc; - -namespace cli -{ - public class CliAppEnv : IApplicationEnvironment - { - public CliAppEnv(IApplicationEnvironment defaultEnv) - { - var envAppVar = Environment.GetEnvironmentVariable("ASPNET_ENV"); - Configuration = envAppVar ?? defaultEnv.Configuration; - ApplicationName = defaultEnv.ApplicationName; - ApplicationVersion = defaultEnv.ApplicationVersion; - ApplicationBasePath = defaultEnv.ApplicationBasePath; - RuntimeFramework = defaultEnv.RuntimeFramework; - } - public string ApplicationName { get; private set; } - - public string ApplicationVersion { get; private set; } - - public string ApplicationBasePath { get; private set; } - - public string Configuration { get; private set; } - - public FrameworkName RuntimeFramework { get; private set; } - - public object GetData(string name) - { - throw new NotImplementedException(); - } - - public void SetData(string name, object value) - { - throw new NotImplementedException(); - } - } - public partial class Program - { - private static IApplicationEnvironment appEnv; - public static IHostingEnvironment HostingEnvironment { get; private set; } - - public Program() - { - appEnv = new CliAppEnv(PlatformServices.Default.Application); - } - - /// - /// Initializes the application by - /// - private static ApplicationBuilder ConfigureApplication() - { - AppDomain.CurrentDomain.UnhandledException += OnUnHandledException; - - var services = new ServiceCollection(); - // create a service provider with the HostEnvironment. - HostingEnvironment = new HostingEnvironment - { - EnvironmentName = appEnv.Configuration - }; - - var startup = new Startup(HostingEnvironment, appEnv); - startup.ConfigureServices(services); - services.AddInstance(HostingEnvironment); - var serviceProvider = services.BuildServiceProvider(); - - var app = new ApplicationBuilder(serviceProvider) - { - ApplicationServices = serviceProvider - }; - - var siteSettings = serviceProvider.GetRequiredService>(); - var cxSettings = serviceProvider.GetRequiredService>(); - var userCxSettings = serviceProvider.GetRequiredService>(); - var loggerFactory = serviceProvider.GetRequiredService(); - - startup.Configure(cxSettings, userCxSettings, loggerFactory); - - return app; - } - - private static void OnUnHandledException(object sender, UnhandledExceptionEventArgs e) - { - Console.WriteLine("Unhandled Exception occured:"); - Console.WriteLine(JsonConvert.SerializeObject(e.ExceptionObject)); - } - - [STAThread] - public static int Main(string[] args) - { - 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(); - var loggerFactory = appBuilder.ApplicationServices.GetRequiredService(); - var cxSettings = appBuilder.ApplicationServices.GetRequiredService>(); - var usercxSettings = appBuilder.ApplicationServices.GetRequiredService>(); - - CommandOption rootCommandHelpOption = cliapp.HelpOption("-? | -h | --help"); - - new SendMailCommandProvider().Integrate(cliapp); - new GenerateJsonSchema().Integrate(cliapp); - new AuthCommander(loggerFactory).Integrate(cliapp); - new GenerationCommander().Integrate(cliapp); - new Streamer(loggerFactory, cxSettings, usercxSettings ).Integrate(cliapp); - new UserListCleanUp().Integrate(cliapp); - - if (args.Length == 0) - { - cliapp.ShowHint(); - return -1; - } - var result = cliapp.Execute(args); - - if (cliapp.RemainingArguments.Count > 0) - { - cliapp.ShowHint(); - return -1; - } - return result; - } - } -} +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/src/cli/Program.old.cs b/src/cli/Program.old.cs new file mode 100644 index 00000000..80bbcf0d --- /dev/null +++ b/src/cli/Program.old.cs @@ -0,0 +1,136 @@ + +using System; +using System.Runtime.Versioning; +using cli.Commands; +using Microsoft.Extensions.CommandLineUtils; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using Yavsc; + +namespace cli +{ + public class CliAppEnv : IApplicationEnvironment + { + public CliAppEnv(IApplicationEnvironment defaultEnv) + { + var envAppVar = Environment.GetEnvironmentVariable("ASPNET_ENV"); + Configuration = envAppVar ?? defaultEnv.Configuration; + ApplicationName = defaultEnv.ApplicationName; + ApplicationVersion = defaultEnv.ApplicationVersion; + ApplicationBasePath = defaultEnv.ApplicationBasePath; + RuntimeFramework = defaultEnv.RuntimeFramework; + } + public string ApplicationName { get; private set; } + + public string ApplicationVersion { get; private set; } + + public string ApplicationBasePath { get; private set; } + + public string Configuration { get; private set; } + + public FrameworkName RuntimeFramework { get; private set; } + + public object GetData(string name) + { + throw new NotImplementedException(); + } + + public void SetData(string name, object value) + { + throw new NotImplementedException(); + } + } + public partial class Program + { + private static IApplicationEnvironment appEnv; + public static IHostingEnvironment HostingEnvironment { get; private set; } + + public Program() + { + appEnv = new CliAppEnv(PlatformServices.Default.Application); + } + + /// + /// Initializes the application by + /// + private static ApplicationBuilder ConfigureApplication() + { + AppDomain.CurrentDomain.UnhandledException += OnUnHandledException; + + var services = new ServiceCollection(); + // create a service provider with the HostEnvironment. + HostingEnvironment = new HostingEnvironment + { + EnvironmentName = appEnv.Configuration + }; + + var startup = new Startup(HostingEnvironment, appEnv); + startup.ConfigureServices(services); + services.AddInstance(HostingEnvironment); + var serviceProvider = services.BuildServiceProvider(); + + var app = new ApplicationBuilder(serviceProvider) + { + ApplicationServices = serviceProvider + }; + + var siteSettings = serviceProvider.GetRequiredService>(); + var cxSettings = serviceProvider.GetRequiredService>(); + var userCxSettings = serviceProvider.GetRequiredService>(); + var loggerFactory = serviceProvider.GetRequiredService(); + + startup.Configure(cxSettings, userCxSettings, loggerFactory); + + return app; + } + + private static void OnUnHandledException(object sender, UnhandledExceptionEventArgs e) + { + Console.WriteLine("Unhandled Exception occured:"); + Console.WriteLine(JsonConvert.SerializeObject(e.ExceptionObject)); + } + + [STAThread] + public static int Main(string[] args) + { + 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(); + var loggerFactory = appBuilder.ApplicationServices.GetRequiredService(); + var cxSettings = appBuilder.ApplicationServices.GetRequiredService>(); + var usercxSettings = appBuilder.ApplicationServices.GetRequiredService>(); + var emailer = appBuilder.ApplicationServices.GetService(); + CommandOption rootCommandHelpOption = cliapp.HelpOption("-? | -h | --help"); + + new SendMailCommandProvider().Integrate(cliapp); + new GenerateJsonSchema().Integrate(cliapp); + new AuthCommander(loggerFactory).Integrate(cliapp); + new GenerationCommander().Integrate(cliapp); + new Streamer(loggerFactory, cxSettings, usercxSettings ).Integrate(cliapp); + new UserListCleanUp().Integrate(cliapp); + + if (args.Length == 0) + { + cliapp.ShowHint(); + return -1; + } + var result = cliapp.Execute(args); + + if (cliapp.RemainingArguments.Count > 0) + { + cliapp.ShowHint(); + return -1; + } + return result; + } + } +} diff --git a/src/cli/Services/EMailer.cs b/src/cli/Services/EMailer.cs deleted file mode 100644 index a2625658..00000000 --- a/src/cli/Services/EMailer.cs +++ /dev/null @@ -1,191 +0,0 @@ -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.AspNetCore.Razor; -using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using Microsoft.AspNetCore.Identity.EntityFramework; - -using Yavsc.Models; -using Yavsc.Templates; -using Yavsc.Abstract.Templates; -using Yavsc.Services; -using Yavsc.Abstract.Manage; -using Yavsc.Server.Settings; - -namespace cli.Services -{ - public class NoMaillingTemplateException : Exception - { - public NoMaillingTemplateException(string templateCode) : base ($"No template found under id {templateCode}.") - { - - } - } - - public class EMailer - { - const string DefaultBaseClassName = "ATemplate"; - const string DefaultBaseClass = nameof(UserOrientedTemplate); - const string DefaultNamespace = "CompiledRazorTemplates"; - readonly RazorTemplateEngine razorEngine; - readonly IStringLocalizer stringLocalizer; - readonly ILogger logger; - readonly ApplicationDbContext dbContext; - readonly IEmailSender mailSender; - readonly RazorEngineHost host; - - public EMailer(ApplicationDbContext context, IEmailSender sender, IStringLocalizer localizer, ILoggerFactory loggerFactory) - { - stringLocalizer = localizer; - mailSender = sender; - - logger = loggerFactory.CreateLogger(); - - 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 SendEmailFromCriteria(string templateCode) - { - string className = "GeneratedTemplate"; - - string subtemp = stringLocalizer["MonthlySubjectTemplate"].Value; - - Func criteria = UserPolicies.Criterias[templateCode]; - - logger.LogInformation($"Generating {subtemp}[{className}]"); - - var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode); - - if (templateInfo==null) throw new NoMaillingTemplateException(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 references = new List(); - - 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 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 => criteria(u) - )) - { - 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}"); - } - } - } - } - } - } -} diff --git a/src/cli/Services/YaRazorEngineHost.cs b/src/cli/Services/YaRazorEngineHost.cs index 6686a035..3d29812a 100644 --- a/src/cli/Services/YaRazorEngineHost.cs +++ b/src/cli/Services/YaRazorEngineHost.cs @@ -2,9 +2,9 @@ namespace cli { - public class YaRazorEngineHost: RazorEngineHost + public class YaRazorEngineHost { - public YaRazorEngineHost(): base() + public YaRazorEngineHost() { } } diff --git a/src/cli/Startup.cs b/src/cli/Startup.cs index 95f70edc..62651b1d 100644 --- a/src/cli/Startup.cs +++ b/src/cli/Startup.cs @@ -1,34 +1,10 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.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 Microsoft.Dnx.Compilation; + using Yavsc; -using Yavsc.Models; -using Yavsc.Services; using cli.Services; using cli.Settings; -using Microsoft.Extensions.CodeGeneration; -using Microsoft.Dnx.Runtime.Compilation; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Compilation.Caching; -using Microsoft.Dnx.Host; -using System.IO; using System.Runtime.Versioning; -using System; -using System.Collections.Generic; -using Microsoft.Extensions.CodeGeneration.EntityFramework; -using System.Linq; using Newtonsoft.Json; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFramework; +using Microsoft.Extensions.DependencyInjection; namespace cli { @@ -43,15 +19,14 @@ namespace cli public static UserConnectionSettings UserConnectionSettings { get; set; } - public static IConfiguration Configuration { get; set; } + public static string HostingFullName { get; private set; } - public static IServiceCollection Services { get; private set; } public static string EnvironmentName { get; private set; } public static Microsoft.Extensions.Logging.ILogger Logger { get; private set; } - public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) + public Startup() { var devtag = env.IsDevelopment() ? "D" : ""; var prodtag = env.IsProduction() ? "P" : ""; diff --git a/src/cli/TODO.md b/src/cli/TODO.md deleted file mode 100644 index 7bb80d84..00000000 --- a/src/cli/TODO.md +++ /dev/null @@ -1,7 +0,0 @@ -# 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 - - diff --git a/src/cli/cli.csproj b/src/cli/cli.csproj new file mode 100644 index 00000000..fadd679b --- /dev/null +++ b/src/cli/cli.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + + + diff --git a/src/cli/cli.nuspec b/src/cli/cli.nuspec deleted file mode 100644 index b20d8679..00000000 --- a/src/cli/cli.nuspec +++ /dev/null @@ -1,22 +0,0 @@ - - - - cli - Yavsc - cli - $version$ - Paul Schneider - Paul Schneider - https://github.com/pazof/yavsc/blob/vnext/LICENSE - https://github.com/pazof/yavsc/blob/vnext/README.md - http://pschneider.fr:84/images/yavsc.png - true - A command line interface to Yavsc server API's - - - - - - - - - diff --git a/src/cli/jsonSchema b/src/cli/jsonSchema deleted file mode 100644 index 570e54ed..00000000 --- a/src/cli/jsonSchema +++ /dev/null @@ -1,96 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "CiBuildSettings", - "type": "object", - "additionalProperties": false, - "required": [ - "build" - ], - "properties": { - "env": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "build": { - "minLength": 1, - "oneOf": [ - { - "$ref": "#/definitions/Command" - } - ] - }, - "prepare": { - "oneOf": [ - { - "type": "null" - }, - { - "$ref": "#/definitions/Command" - } - ] - }, - "post_build": { - "oneOf": [ - { - "type": "null" - }, - { - "$ref": "#/definitions/Command" - } - ] - }, - "emails": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - } - }, - "definitions": { - "Command": { - "type": "object", - "additionalProperties": false, - "required": [ - "path" - ], - "properties": { - "path": { - "type": "string", - "minLength": 1 - }, - "args": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "env": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "working_dir": { - "type": [ - "null", - "string" - ] - } - } - } - } -} diff --git a/src/cli/package.json b/src/cli/package.json deleted file mode 100644 index 9664f260..00000000 --- a/src/cli/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "dependencies": { - } -} diff --git a/src/cli/packages.config b/src/cli/packages.config deleted file mode 100644 index 2038bc1c..00000000 --- a/src/cli/packages.config +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/cli/paul-ci.shema.json b/src/cli/paul-ci.shema.json deleted file mode 100644 index 570e54ed..00000000 --- a/src/cli/paul-ci.shema.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "CiBuildSettings", - "type": "object", - "additionalProperties": false, - "required": [ - "build" - ], - "properties": { - "env": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "build": { - "minLength": 1, - "oneOf": [ - { - "$ref": "#/definitions/Command" - } - ] - }, - "prepare": { - "oneOf": [ - { - "type": "null" - }, - { - "$ref": "#/definitions/Command" - } - ] - }, - "post_build": { - "oneOf": [ - { - "type": "null" - }, - { - "$ref": "#/definitions/Command" - } - ] - }, - "emails": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - } - }, - "definitions": { - "Command": { - "type": "object", - "additionalProperties": false, - "required": [ - "path" - ], - "properties": { - "path": { - "type": "string", - "minLength": 1 - }, - "args": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "env": { - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "working_dir": { - "type": [ - "null", - "string" - ] - } - } - } - } -} diff --git a/src/cli/project.json b/src/cli/project.json deleted file mode 100644 index b01c462f..00000000 --- a/src/cli/project.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "version": "1.0.6-*", - "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-beta5", - "Microsoft.Extensions.CodeGenerators.Mvc": "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": "7.0.1", - "NJsonSchema.CodeGeneration.CSharp": "10.0.27", - "Yavsc": { - "target": "project" - }, - "Microsoft.Dnx.Host": "1.0.0-rc1-final", - "Microsoft.Dnx.Runtime": "1.0.0-rc1-final", - "Microsoft.Dnx.DesignTimeHost": "1.0.0-rc1-final", - "YamlDotNet": "8.0.0" - }, - "frameworks": { - "dnx451": { - "System.Net": {}, - "System.Xml": {} - } - }, - "scripts": { - "postrestore": [ - "grep -v '\\.\\.dll' project.lock.json > new.project.lock.json", - "mv new.project.lock.json project.lock.json" - ] - } -} diff --git a/src/cli/yarn.lock b/src/cli/yarn.lock deleted file mode 100644 index d76b894e..00000000 --- a/src/cli/yarn.lock +++ /dev/null @@ -1,8 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -entities@^1.1.1: - version "1.1.2" - resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56" - integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== diff --git a/test/yavscTests/BaseTestContext.cs b/test/yavscTests/BaseTestContext.cs index 734738e1..92a5ec48 100644 --- a/test/yavscTests/BaseTestContext.cs +++ b/test/yavscTests/BaseTestContext.cs @@ -1,25 +1,18 @@ -using System; -using Microsoft.Dnx.Compilation.CSharp; + using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.PlatformAbstractions; -using Xunit.Abstractions; namespace yavscTests { public class BaseTestContext { - protected IApplicationEnvironment applicationEnvironment = null; protected IServiceProvider serviceProvider = null; protected IConfigurationRoot configurationRoot; - protected BeforeCompileContext beforeCompileContext; protected IServiceProvider provider; protected IConfigurationRoot configuration; - protected readonly ITestOutputHelper _output; protected ServerSideFixture _serverFixture; - public BaseTestContext(ITestOutputHelper output, ServerSideFixture serverFixture) + public BaseTestContext( ServerSideFixture serverFixture) { - this._output = output; this._serverFixture = serverFixture; } } diff --git a/test/yavscTests/Makefile b/test/yavscTests/Makefile deleted file mode 100644 index f034fdbf..00000000 --- a/test/yavscTests/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -CONFIGURATION=Debug -BINTARGET=bin/$(CONFIGURATION)/dnx451/test.dll -SOURCE_DIR=../.. -MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make -MSBUILD=msbuild -YAVSCSRC=../../src - -all: test - -include $(MAKEFILE_DIR)/dnx.mk - -$(YAVSCSRC)/Yavsc/bin/$(CONFIGURATION)/dnx451/Yavsc.dll: - make -C $(YAVSCSRC)/Yavsc - -$(YAVSCSRC)/Yavsc.Abstract/bin/$(CONFIGURATION)/dnx451/Yavsc.Abstract.dll: - make -C $(YAVSCSRC)/Yavsc.Abstract - -$(YAVSCSRC)/Yavsc.Server/bin/$(CONFIGURATION)/dnx451/Yavsc.Server.dll: - make -C $(YAVSCSRC)/Yavsc.Server - -$(BINTARGET): project.lock.json $(YAVSCSRC)/Yavsc/bin/$(CONFIGURATION)/dnx451/Yavsc.dll $(YAVSCSRC)/Yavsc.Abstract/bin/$(CONFIGURATION)/dnx451/Yavsc.Abstract.dll $(YAVSCSRC)/Yavsc.Server/bin/$(CONFIGURATION)/dnx451/Yavsc.Server.dll - dnu build --configuration $(CONFIGURATION) - -non-regression: $(BINTARGET) - ASPNET_ENV=Development dnx test -maxthreads 1 -trait regression=non - -all-tests: $(BINTARGET) - ASPNET_ENV=Testing dnx test -maxthreads 1 - -regression: $(BINTARGET) - ASPNET_ENV=Testing dnx test -maxthreads 1 -trait regression=oui - -test: all-tests - -testdev: $(BINTARGET) - ASPNET_ENV=Development dnx test -maxthreads 1 -trait dev=wip - -clean: - rm -rf bin obj testingrepo - -.PHONY: test diff --git a/test/yavscTests/Startup.cs b/test/yavscTests/Startup.cs index 24f01beb..63f4e04a 100644 --- a/test/yavscTests/Startup.cs +++ b/test/yavscTests/Startup.cs @@ -64,7 +64,7 @@ namespace yavscTests public static string ApiKey { get; private set; } - public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) + public Startup(IHostingEnvironment env) { var devtag = env.IsDevelopment() ? "D" : ""; var prodtag = env.IsProduction() ? "P" : ""; diff --git a/test/yavscTests/YavscServerFactory.cs b/test/yavscTests/YavscServerFactory.cs deleted file mode 100644 index 06d2a31a..00000000 --- a/test/yavscTests/YavscServerFactory.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.AspNetCore.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 application) - { - var task = application(serverFeatures); - return task; - } - } -} diff --git a/test/yavscTests/yavscTests.csproj b/test/yavscTests/yavscTests.csproj index b80b61b8..511520f3 100644 --- a/test/yavscTests/yavscTests.csproj +++ b/test/yavscTests/yavscTests.csproj @@ -8,10 +8,12 @@ - - - + + + + +