/// <inheritdoc cref="IBrowser.StopTracingAsync"/> public async Task <string> StopTracingAsync() { var taskWrapper = new TaskCompletionSource <string>(TaskCreationOptions.RunContinuationsAsynchronously); async void EventHandler(object sender, IChromiumEvent e) { try { if (e is TracingTracingCompleteChromiumEvent tracingTracingComplete) { string stream = tracingTracingComplete.Stream; string tracingData = await ProtocolStreamReader.ReadProtocolStreamStringAsync(_tracingClient, stream, _tracingPath).ConfigureAwait(false); _client.MessageReceived -= EventHandler; taskWrapper.TrySetResult(tracingData); } } catch (Exception ex) { string message = $"Tracing failed to process the tracing complete. {ex.Message}. {ex.StackTrace}"; System.Diagnostics.Debug.WriteLine(ex); _tracingClient.OnClosed(message); } } _tracingClient.MessageReceived += EventHandler; await _tracingClient.SendAsync(new TracingEndRequest()).ConfigureAwait(false); _tracingRecording = false; return(await taskWrapper.Task.ConfigureAwait(false)); }
private async void Client_MessageReceived(object sender, IChromiumEvent e) { try { switch (e) { case NetworkResponseReceivedChromiumEvent networkResponseReceived: OnResponseReceived(networkResponseReceived); break; case NetworkRequestWillBeSentChromiumEvent networkRequestWillBeSent: OnRequestWillBeSent(networkRequestWillBeSent); break; case FetchRequestPausedChromiumEvent fetchRequestPaused: await OnRequestPausedAsync(fetchRequestPaused).ConfigureAwait(false); break; case NetworkLoadingFinishedChromiumEvent networkLoadingFinished: OnLoadingFinished(networkLoadingFinished); break; case NetworkLoadingFailedChromiumEvent networkLoadingFailed: OnLoadingFailed(networkLoadingFailed); break; case FetchAuthRequiredChromiumEvent fetchAuthRequired: await OnAuthRequiredAsync(fetchAuthRequired).ConfigureAwait(false); break; } } catch (Exception ex) { // TODO Add Logger /* * var message = $"Page failed to process {e.MessageID}. {ex.Message}. {ex.StackTrace}"; * _logger.LogError(ex, message); */ System.Diagnostics.Debug.WriteLine(ex); _client.OnClosed(ex.ToString()); } }
private async void Client_MessageReceived(object sender, IChromiumEvent e) { try { switch (e) { case CSSStyleSheetAddedChromiumEvent cssStyleSheetAdded: await OnStyleSheetAddedAsync(cssStyleSheetAdded).ConfigureAwait(false); break; case RuntimeExecutionContextsClearedChromiumEvent _: OnExecutionContextsCleared(); break; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); _client.OnClosed(ex.ToString()); } }