Run the correct entrypoint

This commit is contained in:
Frank A. Krueger 2018-03-13 10:05:43 -07:00
parent d4308a740d
commit c41057a634
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
2 changed files with 20 additions and 12 deletions

View File

@ -29,6 +29,7 @@ namespace Ooui.Wasm.Build.Tasks
CopyRuntime ();
LinkAssemblies ();
ExtractClientJs ();
DiscoverEntryPoint ();
GenerateHtml ();
GenerateServer ();
return true;
@ -151,6 +152,17 @@ namespace Ooui.Wasm.Build.Tasks
Log.LogMessage ($"Client JS {dest}");
}
MethodDefinition entryPoint;
void DiscoverEntryPoint ()
{
var asm = AssemblyDefinition.ReadAssembly (Assembly);
entryPoint = asm.EntryPoint;
if (entryPoint == null) {
throw new Exception ($"{Path.GetFileName (Assembly)} is missing an entry point");
}
}
void GenerateHtml ()
{
var htmlPath = Path.Combine (distPath, "index.html");
@ -158,7 +170,6 @@ namespace Ooui.Wasm.Build.Tasks
w.Write (@"<!DOCTYPE html>
<html>
<head>
<title>Ooui Wasm</title>
<meta name=""viewport"" content=""width=device-width, initial-scale=1"" />
<link rel=""stylesheet"" href=""https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"" />
<link rel=""stylesheet"" href=""https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"">
@ -167,12 +178,8 @@ namespace Ooui.Wasm.Build.Tasks
<div id=""ooui-body"" class=""container-fluid"">
<p id=""loading""><i class=""fa fa-refresh fa-spin"" style=""font-size:14px;margin-right:0.5em;""></i> Loading...</p>
</div>
<script type=""text/javascript"" src=""ooui.js""></script>
<script type=""text/javascript"">
var mainAsmName = """);
w.Write (Path.GetFileNameWithoutExtension (Assembly));
w.Write (@""";
var assemblies = [");
var head = "";
foreach (var l in linkedAsmNames) {
@ -182,8 +189,8 @@ namespace Ooui.Wasm.Build.Tasks
w.Write ('\"');
head = ",";
}
w.WriteLine (@"];
oouiWasm (mainAsmName, """", ""Program"", ""Main"", assemblies);
w.WriteLine ($@"];
oouiWasm (""{Path.GetFileNameWithoutExtension (Assembly)}"", ""{entryPoint.DeclaringType.Namespace}"", ""{entryPoint.DeclaringType.Name}"", ""{entryPoint.Name}"", assemblies);
</script>
<script async type=""text/javascript"" src=""mono.js""></script>
</body>

View File

@ -108,8 +108,9 @@ function ooui (rootElementPath) {
monitorSizeChanges (1000/10);
}
function oouiWasm (mainAsmName, mainNamspace, mainClassName, mainMethodNmae, assemblies)
function oouiWasm (mainAsmName, mainNamespace, mainClassName, mainMethodName, assemblies)
{
Module.entryPoint = { "a": mainAsmName, "n": mainNamespace, "t": mainClassName, "m": mainMethodName };
Module.assemblies = assemblies;
monitorSizeChanges (1000/30);
@ -453,15 +454,15 @@ var WebAssemblyApp = {
if (!this.ooui_ReceiveWebAssemblySessionMessageJson_method)
throw "Could not find ReceiveWebAssemblySessionMessageJson method";
this.main_module = MonoRuntime.assembly_load (mainAsmName);
this.main_module = MonoRuntime.assembly_load (Module.entryPoint.a);
if (!this.main_module)
throw "Could not find Main Module " + mainAsmName + ".dll";
throw "Could not find Main Module " + Module.entryPoint.a + ".dll";
this.main_class = MonoRuntime.find_class (this.main_module, "", "Program")
this.main_class = MonoRuntime.find_class (this.main_module, Module.entryPoint.n, Module.entryPoint.t)
if (!this.main_class)
throw "Could not find Program class in main module";
this.main_method = MonoRuntime.find_method (this.main_class, "Main", -1)
this.main_method = MonoRuntime.find_method (this.main_class, Module.entryPoint.m, -1)
if (!this.main_method)
throw "Could not find Main method";
},