Example #1
0
        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)));
        }
Example #2
0
        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)));
        }
Example #3
0
        public AgentProcessManager(IWorkbookAppInstallation workbookApp, Type agentProcessType)
        {
            if (!typeof(IAgentProcess).IsAssignableFrom(agentProcessType))
            {
                throw new ArgumentException("Must be an IAgentProcess", nameof(agentProcessType));
            }

            TAG = $"{nameof (AgentProcessManager)}<{agentProcessType.Name}>";

            this.workbookApp      = workbookApp;
            this.agentProcessType = agentProcessType;
        }
Example #4
0
        #pragma warning restore 0067

        public iOSAgentProcess(IWorkbookAppInstallation workbookApp)
        => WorkbookApp = workbookApp ?? throw new ArgumentNullException(nameof(workbookApp));
Example #5
0
 public AgentProcessState(IWorkbookAppInstallation workbookApp, Type agentProcessType)
 => AgentProcess = (IAgentProcess)Activator.CreateInstance(