[WONT RUN] RazorEngine
This commit is contained in:
parent
1a9fc24ba9
commit
5f188c99a8
7 changed files with 292 additions and 9237 deletions
|
|
@ -1,22 +0,0 @@
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNet.Builder;
|
|
||||||
using Microsoft.AspNet.Hosting;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
|
|
||||||
public class InteractiveConsoleMiddleWare
|
|
||||||
{
|
|
||||||
public InteractiveConsoleMiddleWare(RequestDelegate next)
|
|
||||||
{
|
|
||||||
_next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
readonly RequestDelegate _next;
|
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context, IHostingEnvironment hostingEnviroment)
|
|
||||||
{
|
|
||||||
//do something
|
|
||||||
System.Console.WriteLine("kjhnlkhkl");
|
|
||||||
await _next.Invoke(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
7
cli/Modules/IModule.cs
Normal file
7
cli/Modules/IModule.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace cli.Modules
|
||||||
|
{
|
||||||
|
public interface IModule
|
||||||
|
{
|
||||||
|
void Run (string[] args);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
cli/Modules/MonthlyEMailGenerator.cs
Normal file
29
cli/Modules/MonthlyEMailGenerator.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using RazorEngine.Templating;
|
||||||
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Services;
|
||||||
|
|
||||||
|
namespace cli.Modules
|
||||||
|
{
|
||||||
|
public class MonthlyEMailGenerator : IModule
|
||||||
|
{
|
||||||
|
IRazorEngineService engine;
|
||||||
|
IEmailSender emailSender;
|
||||||
|
|
||||||
|
ApplicationDbContext dbContext;
|
||||||
|
public MonthlyEMailGenerator(ApplicationDbContext context, IRazorEngineService res, IEmailSender sender)
|
||||||
|
{
|
||||||
|
dbContext = context;
|
||||||
|
engine = res;
|
||||||
|
emailSender = sender;
|
||||||
|
// engine.AddTemplate(new Tem)
|
||||||
|
}
|
||||||
|
public void Run(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Hello from second module using {engine}");
|
||||||
|
string template = "Hello @Model.Name, welcome to RazorEngine!";
|
||||||
|
var result = engine.RunCompile(template, "templateKey", null, new { Name = "World" });
|
||||||
|
Console.WriteLine(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
cli/Modules/MyGenerator.cs
Normal file
25
cli/Modules/MyGenerator.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using RazorEngine.Configuration;
|
||||||
|
using RazorEngine.Templating;
|
||||||
|
|
||||||
|
namespace cli.Modules
|
||||||
|
{
|
||||||
|
public class MyGenerator : IModule
|
||||||
|
{
|
||||||
|
|
||||||
|
ILogger logger;
|
||||||
|
public MyGenerator(ILoggerFactory loggerfactory)
|
||||||
|
{
|
||||||
|
logger = loggerfactory.CreateLogger<MyGenerator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run(string[] args)
|
||||||
|
{
|
||||||
|
logger.LogInformation(nameof(MyGenerator));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using Google.Apis.Util.Store;
|
using Google.Apis.Util.Store;
|
||||||
using Microsoft.AspNet.Builder.Internal;
|
|
||||||
using Microsoft.AspNet.Hosting;
|
|
||||||
using Microsoft.AspNet.Hosting.Builder;
|
|
||||||
using Microsoft.AspNet.Hosting.Internal;
|
|
||||||
using Microsoft.AspNet.Server;
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Identity.EntityFramework;
|
using Microsoft.AspNet.Identity.EntityFramework;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.OptionsModel;
|
using Microsoft.Extensions.OptionsModel;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using Yavsc;
|
using Yavsc;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
|
|
||||||
|
|
@ -25,18 +15,25 @@ using cli_2;
|
||||||
using Yavsc.Server.Helpers;
|
using Yavsc.Server.Helpers;
|
||||||
using Microsoft.AspNet.Identity;
|
using Microsoft.AspNet.Identity;
|
||||||
using Microsoft.Data.Entity;
|
using Microsoft.Data.Entity;
|
||||||
using Newtonsoft.Json;
|
using cli.Modules;
|
||||||
|
using RazorEngine.Configuration;
|
||||||
|
using RazorEngine.Templating;
|
||||||
|
using System.Security.Policy;
|
||||||
|
using System.Security;
|
||||||
|
using System.Security.Permissions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Collections;
|
||||||
|
using RazorEngine;
|
||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
private IServiceProvider serviceProvider;
|
private static IServiceProvider serviceProvider;
|
||||||
public string ConnectionString
|
public string ConnectionString
|
||||||
{
|
{
|
||||||
get { return DbHelpers.ConnectionString; }
|
get { return DbHelpers.ConnectionString; }
|
||||||
private set { DbHelpers.ConnectionString = value; }
|
private set { DbHelpers.ConnectionString = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static SiteSettings SiteSetup { get; private set; }
|
public static SiteSettings SiteSetup { get; private set; }
|
||||||
public static SmtpSettings SmtpSettup { get; private set; }
|
public static SmtpSettings SmtpSettup { get; private set; }
|
||||||
public IConfigurationRoot Configuration { get; set; }
|
public IConfigurationRoot Configuration { get; set; }
|
||||||
|
|
@ -52,31 +49,24 @@ public class Program
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IHostingEnvironment hosting = new HostingEnvironment { EnvironmentName = environmentName };
|
|
||||||
if (hosting.IsDevelopment())
|
|
||||||
{
|
|
||||||
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
|
|
||||||
// builder.AddUserSecrets();
|
|
||||||
}
|
|
||||||
|
|
||||||
var confbuilder = new ConfigurationBuilder()
|
var confbuilder = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appsettings.json")
|
.AddJsonFile("appsettings.json")
|
||||||
.AddJsonFile($"appsettings.{hosting.EnvironmentName}.json", optional: true);
|
.AddJsonFile($"appsettings.{environmentName}.json", optional: true);
|
||||||
|
|
||||||
confbuilder.AddEnvironmentVariables();
|
|
||||||
Configuration = confbuilder.Build();
|
Configuration = confbuilder.Build();
|
||||||
|
|
||||||
|
|
||||||
var siteSettingsconf = Configuration.GetSection("Site");
|
var siteSettingsconf = Configuration.GetSection("Site");
|
||||||
services.Configure<SiteSettings>(siteSettingsconf);
|
services.Configure<SiteSettings>(siteSettingsconf);
|
||||||
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
||||||
services.Configure<SmtpSettings>(smtpSettingsconf);
|
services.Configure<SmtpSettings>(smtpSettingsconf);
|
||||||
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IHostingEnvironment), hosting));
|
|
||||||
|
|
||||||
|
services.AddTransient(typeof(IModule), typeof(MonthlyEMailGenerator));
|
||||||
|
// services.AddTransient( typeof(Microsoft.AspNet.Mvc.Razor.Compilation.ICompilationService), typeof (Microsoft.AspNet.Mvc.Razor.Compilation.RazorCompilationService) );
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
|
|
||||||
|
// services.AddTransient(typeof(Microsoft.AspNet.Mvc.Razor.Compilation.IRazorCompilationService), typeof(Microsoft.AspNet.Mvc.Razor.Compilation.RazorCompilationService));
|
||||||
|
|
||||||
|
|
||||||
services.AddEntityFramework()
|
services.AddEntityFramework()
|
||||||
.AddNpgsql()
|
.AddNpgsql()
|
||||||
|
|
@ -140,12 +130,24 @@ public class Program
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddIdentity<ApplicationUser, IdentityRole>();
|
services.AddIdentity<ApplicationUser, IdentityRole>();
|
||||||
|
|
||||||
|
// Razor
|
||||||
|
|
||||||
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
// FIXME null ref var appName = AppDomain.CurrentDomain.ApplicationIdentity.FullName;
|
// FIXME null ref var appName = AppDomain.CurrentDomain.ApplicationIdentity.FullName;
|
||||||
|
|
||||||
// var rtdcontext = new WindowsRuntimeDesignerContext (new string [] { "../Yavsc" }, "Yavsc");
|
|
||||||
|
|
||||||
|
var config = new TemplateServiceConfiguration();
|
||||||
|
// TODO .. configure your instance
|
||||||
|
|
||||||
|
// config.DisableTempFileLocking = true; // loads the files in-memory (gives the templates full-trust permissions)
|
||||||
|
// config.CachingProvider = new DefaultCachingProvider(t => { }); //disables the warnings
|
||||||
|
// Use the config
|
||||||
|
var razorService = RazorEngineService.Create(config);
|
||||||
|
Engine.Razor = razorService;
|
||||||
|
services.AddInstance(typeof(IRazorEngineService), razorService);
|
||||||
|
|
||||||
|
// Razor.SetTemplateService(new TemplateService(config)); // legacy API
|
||||||
serviceProvider = services.BuildServiceProvider();
|
serviceProvider = services.BuildServiceProvider();
|
||||||
|
|
||||||
//configure console logging
|
//configure console logging
|
||||||
|
|
@ -158,7 +160,6 @@ public class Program
|
||||||
|
|
||||||
var projectRoot = "/home/paul/workspace/yavsc/Yavsc";
|
var projectRoot = "/home/paul/workspace/yavsc/Yavsc";
|
||||||
|
|
||||||
hosting.Initialize(projectRoot, null);
|
|
||||||
|
|
||||||
var targetFramework = new FrameworkName("dnx", new Version(4, 5, 1));
|
var targetFramework = new FrameworkName("dnx", new Version(4, 5, 1));
|
||||||
//
|
//
|
||||||
|
|
@ -168,15 +169,11 @@ public class Program
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ApplicationBuilderFactory applicationBuilderFactory
|
|
||||||
= new ApplicationBuilderFactory(serviceProvider);
|
|
||||||
|
|
||||||
var builder = applicationBuilderFactory.CreateBuilder(null);
|
|
||||||
|
|
||||||
ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"];
|
ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"];
|
||||||
|
|
||||||
|
|
||||||
logger.LogInformation($"cx: {ConnectionString} ({hosting.EnvironmentName})");
|
logger.LogInformation($"cx: {ConnectionString} ({environmentName})");
|
||||||
|
|
||||||
var sitesetupjson = Configuration.GetSection("Site");
|
var sitesetupjson = Configuration.GetSection("Site");
|
||||||
services.Configure<SiteSettings>(sitesetupjson);
|
services.Configure<SiteSettings>(sitesetupjson);
|
||||||
|
|
@ -184,27 +181,28 @@ public class Program
|
||||||
var smtpsetupjson = Configuration.GetSection("Smtp");
|
var smtpsetupjson = Configuration.GetSection("Smtp");
|
||||||
services.Configure<SmtpSettings>(smtpsetupjson);
|
services.Configure<SmtpSettings>(smtpsetupjson);
|
||||||
|
|
||||||
builder.ApplicationServices = serviceProvider;
|
|
||||||
|
|
||||||
logger.LogInformation(Configuration["Site:Title"]);
|
|
||||||
//logger.LogInformation(Configuration["Smtp"]);
|
|
||||||
IOptions<SiteSettings> siteSettings = serviceProvider.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
IOptions<SiteSettings> siteSettings = serviceProvider.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||||
IOptions<SmtpSettings> smtpSettings = serviceProvider.GetService(typeof(IOptions<SmtpSettings>)) as IOptions<SmtpSettings>;
|
IOptions<SmtpSettings> smtpSettings = serviceProvider.GetService(typeof(IOptions<SmtpSettings>)) as IOptions<SmtpSettings>;
|
||||||
|
|
||||||
|
|
||||||
SiteSetup = siteSettings.Value;
|
SiteSetup = siteSettings.Value;
|
||||||
SmtpSettup = smtpSettings.Value;
|
SmtpSettup = smtpSettings.Value;
|
||||||
|
|
||||||
logger.LogInformation($"done with {SiteSetup.Title}");
|
logger.LogInformation($"done with {SiteSetup.Title} config.");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ILoggerFactory loggerFactory = serviceProvider.GetService<ILoggerFactory>();
|
||||||
|
var logger = loggerFactory.CreateLogger<Program>();
|
||||||
|
logger.LogInformation("Hello.");
|
||||||
|
var mods = serviceProvider.GetServices<IModule>();
|
||||||
|
foreach (var mod in mods) {
|
||||||
|
logger.LogInformation($"running {mod.GetType().Name}");
|
||||||
|
mod.Run(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,37 @@
|
||||||
{
|
{
|
||||||
"version": "1.0.0-*",
|
"version": "1.0.0-*",
|
||||||
"commands": {
|
"commands": {
|
||||||
"run": "cli"
|
"run": "cli"
|
||||||
|
},
|
||||||
|
"resource": "Resources/**/*.resx",
|
||||||
|
"buildOptions": {
|
||||||
|
"debugType": "full",
|
||||||
|
"emitEntryPoint": true,
|
||||||
|
"compile": {
|
||||||
|
"include": "*.cs",
|
||||||
|
"exclude": [
|
||||||
|
"contrib"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"resource": "Resources/**/*.resx",
|
"embed": [
|
||||||
"buildOptions": {
|
"Resources/**/*.resx"
|
||||||
"debugType": "full",
|
]
|
||||||
"emitEntryPoint": true,
|
},
|
||||||
"compile": {
|
"dependencies": {
|
||||||
"include": "*.cs",
|
"Yavsc.Server": {
|
||||||
"exclude": [
|
"target": "project",
|
||||||
"contrib"
|
"type": "build"
|
||||||
]
|
|
||||||
},
|
|
||||||
"embed": [
|
|
||||||
"Resources/**/*.resx"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
|
||||||
"Yavsc.Server": {
|
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
|
||||||
"target": "project",
|
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
|
||||||
"type": "build"
|
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
|
||||||
},
|
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
|
||||||
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
|
"RazorEngine": "4.5.1-alpha001",
|
||||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
|
"Microsoft.CodeAnalysis.CSharp": "2.8.0-beta3"
|
||||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
|
},
|
||||||
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-*",
|
"frameworks": {
|
||||||
"Microsoft.AspNet.Hosting": "1.0.0-rc1-*",
|
"dnx451": {},
|
||||||
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
|
"net451": {}
|
||||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final"
|
}
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"dnx451": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"net451": {
|
|
||||||
"dependencies": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue