Exemplo n.º 1
0
 public override void Dispose(ChromiumProcessManager p)
 {
     // Nothing to do
 }
Exemplo n.º 2
0
 /// <summary>
 /// Handles process start request.
 /// </summary>
 /// <param name="p">The Chromium process.</param>
 /// <returns>A <see cref="Task"/> that completes when the start action is done.</returns>
 public virtual Task StartAsync(ChromiumProcessManager p) => Task.FromException(InvalidOperation("start"));
Exemplo n.º 3
0
 public override Task WaitForExitAsync(ChromiumProcessManager p) => Task.FromException(InvalidOperation("wait for exit"));
Exemplo n.º 4
0
                private async Task StartCoreAsync(ChromiumProcessManager p)
                {
                    var output = new StringBuilder();

                    void OnProcessDataReceivedWhileStarting(object sender, DataReceivedEventArgs e)
                    {
                        if (e.Data != null)
                        {
                            output.AppendLine(e.Data);
                            var match = Regex.Match(e.Data, "^DevTools listening on (ws:\\/\\/.*)");
                            if (match.Success)
                            {
                                p._startCompletionSource.TrySetResult(match.Groups[1].Value);
                            }
                        }
                    }

                    void OnProcessExitedWhileStarting(object sender, EventArgs e)
                    => p._startCompletionSource.TrySetException(new MessageException($"Failed to launch Chromium! {output}"));
                    void OnProcessExited(object sender, EventArgs e) => Exited.EnterFrom(p, p._currentState);

                    p.Process.ErrorDataReceived += OnProcessDataReceivedWhileStarting;
                    p.Process.Exited            += OnProcessExitedWhileStarting;
                    p.Process.Exited            += OnProcessExited;
                    CancellationTokenSource cts = null;

                    try
                    {
                        p.Process.Start();
                        await Started.EnterFromAsync(p, this).ConfigureAwait(false);

                        p.Process.BeginErrorReadLine();

                        int timeout = p.Timeout;
                        if (timeout > 0)
                        {
                            cts = new CancellationTokenSource(timeout);
                            cts.Token.Register(() => p._startCompletionSource.TrySetException(
                                                   new MessageException($"Timed out after {timeout} ms while trying to connect to Chromium!")));
                        }

                        try
                        {
                            await p._startCompletionSource.Task.ConfigureAwait(false);

                            await Started.EnterFromAsync(p, this).ConfigureAwait(false);
                        }
                        catch
                        {
                            await Killing.EnterFromAsync(p, this).ConfigureAwait(false);

                            throw;
                        }
                    }
                    finally
                    {
                        cts?.Dispose();
                        p.Process.Exited            -= OnProcessExitedWhileStarting;
                        p.Process.ErrorDataReceived -= OnProcessDataReceivedWhileStarting;
                    }
                }
Exemplo n.º 5
0
 /// <summary>
 /// Notifies that state machine is about to transition to another state.
 /// </summary>
 /// <param name="p">The Chromium process.</param>
 protected virtual void Leave(ChromiumProcessManager p)
 {
 }
Exemplo n.º 6
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout)
 {
     Exited.EnterFrom(p, this);
     return(Task.CompletedTask);
 }
Exemplo n.º 7
0
 public override Task KillAsync(ChromiumProcessManager p) => WaitForExitAsync(p);
Exemplo n.º 8
0
 /// <summary>
 /// Handles wait for process exit request.
 /// </summary>
 /// <param name="p">The Chromium process.</param>
 /// <returns>A <see cref="Task"/> that completes when the wait finishes.</returns>
 public virtual Task WaitForExitAsync(ChromiumProcessManager p) => p._exitCompletionSource.Task;
Exemplo n.º 9
0
 public override Task KillAsync(ChromiumProcessManager p) => Killing.EnterFromAsync(p, this);
Exemplo n.º 10
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => WaitForExitAsync(p);
Exemplo n.º 11
0
 public Task EnterFromAsync(ChromiumProcessManager p, State fromState, TimeSpan timeout)
 => !TryEnter(p, fromState) ? p._currentState.ExitAsync(p, timeout) : ExitAsync(p, timeout);
Exemplo n.º 12
0
 protected override void Leave(ChromiumProcessManager p)
 => LogProcessCount(p, Interlocked.Decrement(ref _processCount));
Exemplo n.º 13
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);
Exemplo n.º 14
0
 /// <summary>
 /// Handles process exit request.
 /// </summary>
 /// <param name="p">The Chromium process.</param>
 /// <param name="timeout">The maximum waiting time for a graceful process exit.</param>
 /// <returns>A <see cref="Task"/> that completes when the exit action is done.</returns>
 public virtual Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Task.FromException(InvalidOperation("exit"));
Exemplo n.º 15
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Task.CompletedTask;
Exemplo n.º 16
0
 /// <summary>
 /// Handles process kill request.
 /// </summary>
 /// <param name="p">The Chromium process.</param>
 /// <returns>A <see cref="Task"/> that completes when the kill action is done.</returns>
 public virtual Task KillAsync(ChromiumProcessManager p) => Task.FromException(InvalidOperation("kill"));
Exemplo n.º 17
0
 public override Task KillAsync(ChromiumProcessManager p) => Task.CompletedTask;
Exemplo n.º 18
0
 /// <summary>
 /// Handles disposal of process and temporary user directory.
 /// </summary>
 /// <param name="p">Process.</param>
 public virtual void Dispose(ChromiumProcessManager p) => Disposed.EnterFrom(p, this);
Exemplo n.º 19
0
 public override Task WaitForExitAsync(ChromiumProcessManager p) => Task.CompletedTask;
Exemplo n.º 20
0
 public override Task StartAsync(ChromiumProcessManager p) => Starting.EnterFromAsync(p, this);
Exemplo n.º 21
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => throw new ObjectDisposedException(p.ToString());
Exemplo n.º 22
0
 public override Task KillAsync(ChromiumProcessManager p)
 {
     Exited.EnterFrom(p, this);
     return(Task.CompletedTask);
 }
Exemplo n.º 23
0
 public override Task KillAsync(ChromiumProcessManager p) => throw new ObjectDisposedException(p.ToString());
Exemplo n.º 24
0
 public override Task StartAsync(ChromiumProcessManager p) => p._startCompletionSource.Task;
Exemplo n.º 25
0
 public override void Dispose(ChromiumProcessManager p)
 {
     p._startCompletionSource.TrySetException(new ObjectDisposedException(p.ToString()));
     base.Dispose(p);
 }