Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Program.cs « BrowserDebugHost « wasm « sdks - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: faaa4960c586d1bb94f27aac544f0acacb858e40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace WebAssembly.Net.Debugging
{
	public class ProxyOptions {
		public Uri DevToolsUrl { get; set; } = new Uri ("http://localhost:9222");
	}

	public class TestHarnessOptions : ProxyOptions {
		public string ChromePath { get; set; }
		public string AppPath { get; set; }
		public string PagePath { get; set; }
		public string NodeApp { get; set; }
	}

	public class Program {
		public static void Main(string[] args)
		{
			var host = new WebHostBuilder()
				.UseSetting ("UseIISIntegration", false.ToString ())
				.UseKestrel ()
				.UseContentRoot (Directory.GetCurrentDirectory())
				.UseStartup<Startup> ()
				.ConfigureAppConfiguration ((hostingContext, config) =>
				{
					config.AddCommandLine(args);
				})
				.UseUrls ("http://localhost:9300")
				.Build ();

			host.Run ();
		}
	}

	public class TestHarnessProxy {
		static IWebHost host;
		static Task hostTask;
		static CancellationTokenSource cts = new CancellationTokenSource ();
		static object proxyLock = new object ();

		public static readonly Uri Endpoint = new Uri ("http://localhost:9400");

		public static Task Start (string chromePath, string appPath, string pagePath)
		{
			lock (proxyLock) {
				if (host != null)
					return hostTask;

				host = WebHost.CreateDefaultBuilder ()
					.UseSetting ("UseIISIntegration", false.ToString ())
					.ConfigureAppConfiguration ((hostingContext, config) => {
						config.AddEnvironmentVariables (prefix: "WASM_TESTS_");
					})
					.ConfigureServices ((ctx, services) => {
						services.Configure<TestHarnessOptions> (ctx.Configuration);
						services.Configure<TestHarnessOptions> (options => {
							options.ChromePath = options.ChromePath ?? chromePath;
							options.AppPath = appPath;
							options.PagePath = pagePath;
							options.DevToolsUrl = new Uri ("http://localhost:0");
						});
					})
					.UseStartup<TestHarnessStartup> ()
					.UseUrls (Endpoint.ToString ())
					.Build();
				hostTask = host.StartAsync (cts.Token);
			}

			Console.WriteLine ("WebServer Ready!");
			return hostTask;
		}
	}
}