Esempio n. 1
0
        private void HandleCdpResponse(CdpResponse response)
        {
            if (response.IsMsgTargetPageCreated())
            {
                _cdpTargetId = response.GetStrValue("params.targetInfo.targetId");
                _logger.LogInformation($"Target Id : {_cdpTargetId}");
                Send(CdpApi.GetOpenSessionMsg(_cdpTargetId)).Wait();
                return;
            }

            if (response.IsMsgSessionCreated())
            {
                _cdpSessionId = response.GetStrValue("result.sessionId");
                _logger.LogInformation($"Session Id : {_cdpSessionId}");
                foreach (var setting in CdpApi.Configuration)
                {
                    Publish(setting, new { });
                }

                Publish(CdpApi.Methods.TargetAutoAttach, CdpApi.TargetAutoAttachConfig);
                Publish(CdpApi.Methods.BrowserGetWinTarget, new { targetId = _cdpTargetId }, (rq, rs) =>
                {
                    rs.WithVal <int>("result.windowId", x => { _cdpWindowId = x; });
                    _logger.LogInformation($"Window Id : {_cdpWindowId}");
                    HandleActionResult(_routeService.Execute(NBlinkContext.DefaultRoute()));
                });
                return;
            }
            if (string.IsNullOrEmpty(_cdpSessionId))
            {
                return;
            }

            if (response.IsMsgFromTargetSession(_cdpSessionId))
            {
                HandleTargetSessionMsg(response);
                return;
            }

            if (response.IsMsgTargetDestroyed(_cdpTargetId))
            {
                _logger.LogError($"{_cdpTargetId} destroyed s******g down application...");
                _dispatcher.Publish(new ExitCmd());
            }
        }