public LauncherConnection(TestApp app, Stream stream, IServerConnection connection, ApplicationLauncher launcher) : base(app, stream, connection) { this.launcher = launcher; }
public static async Task <TestServer> LaunchApplication(TestApp app, IPortableEndPoint address, ApplicationLauncher launcher, LauncherOptions options, CancellationToken cancellationToken) { var support = DependencyInjector.Get <IServerHost> (); var connection = await support.Listen(address, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); var sb = new StringBuilder(); if (options != null) { if (options.Category != null) { sb.AppendFormat("--category={0} ", options.Category); } if (options.Features != null) { sb.AppendFormat("--features={0} ", options.Features); } } if (!string.IsNullOrWhiteSpace(app.PackageName)) { sb.AppendFormat("--package-name={0} ", app.PackageName); } sb.AppendFormat("connect {0}:{1}", address.Address, address.Port); var process = await launcher.LaunchApplication(sb.ToString(), cancellationToken); var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); cts.CancelAfter(60000); bool launcherError = false; var launcherTask = process.WaitForExit(cts.Token).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { launcherError = true; cts.Cancel(); } }); Stream stream; try { stream = await connection.Open(cts.Token); cts.Token.ThrowIfCancellationRequested(); } catch { if (launcherError || launcherTask.IsCanceled || cts.IsCancellationRequested) { throw new LauncherErrorException("Launcher exited abnormally before establishing connection."); } throw; } var launcherConnection = new LauncherConnection(app, stream, connection, process); var client = new Client(app, launcherConnection); await client.Initialize(cancellationToken); cts.Token.ThrowIfCancellationRequested(); return(client); }