[WONT RUN] RazorEngine

vnext
Paul Schneider 7 years ago
parent 5d75f3a226
commit 7244dcd5e1
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);
}
}

@ -0,0 +1,7 @@
namespace cli.Modules
{
public interface IModule
{
void Run (string[] args);
}
}

@ -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);
}
}
}

@ -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.Runtime.Versioning;
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.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.PlatformAbstractions;
using Yavsc;
using Yavsc.Models;
@ -25,18 +15,25 @@ using cli_2;
using Yavsc.Server.Helpers;
using Microsoft.AspNet.Identity;
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
{
private IServiceProvider serviceProvider;
private static IServiceProvider serviceProvider;
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 IConfigurationRoot Configuration { get; set; }
@ -52,18 +49,10 @@ 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()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{hosting.EnvironmentName}.json", optional: true);
.AddJsonFile($"appsettings.{environmentName}.json", optional: true);
confbuilder.AddEnvironmentVariables();
Configuration = confbuilder.Build();
@ -72,11 +61,12 @@ public class Program
var smtpSettingsconf = Configuration.GetSection("Smtp");
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.AddTransient(typeof(Microsoft.AspNet.Mvc.Razor.Compilation.IRazorCompilationService), typeof(Microsoft.AspNet.Mvc.Razor.Compilation.RazorCompilationService));
services.AddEntityFramework()
.AddNpgsql()
@ -140,12 +130,24 @@ public class Program
});
services.AddIdentity<ApplicationUser, IdentityRole>();
// Razor
var basePath = AppDomain.CurrentDomain.BaseDirectory;
// 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();
//configure console logging
@ -158,7 +160,6 @@ public class Program
var projectRoot = "/home/paul/workspace/yavsc/Yavsc";
hosting.Initialize(projectRoot, null);
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"];
logger.LogInformation($"cx: {ConnectionString} ({hosting.EnvironmentName})");
logger.LogInformation($"cx: {ConnectionString} ({environmentName})");
var sitesetupjson = Configuration.GetSection("Site");
services.Configure<SiteSettings>(sitesetupjson);
@ -184,10 +181,6 @@ public class Program
var smtpsetupjson = Configuration.GetSection("Smtp");
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<SmtpSettings> smtpSettings = serviceProvider.GetService(typeof(IOptions<SmtpSettings>)) as IOptions<SmtpSettings>;
@ -195,16 +188,21 @@ public class Program
SiteSetup = siteSettings.Value;
SmtpSettup = smtpSettings.Value;
logger.LogInformation($"done with {SiteSetup.Title}");
logger.LogInformation($"done with {SiteSetup.Title} config.");
}
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);
}
}
}

@ -25,17 +25,13 @@
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-*",
"Microsoft.AspNet.Hosting": "1.0.0-rc1-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final"
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
"RazorEngine": "4.5.1-alpha001",
"Microsoft.CodeAnalysis.CSharp": "2.8.0-beta3"
},
"frameworks": {
"dnx451": {
},
"net451": {
"dependencies": {}
}
"dnx451": {},
"net451": {}
}
}

File diff suppressed because it is too large Load Diff
Loading…