Ejemplo n.º 1
0
        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);

            cancellationToken.ThrowIfCancellationRequested();

            var sb = new StringBuilder();

            sb.AppendFormat("connect {0}:{1}", address.Address, address.Port);

            if (options != null)
            {
                if (options.Category != null)
                {
                    sb.AppendFormat(" --category={0}", options.Category);
                }
                if (options.Features != null)
                {
                    sb.AppendFormat(" --features={0}", options.Features);
                }
            }

            launcher.LaunchApplication(sb.ToString());

            var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            cts.CancelAfter(90000);

            bool launcherError = false;
            var  launcherTask  = launcher.WaitForExit().ContinueWith(t => {
                if (t.IsFaulted || t.IsCanceled || !t.Result)
                {
                    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, launcher);
            var client             = new Client(app, launcherConnection);
            await client.Initialize(cancellationToken);

            cts.Token.ThrowIfCancellationRequested();

            return(client);
        }
Ejemplo n.º 2
0
 public Launcher(TestApp app, LauncherConnection connection)
     : base(app, connection)
 {
 }