private void ProcessIncomingMessage(ConnectionResponse obj)
        {
            if (obj.Id == BrowserCloseMessageId)
            {
                return;
            }

            IFirefoxEvent param = null;

            if (obj.Params?.ValueKind == JsonValueKind.Object)
            {
                param = FirefoxProtocolTypes.ParseEvent(obj.Method, obj.Params.Value.GetRawText());
                if (param is TargetAttachedToTargetFirefoxEvent targetAttachedToTarget)
                {
                    string sessionId = targetAttachedToTarget.SessionId;
                    var    session   = new FirefoxSession(this, targetAttachedToTarget.TargetInfo.Type.ToString(), sessionId, (id, request) =>
                                                          RawSendAsync(new ConnectionRequest
                    {
                        Id        = id,
                        Method    = request.Command,
                        Params    = request,
                        SessionId = sessionId,
                    }));
                    _asyncSessions.AddItem(sessionId, session);
                }
                else if (param is TargetDetachedFromTargetFirefoxEvent targetDetachedFromTarget)
                {
                    string sessionId = targetDetachedFromTarget.SessionId;
                    if (_sessions.TryRemove(sessionId, out var session))
                    {
                        session.OnClosed(targetDetachedFromTarget.InternalName);
                    }
                }
            }

            if (obj.SessionId != null)
            {
                GetSession(obj.SessionId)?.OnMessage(obj);
            }
            else if (obj.Id.HasValue && _callbacks.TryRemove(obj.Id.Value, out var callback))
            {
                if (obj.Error != null)
                {
                    callback.TaskWrapper.TrySetException(new MessageException(callback, obj.Error));
                }
                else
                {
                    callback.TaskWrapper.TrySetResult(FirefoxProtocolTypes.ParseResponse(callback.Method, obj.Result?.GetRawText()));
                }
            }
            else if (param != null)
            {
                MessageReceived?.Invoke(this, param);
            }
        }
예제 #2
0
        private async void OnMessageReceived(object sender, IFirefoxEvent e)
        {
            switch (e)
            {
            case TargetTargetCreatedFirefoxEvent targetCreated:
                await OnTargetCreatedAsync(targetCreated).ConfigureAwait(false);

                break;

            case TargetTargetDestroyedFirefoxEvent targetDestroyed:
                OnTargetDestroyed(targetDestroyed);
                break;

            case TargetTargetInfoChangedFirefoxEvent targetInfoChanged:
                OnTargetInfoChanged(targetInfoChanged);
                break;
            }
        }
        private void OnMessageReceived(object sender, IFirefoxEvent e)
        {
            switch (e)
            {
            case NetworkRequestWillBeSentFirefoxEvent requestWillBeSent:
                OnRequestWillBeSent(requestWillBeSent);
                break;

            case NetworkResponseReceivedFirefoxEvent responseReceived:
                OnResponseReceived(responseReceived);
                break;

            case NetworkRequestFinishedFirefoxEvent requestFinished:
                OnRequestFinished(requestFinished);
                break;

            case NetworkRequestFailedFirefoxEvent requestFailed:
                OnRequestFailed(requestFailed);
                break;
            }
        }
예제 #4
0
        private void OnMessageReceived(object sender, IFirefoxEvent e)
        {
            switch (e)
            {
            case PageEventFiredFirefoxEvent pageEventFired:
                OnEventFired(pageEventFired);
                break;

            case PageFrameAttachedFirefoxEvent pageFrameAttached:
                OnFrameAttached(pageFrameAttached);
                break;

            case PageFrameDetachedFirefoxEvent pageFrameDetached:
                OnFrameDetached(pageFrameDetached);
                break;

            case PageNavigationAbortedFirefoxEvent pageNavigationAborted:
                OnNavigationAborted(pageNavigationAborted);
                break;

            case PageNavigationCommittedFirefoxEvent pageNavigationCommitted:
                OnNavigationCommitted(pageNavigationCommitted);
                break;

            case PageNavigationStartedFirefoxEvent pageNavigationStarted:
                OnNavigationStarted(pageNavigationStarted);
                break;

            case PageSameDocumentNavigationFirefoxEvent pageSameDocumentNavigation:
                OnSameDocumentNavigation(pageSameDocumentNavigation);
                break;

            case RuntimeExecutionContextCreatedFirefoxEvent runtimeExecutionContextCreated:
                OnExecutionContextCreated(runtimeExecutionContextCreated);
                break;

            case RuntimeExecutionContextDestroyedFirefoxEvent runtimeExecutionContextDestroyed:
                OnExecutionContextDestroyed(runtimeExecutionContextDestroyed);
                break;

            case PageUncaughtErrorFirefoxEvent pageUncaughtError:
                break;

            case RuntimeConsoleFirefoxEvent runtimeConsole:
                OnConsole(runtimeConsole);
                break;

            case PageDialogOpenedFirefoxEvent pageDialogOpened:
                break;

            case PageBindingCalledFirefoxEvent pageBindingCalled:
                OnBindingCalled(pageBindingCalled);
                break;

            case PageFileChooserOpenedFirefoxEvent pageFileChooserOpened:
                OnFileChooserOpened(pageFileChooserOpened);
                break;

            case PageWorkerCreatedFirefoxEvent pageWorkerCreated:
                OnWorkerCreated(pageWorkerCreated);
                break;

            case PageWorkerDestroyedFirefoxEvent pageWorkerDestroyed:
                OnWorkerDestroyed(pageWorkerDestroyed);
                break;

            case PageDispatchMessageFromWorkerFirefoxEvent pageDispatchMessageFromWorker:
                OnDispatchMessageFromWorker(pageDispatchMessageFromWorker);
                break;
            }
        }
예제 #5
0
 internal void OnMessageReceived(object sender, IFirefoxEvent e) => MessageReceived?.Invoke(this, e);