rc20-alpha8
mailling [WIP]
This commit is contained in:
@ -8,6 +8,8 @@ all: $(BINTARGETPATH)
|
||||
msbuild-restore:
|
||||
$(MSBUILD) cli.csproj /t:Restore
|
||||
|
||||
check: run
|
||||
|
||||
run: project.lock.json
|
||||
ASPNET_ENV=$(ASPNET_ENV) dnx run --configuration=$(CONFIGURATION)
|
||||
|
||||
|
@ -40,9 +40,8 @@ namespace cli
|
||||
var mailer = app.Services.GetService<EMailer>();
|
||||
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger<Program>();
|
||||
mailer.AllUserGen(2,"UserOrientedTemplate");
|
||||
mailer.SendMonthlyEmail(2,"UserOrientedTemplate");
|
||||
logger.LogInformation("Finished");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
63
cli/Resources/cli.Services.EMailer.fr.resx
Normal file
63
cli/Resources/cli.Services.EMailer.fr.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="MonthlySubjectTemplate"><value>[{0} Monthly] {1}</value></data>
|
||||
|
||||
</root>
|
@ -62,7 +62,7 @@ namespace cli.Services
|
||||
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.InstrumentedSourceFilePath = ".";
|
||||
host.StaticHelpers = true;
|
||||
dbContext = context;
|
||||
razorEngine = new RazorTemplateEngine(host);
|
||||
@ -73,7 +73,7 @@ namespace cli.Services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AllUserGen(long templateCode, string baseclassName = DefaultBaseClassName)
|
||||
public void SendMonthlyEmail(long templateCode, string baseclassName = DefaultBaseClassName)
|
||||
{
|
||||
string className = "Generated" + baseclassName;
|
||||
|
||||
@ -83,37 +83,47 @@ namespace cli.Services
|
||||
|
||||
var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode);
|
||||
|
||||
logger.LogInformation($"Using code: {templateCode} and subject: {subtemp} ");
|
||||
|
||||
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, "fakeFileName.cs");
|
||||
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<MetadataReference> references = new List<MetadataReference>();
|
||||
|
||||
string assemblyName = Path.GetRandomFileName();
|
||||
MetadataReference[] references = new MetadataReference[]
|
||||
foreach (var type in new Type[] {
|
||||
typeof(object),
|
||||
typeof(Enumerable),
|
||||
typeof(IdentityUser),
|
||||
typeof(ApplicationUser),
|
||||
typeof(Template),
|
||||
typeof(UserOrientedTemplate)
|
||||
} )
|
||||
{
|
||||
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),
|
||||
MetadataReference.CreateFromFile( typeof(UserOrientedTemplate).Assembly.Location)
|
||||
};
|
||||
logger.LogInformation("typeof(Template).Assembly.Location: "+typeof(Template).Assembly.Location);
|
||||
|
||||
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.Release)
|
||||
.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 },
|
||||
@ -121,9 +131,9 @@ namespace cli.Services
|
||||
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))
|
||||
@ -151,7 +161,9 @@ namespace cli.Services
|
||||
|
||||
Type type = assembly.GetType(DefaultNamespace + "." + className);
|
||||
var generatedtemplate = (UserOrientedTemplate)Activator.CreateInstance(type);
|
||||
foreach (var user in dbContext.ApplicationUser)
|
||||
foreach (var user in dbContext.ApplicationUser.Where(
|
||||
u => u.AllowMonthlyEmail
|
||||
))
|
||||
{
|
||||
logger.LogInformation("Generation for " + user.UserName);
|
||||
generatedtemplate.Init();
|
||||
@ -160,13 +172,6 @@ namespace cli.Services
|
||||
logger.LogInformation(generatedtemplate.GeneratedText);
|
||||
}
|
||||
|
||||
/* ... type.InvokeMember("Write",
|
||||
BindingFlags.Default | BindingFlags.InvokeMethod,
|
||||
null,
|
||||
model,
|
||||
new object[] { "Hello World" }); */
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
{
|
||||
"Site": {
|
||||
"Authority": "dev.pschneider.fr",
|
||||
"Title": "Yavsc dev",
|
||||
"Slogan": "Yavsc : WIP.",
|
||||
"Banner": "/images/yavsc.png",
|
||||
"HomeViewName": "Home",
|
||||
"FavIcon": "/favicon.ico",
|
||||
"Icon": "/images/yavsc.png",
|
||||
"Owner": {
|
||||
"Name": "Paul",
|
||||
"EMail": "paul@pschneider.fr",
|
||||
"PostalAddress": {
|
||||
"Street1": "2 Blv A. Briand",
|
||||
"Street2": "Apt 284 - Bat V",
|
||||
"PostalCode": "92150",
|
||||
"City": "Suresnes",
|
||||
"State": "France",
|
||||
"Province": null
|
||||
}
|
||||
},
|
||||
"Admin": {
|
||||
"Name": "Paul",
|
||||
"EMail": "contact@pschneider.fr"
|
||||
},
|
||||
"UserFiles": {
|
||||
"Avatars": "Avatars-Dev",
|
||||
"Quota": 200000000,
|
||||
"Bills": "Bills-Dev",
|
||||
"Blog": "Blog-Dev"
|
||||
},
|
||||
"TempDir": "Temp-Dev"
|
||||
},
|
||||
"Smtp": {
|
||||
"Host": "localhost",
|
||||
"Port": 25,
|
||||
"EnableSSL": false
|
||||
},
|
||||
"Data": {
|
||||
"DefaultConnection": {
|
||||
"ConnectionString": "Server=localhost;Port=5432;Database=YavscDev;Username=yavscdev;Password=admin;"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "1.0.5-*",
|
||||
"commands": {
|
||||
"run": "cli"
|
||||
"run": "run"
|
||||
},
|
||||
"resource": "Resources/**/*.resx",
|
||||
"buildOptions": {
|
||||
@ -44,9 +44,13 @@
|
||||
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
|
||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"Yavsc": { "version": "1.0.5-rc20-alpha7", "target": "package" }
|
||||
"Yavsc": { "version": "1.0.5-rc20-alpha8", "target": "package" },
|
||||
"Yavsc.Abstract": { "version": "1.0.5-rc20-alpha8", "target": "package" },
|
||||
"Yavsc.Server": { "version": "1.0.5-rc20-alpha8", "target": "package" }
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {}
|
||||
"dnx451": {
|
||||
"System.Net": "4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user