示例#1
0
 public override void Dispose(ChromiumProcessManager p)
 {
     // Nothing to do
 }
示例#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"));
示例#3
0
 public override Task WaitForExitAsync(ChromiumProcessManager p) => Task.FromException(InvalidOperation("wait for exit"));
示例#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;
                    }
                }
示例#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)
 {
 }
示例#6
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout)
 {
     Exited.EnterFrom(p, this);
     return(Task.CompletedTask);
 }
示例#7
0
 public override Task KillAsync(ChromiumProcessManager p) => WaitForExitAsync(p);
示例#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;
示例#9
0
 public override Task KillAsync(ChromiumProcessManager p) => Killing.EnterFromAsync(p, this);
示例#10
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => WaitForExitAsync(p);
示例#11
0
 public Task EnterFromAsync(ChromiumProcessManager p, State fromState, TimeSpan timeout)
 => !TryEnter(p, fromState) ? p._currentState.ExitAsync(p, timeout) : ExitAsync(p, timeout);
示例#12
0
 protected override void Leave(ChromiumProcessManager p)
 => LogProcessCount(p, Interlocked.Decrement(ref _processCount));
示例#13
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);
示例#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"));
示例#15
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => Task.CompletedTask;
示例#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"));
示例#17
0
 public override Task KillAsync(ChromiumProcessManager p) => Task.CompletedTask;
示例#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);
示例#19
0
 public override Task WaitForExitAsync(ChromiumProcessManager p) => Task.CompletedTask;
示例#20
0
 public override Task StartAsync(ChromiumProcessManager p) => Starting.EnterFromAsync(p, this);
示例#21
0
 public override Task ExitAsync(ChromiumProcessManager p, TimeSpan timeout) => throw new ObjectDisposedException(p.ToString());
示例#22
0
 public override Task KillAsync(ChromiumProcessManager p)
 {
     Exited.EnterFrom(p, this);
     return(Task.CompletedTask);
 }
示例#23
0
 public override Task KillAsync(ChromiumProcessManager p) => throw new ObjectDisposedException(p.ToString());
示例#24
0
 public override Task StartAsync(ChromiumProcessManager p) => p._startCompletionSource.Task;
示例#25
0
 public override void Dispose(ChromiumProcessManager p)
 {
     p._startCompletionSource.TrySetException(new ObjectDisposedException(p.ToString()));
     base.Dispose(p);
 }