Should fix use in production environment,
since it make from Yavsc and Yavsc.Abstract some nuget references.
This commit is contained in:
2
Makefile
2
Makefile
@ -14,7 +14,7 @@ $(SUBDIRS):
|
|||||||
Yavsc.Abstract-deploy:
|
Yavsc.Abstract-deploy:
|
||||||
$(MAKE) -C Yavsc.Abstract deploy-pkg VERSION=$(VERSION)
|
$(MAKE) -C Yavsc.Abstract deploy-pkg VERSION=$(VERSION)
|
||||||
|
|
||||||
Yavsc.Abstract-deploy: Yavsc
|
Yavsc-deploy: Yavsc
|
||||||
$(MAKE) -C Yavsc deploy-pkg VERSION=$(VERSION)
|
$(MAKE) -C Yavsc deploy-pkg VERSION=$(VERSION)
|
||||||
|
|
||||||
Yavsc: Yavsc.Abstract-deploy
|
Yavsc: Yavsc.Abstract-deploy
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
<summary>
|
<summary>
|
||||||
</summary>
|
</summary>
|
||||||
<tags>Blog, POS, Web API</tags>
|
<tags>Blog, POS, Web API</tags>
|
||||||
|
<dependencies>
|
||||||
|
<dependency id="Yavsc.Abstract" version="$version$"></dependency>
|
||||||
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files>
|
<files>
|
||||||
<file src="bin/$config$/dnx451/Yavsc.dll" target="lib/portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />
|
<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": [
|
"authors": [
|
||||||
"Paul Schneider"
|
"Paul Schneider"
|
||||||
],
|
],
|
||||||
|
@ -40,11 +40,6 @@ namespace cli
|
|||||||
.UseEnvironment("Development")
|
.UseEnvironment("Development")
|
||||||
.UseServer("cli")
|
.UseServer("cli")
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
|
|
||||||
.UseServices(services => {
|
|
||||||
Console.WriteLine($"> Using {services.Count} services:");
|
|
||||||
foreach (var s in services) Console.WriteLine($"> * {s.ServiceType}");
|
|
||||||
})
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var app = hostengnine.Start();
|
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -25,146 +25,147 @@ using Microsoft.AspNet.Identity.EntityFramework;
|
|||||||
namespace cli.Services
|
namespace cli.Services
|
||||||
{
|
{
|
||||||
|
|
||||||
public class EMailer
|
public class EMailer
|
||||||
{
|
|
||||||
RazorTemplateEngine razorEngine;
|
|
||||||
IStringLocalizer<EMailer> stringLocalizer;
|
|
||||||
ILogger logger;
|
|
||||||
ApplicationDbContext dbContext;
|
|
||||||
|
|
||||||
const string DefaultBaseClassName = "ATemplate";
|
|
||||||
const string DefaultBaseClass = nameof(UserOrientedTemplate);
|
|
||||||
const string DefaultNamespace = "CompiledRazorTemplates";
|
|
||||||
|
|
||||||
RazorEngineHost host;
|
|
||||||
public EMailer(ApplicationDbContext context, IStringLocalizer<EMailer> localizer, ILoggerFactory loggerFactory)
|
|
||||||
{
|
{
|
||||||
stringLocalizer = localizer;
|
RazorTemplateEngine razorEngine;
|
||||||
|
IStringLocalizer<EMailer> stringLocalizer;
|
||||||
logger = loggerFactory.CreateLogger<EMailer>();
|
ILogger logger;
|
||||||
|
ApplicationDbContext dbContext;
|
||||||
|
|
||||||
var language = new CSharpRazorCodeLanguage();
|
const string DefaultBaseClassName = "ATemplate";
|
||||||
|
const string DefaultBaseClass = nameof(UserOrientedTemplate);
|
||||||
host = new RazorEngineHost(language) {
|
const string DefaultNamespace = "CompiledRazorTemplates";
|
||||||
DefaultBaseClass = DefaultBaseClass,
|
|
||||||
DefaultClassName = DefaultBaseClassName,
|
|
||||||
DefaultNamespace = DefaultNamespace
|
|
||||||
};
|
|
||||||
|
|
||||||
|
RazorEngineHost host;
|
||||||
|
public EMailer(ApplicationDbContext context, IStringLocalizer<EMailer> localizer, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
stringLocalizer = localizer;
|
||||||
|
|
||||||
// Everyone needs the System namespace, right?
|
logger = loggerFactory.CreateLogger<EMailer>();
|
||||||
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 = "bin/output/approot/src/";
|
|
||||||
host.StaticHelpers=true;
|
|
||||||
dbContext = context;
|
|
||||||
|
|
||||||
this.razorEngine = new RazorTemplateEngine(host);
|
var language = new CSharpRazorCodeLanguage();
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
public void AllUserGen(long templateCode, string baseclassName = DefaultBaseClassName)
|
|
||||||
{
|
|
||||||
string className = "Generated"+baseclassName;
|
|
||||||
|
|
||||||
string subtemp = stringLocalizer["MonthlySubjectTemplate"].Value;
|
host = new RazorEngineHost(language)
|
||||||
|
|
||||||
logger.LogInformation($"Generating {subtemp}[{className}]");
|
|
||||||
var templateInfo = dbContext.MailingTemplate.FirstOrDefault (t => t.Id == templateCode);
|
|
||||||
|
|
||||||
logger.LogInformation ( $"Using code: {templateCode} and subject: {subtemp} " );
|
|
||||||
|
|
||||||
logger.LogInformation (templateInfo.Body);
|
|
||||||
|
|
||||||
using (StringReader reader = new StringReader(templateInfo.Body)) {
|
|
||||||
|
|
||||||
// Generate code for the template
|
|
||||||
var razorResult =
|
|
||||||
razorEngine.GenerateCode(reader,className,DefaultNamespace,"fakeFileName.cs");
|
|
||||||
|
|
||||||
logger.LogInformation("Razor exited "+(razorResult.Success?"Ok":"Ko")+".");
|
|
||||||
logger.LogInformation(razorResult.GeneratedCode);
|
|
||||||
|
|
||||||
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(razorResult.GeneratedCode);
|
|
||||||
|
|
||||||
|
|
||||||
string assemblyName = Path.GetRandomFileName();
|
|
||||||
MetadataReference[] references = new MetadataReference[]
|
|
||||||
{
|
{
|
||||||
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
|
DefaultBaseClass = DefaultBaseClass,
|
||||||
MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
|
DefaultClassName = DefaultBaseClassName,
|
||||||
MetadataReference.CreateFromFile(typeof(IdentityUser).Assembly.Location),
|
DefaultNamespace = DefaultNamespace
|
||||||
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" )
|
|
||||||
};
|
|
||||||
//Microsoft.CodeAnalysis.SourceReferenceResolver resolver = new CliSourceReferenceResolver() ;
|
|
||||||
|
|
||||||
|
|
||||||
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
|
// Everyone needs the System namespace, right?
|
||||||
// .WithModuleName("Yavsc.Absctract").WithModuleName("Yavsc")
|
host.NamespaceImports.Add("System");
|
||||||
.WithAllowUnsafe(true).WithOptimizationLevel(OptimizationLevel.Release)
|
host.NamespaceImports.Add("Yavsc.Templates");
|
||||||
.WithOutputKind(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.AnyCpu);
|
host.NamespaceImports.Add("Yavsc.Models");
|
||||||
|
host.NamespaceImports.Add("Yavsc.Models.Identity");
|
||||||
CSharpCompilation compilation = CSharpCompilation.Create(
|
host.NamespaceImports.Add("Microsoft.AspNet.Identity.EntityFramework");
|
||||||
assemblyName,
|
host.InstrumentedSourceFilePath = "bin/output/approot/src/";
|
||||||
syntaxTrees: new[] { syntaxTree },
|
host.StaticHelpers = true;
|
||||||
references: references,
|
dbContext = context;
|
||||||
options: compilationOptions);
|
|
||||||
|
|
||||||
|
this.razorEngine = new RazorTemplateEngine(host);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var mref in references) logger.LogInformation($"ctor used ref to {mref.Display}[{mref.Properties.Kind}]");
|
public string GenerateTemplateObject(string baseclassName = DefaultBaseClassName)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AllUserGen(long templateCode, string baseclassName = DefaultBaseClassName)
|
||||||
|
{
|
||||||
|
string className = "Generated" + baseclassName;
|
||||||
|
|
||||||
using (var ms = new MemoryStream())
|
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} ");
|
||||||
|
|
||||||
|
using (StringReader reader = new StringReader(templateInfo.Body))
|
||||||
{
|
{
|
||||||
EmitResult result = compilation.Emit(ms);
|
|
||||||
foreach (Diagnostic diagnostic in result.Diagnostics.Where(diagnostic =>
|
// Generate code for the template
|
||||||
diagnostic.Severity < DiagnosticSeverity.Error && !diagnostic.IsWarningAsError))
|
var razorResult = razorEngine.GenerateCode(reader, className, DefaultNamespace, "fakeFileName.cs");
|
||||||
|
|
||||||
|
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( typeof(ApplicationUser).Assembly.Location),
|
||||||
|
MetadataReference.CreateFromFile( typeof(Template).Assembly.Location)
|
||||||
|
};
|
||||||
|
|
||||||
|
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
|
||||||
|
.WithModuleName("Yavsc.Absctract").WithModuleName("Yavsc")
|
||||||
|
.WithAllowUnsafe(true).WithOptimizationLevel(OptimizationLevel.Release)
|
||||||
|
.WithOutputKind(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.AnyCpu);
|
||||||
|
|
||||||
|
CSharpCompilation compilation = CSharpCompilation.Create(
|
||||||
|
assemblyName,
|
||||||
|
syntaxTrees: new[] { syntaxTree },
|
||||||
|
references: references,
|
||||||
|
options: compilationOptions);
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var mref in references) logger.LogInformation($"ctor used ref to {mref.Display}[{mref.Properties.Kind}]");
|
||||||
|
|
||||||
|
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
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.GetMessage());
|
||||||
logger.LogWarning("{0}: {1}", diagnostic.Id, diagnostic.Location.GetLineSpan());
|
logger.LogWarning("{0}: {1}", diagnostic.Id, diagnostic.Location.GetLineSpan());
|
||||||
}
|
}
|
||||||
if (!result.Success)
|
if (!result.Success)
|
||||||
{
|
|
||||||
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.LogInformation(razorResult.GeneratedCode);
|
||||||
logger.LogCritical("{0}: {1}", diagnostic.Id, diagnostic.Location.GetLineSpan());
|
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
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
generatedtemplate.Init();
|
||||||
|
generatedtemplate.User = user;
|
||||||
|
|
||||||
|
logger.LogInformation(generatedtemplate.GeneratedText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ... type.InvokeMember("Write",
|
||||||
|
BindingFlags.Default | BindingFlags.InvokeMethod,
|
||||||
|
null,
|
||||||
|
model,
|
||||||
|
new object[] { "Hello World" }); */
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
generatedtemplate.Init();
|
|
||||||
generatedtemplate.User = user;
|
|
||||||
|
|
||||||
logger.LogInformation (generatedtemplate.GeneratedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ... type.InvokeMember("Write",
|
|
||||||
BindingFlags.Default | BindingFlags.InvokeMethod,
|
|
||||||
null,
|
|
||||||
model,
|
|
||||||
new object[] { "Hello World" }); */
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
97
cli/Startup.cs
Normal file
97
cli/Startup.cs
Normal file
@ -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": {
|
"commands": {
|
||||||
"run": "cli"
|
"run": "cli"
|
||||||
},
|
},
|
||||||
@ -38,12 +38,14 @@
|
|||||||
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
|
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
|
||||||
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
|
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
|
||||||
"Microsoft.AspNet.Identity": "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.DependencyInjection.Abstractions": "1.0.0-rc1-final",
|
||||||
"Microsoft.Extensions.Logging.Debug": "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": {
|
"frameworks": {
|
||||||
"dnx451": {}
|
"dnx451": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
|||||||
13
|
14
|
||||||
|
Reference in New Issue
Block a user