Should fix use in production environment,

since it make from Yavsc and Yavsc.Abstract some nuget references.
vnext
Paul Schneider 6 years ago
parent edeecb628d
commit 1afd1df24e
9 changed files with 382 additions and 3848 deletions

@ -14,7 +14,7 @@ $(SUBDIRS):
Yavsc.Abstract-deploy:
$(MAKE) -C Yavsc.Abstract deploy-pkg VERSION=$(VERSION)
Yavsc.Abstract-deploy: Yavsc
Yavsc-deploy: Yavsc
$(MAKE) -C Yavsc deploy-pkg VERSION=$(VERSION)
Yavsc: Yavsc.Abstract-deploy

@ -16,6 +16,9 @@
<summary>
</summary>
<tags>Blog, POS, Web API</tags>
<dependencies>
<dependency id="Yavsc.Abstract" version="$version$"></dependency>
</dependencies>
</metadata>
<files>
<file src="bin/$config$/dnx451/Yavsc.dll" target="lib/portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />

@ -1,5 +1,5 @@
{
"version": "1.0.5-rc12",
"version": "1.0.5-*",
"authors": [
"Paul Schneider"
],

@ -40,11 +40,6 @@ namespace cli
.UseEnvironment("Development")
.UseServer("cli")
.UseStartup<Startup>()
.UseServices(services => {
Console.WriteLine($"> Using {services.Count} services:");
foreach (var s in services) Console.WriteLine($"> * {s.ServiceType}");
})
.Build();
var app = hostengnine.Start();
@ -53,78 +48,3 @@ namespace cli
}
}
}
namespace cli
{
public class Startup
{
public string ConnectionString
{
get { return DbHelpers.ConnectionString; }
private set { DbHelpers.ConnectionString = value; }
}
public static SiteSettings SiteSetup { get; private set; }
public static SmtpSettings SmtpSettup { 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();
}
public void ConfigureServices (IServiceCollection services)
{
services.AddOptions();
var siteSettingsconf = Configuration.GetSection("Site");
services.Configure<SiteSettings>(siteSettingsconf);
var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf);
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
services.AddTransient(typeof(IEmailSender), typeof(MessageSender));
services.AddTransient(typeof(RazorEngineHost), typeof(YaRazorEngineHost));
services.AddEntityFramework().AddNpgsql().AddDbContext<ApplicationDbContext>();
services.AddTransient((s) => new RazorTemplateEngine(s.GetService<RazorEngineHost>()));
var serviceProvider = services.BuildServiceProvider();
services.AddLogging();
services.AddTransient<EMailer>();
services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});
}
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 cxstr = Configuration["Data:DefaultConnection:ConnectionString"];
DbHelpers.ConnectionString = cxstr;
}
}
}

@ -45,7 +45,8 @@ namespace cli.Services
var language = new CSharpRazorCodeLanguage();
host = new RazorEngineHost(language) {
host = new RazorEngineHost(language)
{
DefaultBaseClass = DefaultBaseClass,
DefaultClassName = DefaultBaseClassName,
DefaultNamespace = DefaultNamespace
@ -59,53 +60,51 @@ namespace cli.Services
host.NamespaceImports.Add("Yavsc.Models.Identity");
host.NamespaceImports.Add("Microsoft.AspNet.Identity.EntityFramework");
host.InstrumentedSourceFilePath = "bin/output/approot/src/";
host.StaticHelpers=true;
host.StaticHelpers = true;
dbContext = context;
this.razorEngine = new RazorTemplateEngine(host);
}
public string GenerateTemplateObject(string baseclassName = DefaultBaseClassName)
{
throw new NotImplementedException();
}
public void AllUserGen(long templateCode, string baseclassName = DefaultBaseClassName)
{
string className = "Generated"+baseclassName;
string className = "Generated" + baseclassName;
string subtemp = stringLocalizer["MonthlySubjectTemplate"].Value;
logger.LogInformation($"Generating {subtemp}[{className}]");
var templateInfo = dbContext.MailingTemplate.FirstOrDefault (t => t.Id == templateCode);
logger.LogInformation ( $"Using code: {templateCode} and subject: {subtemp} " );
var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode);
logger.LogInformation (templateInfo.Body);
logger.LogInformation($"Using code: {templateCode} and subject: {subtemp} ");
using (StringReader reader = new StringReader(templateInfo.Body)) {
using (StringReader reader = new StringReader(templateInfo.Body))
{
// Generate code for the template
var razorResult =
razorEngine.GenerateCode(reader,className,DefaultNamespace,"fakeFileName.cs");
var razorResult = razorEngine.GenerateCode(reader, className, DefaultNamespace, "fakeFileName.cs");
logger.LogInformation("Razor exited "+(razorResult.Success?"Ok":"Ko")+".");
logger.LogInformation(razorResult.GeneratedCode);
logger.LogInformation("Razor exited " + (razorResult.Success ? "Ok" : "Ko") + ".");
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(razorResult.GeneratedCode);
string assemblyName = Path.GetRandomFileName();
MetadataReference[] references = new MetadataReference[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
MetadataReference.CreateFromFile(typeof(IdentityUser).Assembly.Location),
MetadataReference.CreateFromFile("bin/Debug/dnx451/cli.dll") ,
MetadataReference.CreateFromFile( "../Yavsc/bin/Debug/dnx451/Yavsc.dll" ),
MetadataReference.CreateFromFile( "../Yavsc.Abstract/bin/Debug/dnx451/Yavsc.Abstract.dll" )
MetadataReference.CreateFromFile( typeof(object).Assembly.Location),
MetadataReference.CreateFromFile( typeof(Enumerable).Assembly.Location),
MetadataReference.CreateFromFile( typeof(IdentityUser).Assembly.Location),
MetadataReference.CreateFromFile( typeof(ApplicationUser).Assembly.Location),
MetadataReference.CreateFromFile( typeof(Template).Assembly.Location)
};
//Microsoft.CodeAnalysis.SourceReferenceResolver resolver = new CliSourceReferenceResolver() ;
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
// .WithModuleName("Yavsc.Absctract").WithModuleName("Yavsc")
.WithModuleName("Yavsc.Absctract").WithModuleName("Yavsc")
.WithAllowUnsafe(true).WithOptimizationLevel(OptimizationLevel.Release)
.WithOutputKind(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.AnyCpu);
@ -130,6 +129,7 @@ namespace cli.Services
}
if (!result.Success)
{
logger.LogInformation(razorResult.GeneratedCode);
IEnumerable<Diagnostic> failures = result.Diagnostics.Where(diagnostic =>
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error);
@ -144,14 +144,15 @@ namespace cli.Services
ms.Seek(0, SeekOrigin.Begin);
Assembly assembly = Assembly.Load(ms.ToArray());
Type type = assembly.GetType(DefaultNamespace+"."+className);
var generatedtemplate = (UserOrientedTemplate) Activator.CreateInstance(type);
foreach (var user in dbContext.ApplicationUser) {
logger.LogInformation ("Generation for "+user.UserName);
Type type = assembly.GetType(DefaultNamespace + "." + className);
var generatedtemplate = (UserOrientedTemplate)Activator.CreateInstance(type);
foreach (var user in dbContext.ApplicationUser)
{
logger.LogInformation("Generation for " + user.UserName);
generatedtemplate.Init();
generatedtemplate.User = user;
logger.LogInformation (generatedtemplate.GeneratedText);
logger.LogInformation(generatedtemplate.GeneratedText);
}
/* ... type.InvokeMember("Write",

@ -0,0 +1,97 @@
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using System.Globalization;
using System.Reflection;
// using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
// using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Localization;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Razor;
using Microsoft.Net.Http.Headers;
using Microsoft.AspNet.Razor;
using Microsoft.Extensions.DependencyInjection.Abstractions;
using Microsoft.Extensions.PlatformAbstractions;
using cli.Services;
using Yavsc;
using Yavsc.Models;
using Yavsc.Server.Helpers;
using Yavsc.Services;
using Yavsc.Templates;
namespace cli
{
public class Startup
{
public string ConnectionString
{
get { return DbHelpers.ConnectionString; }
private set { DbHelpers.ConnectionString = value; }
}
public static SiteSettings SiteSetup { get; private set; }
public static SmtpSettings SmtpSettup { 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();
}
public void ConfigureServices (IServiceCollection services)
{
services.AddOptions();
var siteSettingsconf = Configuration.GetSection("Site");
services.Configure<SiteSettings>(siteSettingsconf);
var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf);
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
services.AddTransient(typeof(IEmailSender), typeof(MessageSender));
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";
});
}
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 cxstr = Configuration["Data:DefaultConnection:ConnectionString"];
DbHelpers.ConnectionString = cxstr;
}
}
}

@ -1,5 +1,5 @@
{
"version": "1.0.0-*",
"version": "1.0.5-*",
"commands": {
"run": "cli"
},
@ -38,10 +38,12 @@
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
"Microsoft.AspNet.Identity": "3.0.0-rc1-*",
"Yavsc": "1.0.5-rc13",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.CodeAnalysis": "1.0.0-rc1"
"Microsoft.CodeAnalysis": "1.0.0-rc1",
"EntityFramework7.Npgsql": "3.1.0-rc1-3",
"Yavsc.Abstract": { "version": "1.0.5-rc14", "target": "package" },
"Yavsc": { "version": "1.0.5-rc14", "target": "package" }
},
"frameworks": {
"dnx451": {}

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
13
14

Loading…