public override void Dispose(ChromiumProcessManager p) { // Nothing to do }
/// <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"));
public override Task WaitForExitAsync(ChromiumProcessManager p) => Task.FromException(InvalidOperation("wait for exit"));
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; } }
/// <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) { }
public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) { Exited.EnterFrom(p, this); return(Task.CompletedTask); }
public override Task KillAsync(ChromiumProcessManager p) => WaitForExitAsync(p);
/// <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;
public override Task KillAsync(ChromiumProcessManager p) => Killing.EnterFromAsync(p, this);
public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => WaitForExitAsync(p);
public Task EnterFromAsync(ChromiumProcessManager p, State fromState, TimeSpan timeout) => !TryEnter(p, fromState) ? p._currentState.ExitAsync(p, timeout) : ExitAsync(p, timeout);
protected override void Leave(ChromiumProcessManager p) => LogProcessCount(p, Interlocked.Decrement(ref _processCount));
public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);
/// <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"));
public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Task.CompletedTask;
/// <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"));
public override Task KillAsync(ChromiumProcessManager p) => Task.CompletedTask;
/// <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);
public override Task WaitForExitAsync(ChromiumProcessManager p) => Task.CompletedTask;
public override Task StartAsync(ChromiumProcessManager p) => Starting.EnterFromAsync(p, this);
public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => throw new ObjectDisposedException(p.ToString());
public override Task KillAsync(ChromiumProcessManager p) { Exited.EnterFrom(p, this); return(Task.CompletedTask); }
public override Task KillAsync(ChromiumProcessManager p) => throw new ObjectDisposedException(p.ToString());
public override Task StartAsync(ChromiumProcessManager p) => p._startCompletionSource.Task;
public override void Dispose(ChromiumProcessManager p) { p._startCompletionSource.TrySetException(new ObjectDisposedException(p.ToString())); base.Dispose(p); }