Example #1
0
        public async Task <AgentConnection> ConnectAsync(
            WorkbookAppInstallation workbookApp,
            ClientSessionUri clientSessionUri,
            IMessageService messageService,
            Action disconnectedHandler,
            CancellationToken cancellationToken)
        {
            if (disconnectedHandler == null)
            {
                throw new ArgumentNullException(nameof(disconnectedHandler));
            }

            IAgentTicket ticket;

            if (clientSessionUri.SessionKind == ClientSessionKind.Workbook && Type != AgentType.Unknown)
            {
                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)));
        }
Example #2
0
 public static async Task <AgentProcessTicket> RequestTestTicketAsync(
     this WorkbookAppInstallation workbookApp,
     Action disconnectedHandler          = null,
     CancellationToken cancellationToken = default(CancellationToken))
 => (AgentProcessTicket)await workbookApp.RequestAgentTicketAsync(
     new ClientSessionUri (AgentType.Test, ClientSessionKind.Workbook),
     new TestMessageService(),
     disconnectedHandler ?? (() => { }),
     cancellationToken);