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(); }
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); } }
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); }
void ResetAgentConnection() { ViewControllers.Messages.ClearStatusMessages(); var agentType = AgentType.Unknown; if (agent != null) { agentType = agent.Type; ((IDisposable)agent).Dispose(); } agent = new AgentConnection(agentType); }
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(); } }
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(); }
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(); }
async Task RefreshForAgentIntegration() { agent = await agent.RefreshFeaturesAsync(); PostEvent(ClientSessionEventKind.AgentFeaturesUpdated); }
public void TerminateAgentConnection() => agent = agent.TerminateConnection();