Ejemplo n.º 1
0
        async Task ConnectToAgentAsync(CancellationToken cancellationToken)
        {
            if (agent.IsConnected)
            {
                agent = agent.TerminateConnection();
            }

            if (SessionKind == ClientSessionKind.Workbook)
            {
                WorkbookApp = WorkbookAppInstallation.Locate(agent.Type);
            }

            agent = await agent.ConnectAsync(
                WorkbookApp,
                Uri,
                ViewControllers.Messages,
                HandleAgentDisconnected,
                cancellationTokenSource.Token);

            agent.Api.EvaluationContextManager.Events.Subscribe(
                new Observer <ICodeCellEvent> (HandleCodeCellEvent));

            await agent.Api.SetLogLevelAsync(Log.GetLogLevel());

            UpdateTitle();

            PostEvent(ClientSessionEventKind.AgentConnected);

            new Telemetry.Models.AgentSession {
                AppSessionId = ClientApp.SharedInstance.AppSessionId,
                Timestamp    = DateTimeOffset.UtcNow,
                Flavor       = agent.Identity.FlavorId,
                Kind         = (Telemetry.Models.AgentSessionKind)(int) SessionKind
            }.Post();
        }
Ejemplo n.º 2
0
        async Task LoadWorkbookAsync(CancellationToken cancellationToken)
        {
            bool cancelOpen = false;

            await Workbook.Open(async quarantineInfo => {
                var response = await ViewControllers.Messages.PushAlertMessageAsync(
                    quarantineInfo.CreateAlert());
                cancelOpen = response.Id == "cancel";
                return(!cancelOpen);
            }, Uri.WorkbookPath, agent.Type);

            if (cancelOpen)
            {
                throw new QuietlyDisposeClientSessionException();
            }

            ViewControllers.WorkbookTargets.PropertyChanged -= WorkbookTargets_PropertyChanged;
            ViewControllers.WorkbookTargets.UpdateTargets(this);
            ViewControllers.WorkbookTargets.PropertyChanged += WorkbookTargets_PropertyChanged;

            if (ViewControllers.WorkbookTargets.SelectedTarget != null)
            {
                agent = agent.WithAgentType(ViewControllers.WorkbookTargets.SelectedTarget.AgentType);
            }
        }
Ejemplo n.º 3
0
        async Task ConnectToAgentAsync(CancellationToken cancellationToken)
        {
            if (agent.IsConnected)
            {
                agent = agent.TerminateConnection();
            }

            if (SessionKind == ClientSessionKind.Workbook)
            {
                WorkbookApp = WorkbookAppInstallation.Locate(agent.Type);
            }

            agent = await agent.ConnectAsync(
                WorkbookApp,
                Uri,
                ViewControllers.Messages,
                HandleAgentDisconnected,
                cancellationTokenSource.Token);

            agent.Api.Messages.Subscribe(new Observer <object> (HandleAgentMessage));

            await agent.Api.SetLogLevelAsync(Log.GetLogLevel());

            UpdateTitle();

            PostEvent(ClientSessionEventKind.AgentConnected);
        }
Ejemplo n.º 4
0
        void ResetAgentConnection()
        {
            ViewControllers.Messages.ClearStatusMessages();

            var agentType = AgentType.Unknown;

            if (agent != null)
            {
                agentType = agent.Type;
                ((IDisposable)agent).Dispose();
            }

            agent = new AgentConnection(agentType);
        }
Ejemplo n.º 5
0
        void WorkbookTargets_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            EvaluationService.OutdateAllCodeCells();

            var selectedTarget = ViewControllers.WorkbookTargets.SelectedTarget;

            if (selectedTarget == null)
            {
                TerminateAgentConnection();
            }
            else if (selectedTarget.AgentType != agent.Type)
            {
                agent = agent.WithAgentType(selectedTarget.AgentType);
                InitializeAgentConnectionAsync().Forget();
            }
        }
Ejemplo n.º 6
0
        public ClientSession(ClientSessionUri clientSessionUri)
        {
            if (clientSessionUri == null)
            {
                throw new ArgumentNullException(nameof(clientSessionUri));
            }

            Uri         = clientSessionUri;
            SessionKind = clientSessionUri.SessionKind;
            agent       = new AgentConnection(clientSessionUri.AgentType);

            Id = Guid.NewGuid();

            clientWebServerUri = ClientApp.SharedInstance.WebServer.AddSession(this);

            Workbook = new WorkbookPackage(Uri.WorkbookPath);
            Workbook.PropertyChanged += Workbook_PropertyChanged;

            UpdateTitle();
        }
Ejemplo n.º 7
0
        async Task ConnectToAgentAsync(CancellationToken cancellationToken)
        {
            if (agent.IsConnected)
            {
                agent = agent.TerminateConnection();
            }

            if (SessionKind == ClientSessionKind.Workbook)
            {
                WorkbookApp = WorkbookAppInstallation.Locate(agent.Type);
            }

            agent = await agent.ConnectAsync(
                WorkbookApp,
                Uri,
                ViewControllers.Messages,
                HandleAgentDisconnected,
                cancellationTokenSource.Token);

            agent.Api.EvaluationContextManager.Events.Subscribe(
                new Observer <ICodeCellEvent> (HandleCodeCellEvent));

            await agent.Api.SetLogLevelAsync(Log.GetLogLevel());

            UpdateTitle();

            PostEvent(ClientSessionEventKind.AgentConnected);

            // May be set by Inspector extensions to allow correlating client telemetry with IDE telemetry
            var externalTelemetrySessionId = Uri
                                             .Parameters
                                             .FirstOrDefault(p => p.Key == "TelemetrySessionId")
                                             .Value;

            new Telemetry.Models.AgentSession {
                AgentFlavor = agent.Identity.FlavorId,
                ClientKind  = SessionKind,
                ExternalTelemetrySessionId = externalTelemetrySessionId
            }.Post();
        }
Ejemplo n.º 8
0
        async Task RefreshForAgentIntegration()
        {
            agent = await agent.RefreshFeaturesAsync();

            PostEvent(ClientSessionEventKind.AgentFeaturesUpdated);
        }
Ejemplo n.º 9
0
 public void TerminateAgentConnection()
 => agent = agent.TerminateConnection();