public async Task <AgentConnection> ConnectAsync( IWorkbookAppInstallation workbookApp, ClientSessionUri clientSessionUri, IMessageService messageService, Action disconnectedHandler, CancellationToken cancellationToken) { if (disconnectedHandler == null) { throw new ArgumentNullException(nameof(disconnectedHandler)); } IAgentTicket ticket; if (clientSessionUri == null || clientSessionUri.SessionKind == ClientSessionKind.Workbook) { ticket = await workbookApp.RequestAgentTicketAsync( clientSessionUri, messageService, disconnectedHandler, cancellationToken); } else { ticket = new UncachedAgentTicket( clientSessionUri, messageService, disconnectedHandler); } var assemblySearchPaths = ticket.AssemblySearchPaths; var identity = await ticket.GetAgentIdentityAsync(cancellationToken); if (identity == null) { throw new Exception("IAgentTicket.GetAgentIdentityAsync did not return an identity"); } var apiClient = await ticket.GetClientAsync(cancellationToken); if (apiClient == null) { throw new Exception("IAgentTicket.GetClientAsync did not return a client"); } apiClient.SessionCancellationToken = cancellationToken; return(new AgentConnection( ticket, identity.AgentType, identity, apiClient, assemblySearchPaths == null ? ImmutableArray <string> .Empty : assemblySearchPaths.ToImmutableArray(), await apiClient.GetAgentFeaturesAsync(cancellationToken))); }
public async Task <AgentConnection> ConnectAsync( IWorkbookAppInstallation workbookApp, ClientSessionUri clientSessionUri, IMessageService messageService, Action disconnectedHandler, CancellationToken cancellationToken) { if (disconnectedHandler == null) { throw new ArgumentNullException(nameof(disconnectedHandler)); } IAgentTicket ticket; if (clientSessionUri == null || clientSessionUri.Host == null || !ValidPortRange.IsValid(clientSessionUri.Port)) { ticket = await workbookApp.RequestAgentTicketAsync( clientSessionUri, messageService, disconnectedHandler, cancellationToken); } else { ticket = new UncachedAgentTicket( clientSessionUri, messageService, disconnectedHandler); } var identity = await ticket.GetAgentIdentityAsync(cancellationToken); if (identity == null) { throw new Exception("IAgentTicket.GetAgentIdentityAsync did not return an identity"); } var apiClient = await ticket.GetClientAsync(cancellationToken); if (apiClient == null) { throw new Exception("IAgentTicket.GetClientAsync did not return a client"); } apiClient.UpdateSessionCancellationToken(cancellationToken); return(new AgentConnection( ticket, identity.AgentType, identity, apiClient, await apiClient.GetAgentFeaturesAsync(cancellationToken))); }