Esempio 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();
        }
Esempio 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);
            }
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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();
            }
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio n. 8
0
        async Task RefreshForAgentIntegration()
        {
            agent = await agent.RefreshFeaturesAsync();

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