public UncachedAgentTicket(
            ClientSessionUri clientSessionUri,
            IMessageService messageService,
            Action disconnectedHandler)
        {
            if (clientSessionUri == null)
            {
                throw new ArgumentNullException(nameof(clientSessionUri));
            }

            if (disconnectedHandler == null)
            {
                throw new ArgumentNullException(nameof(disconnectedHandler));
            }

            client = new AgentClient(
                clientSessionUri.Host,
                clientSessionUri.Port,
                clientSessionUri.AssemblySearchPaths);

            MessageService = messageService;

            client.OpenAgentMessageChannel(monitorConnectionCancellationTokenSource.Token)
            .ContinueWithOnMainThread(task => disconnectedHandler());
        }
示例#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.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)));
        }
示例#3
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)));
        }
示例#4
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();
        }
示例#5
0
        public bool TryGetApplicationState(
            ClientSessionUri clientSessionUri,
            out TApplicationState applicationState)
        {
            if (clientSessionUri == null)
            {
                throw new ArgumentNullException(nameof(clientSessionUri));
            }

            foreach (var state in sessions.Values)
            {
                switch (state.Session.SessionKind)
                {
                case ClientSessionKind.Workbook:
                    if (clientSessionUri.WorkbookPath != null &&
                        state.Session.Workbook.LogicalPath == clientSessionUri.WorkbookPath)
                    {
                        applicationState = state.ApplicationState;
                        return(true);
                    }

                    break;

                case ClientSessionKind.LiveInspection:
                    if (state.Session.Uri == clientSessionUri)
                    {
                        applicationState = state.ApplicationState;
                        return(true);
                    }

                    break;
                }
            }

            applicationState = null;
            return(false);
        }