Exemple #1
0
 TestModule(IModuleIdentity moduleIdentity, string endpointId, IDeviceListener deviceListener, List <IMessage> receivedMessages)
 {
     this.moduleIdentity   = moduleIdentity;
     this.outputName       = endpointId;
     this.deviceListener   = deviceListener;
     this.receivedMessages = receivedMessages;
 }
Exemple #2
0
        /// <summary>
        /// Creates a new <see cref="IHub"/> instance.
        /// </summary>
        /// <param name="deviceListener">The device listener.</param>
        /// <returns>A new <see cref="IHub"/> instance.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
        public static IHub Create(IDeviceListener deviceListener)
        {
            Contract.Requires <ArgumentNullException>(deviceListener != null, "deviceListener");
            Contract.Ensures(Contract.Result <IHub>() != null);

            return(new Hub(deviceListener));
        }
Exemple #3
0
 public MessagingServiceClient(IDeviceListener deviceListener, IMessageConverter <IProtocolGatewayMessage> messageConverter, IByteBufferConverter byteBufferConverter, ISessionStatePersistenceProvider sessionStatePersistenceProvider)
 {
     this.deviceListener                  = Preconditions.CheckNotNull(deviceListener, nameof(deviceListener));
     this.messageConverter                = Preconditions.CheckNotNull(messageConverter, nameof(messageConverter));
     this.byteBufferConverter             = Preconditions.CheckNotNull(byteBufferConverter, nameof(byteBufferConverter));
     this.sessionStatePersistenceProvider = Preconditions.CheckNotNull(sessionStatePersistenceProvider, nameof(sessionStatePersistenceProvider));
 }
Exemple #4
0
        protected override void ReadThread_DataRead(DeviceData data)
        {
            // decode device data here
            // cache the listener so we only go through the lock once
            IDeviceListener listener = deviceListener;

            deviceListener.DataRead(new DecodedData(data));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Hub" /> class.
        /// </summary>
        /// <param name="deviceListener">The device listener.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
        protected Hub(IDeviceListener deviceListener)
        {
            _myos         = new Dictionary <IntPtr, IMyo>();
            _readonlyMyos = new ReadOnlyMyoCollection(_myos);

            _deviceListener           = deviceListener;
            _deviceListener.Paired   += DeviceListener_Paired;
            _deviceListener.Unpaired += DeviceListener_Unpaired;
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hub" /> class.
        /// </summary>
        /// <param name="deviceListener">The device listener.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
        protected Hub(IDeviceListener deviceListener)
        {
            Contract.Requires<ArgumentNullException>(deviceListener != null, "deviceListener");

            _myos = new Dictionary<IntPtr, IMyo>();
            _readonlyMyos = new ReadOnlyMyoCollection(_myos);

            _deviceListener = deviceListener;
            _deviceListener.Paired += DeviceListener_Paired;
            _deviceListener.Unpaired += DeviceListener_Unpaired;
        }
Exemple #7
0
 static Task AddOrRemoveSubscription(IDeviceListener listener, bool add, DeviceSubscription subscription)
 {
     if (add)
     {
         return(listener.AddSubscription(subscription));
     }
     else
     {
         return(listener.RemoveSubscription(subscription));
     }
 }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hub" /> class.
        /// </summary>
        /// <param name="deviceListener">The device listener.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
        protected Hub(IDeviceListener deviceListener)
        {
            Contract.Requires <ArgumentNullException>(deviceListener != null, "deviceListener");

            _myos         = new Dictionary <IntPtr, IMyo>();
            _readonlyMyos = new ReadOnlyMyoCollection(_myos);

            _deviceListener           = deviceListener;
            _deviceListener.Paired   += DeviceListener_Paired;
            _deviceListener.Unpaired += DeviceListener_Unpaired;
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hub" /> class.
        /// </summary>
        /// <param name="deviceListener">The device listener.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
        protected Hub(IDeviceListener deviceListener)
        {
            if (deviceListener == null)
            {
                throw new ArgumentNullException("deviceListener", "The device listener cannot be null.");
            }

            _myos         = new Dictionary <IntPtr, IMyo>();
            _readonlyMyos = new ReadOnlyMyoCollection(_myos);

            _deviceListener         = deviceListener;
            _deviceListener.Paired += DeviceListener_Paired;
        }
        public async Task <IMessagingBridge> Connect(IDeviceIdentity deviceidentity)
        {
            if (!(deviceidentity is ProtocolGatewayIdentity protocolGatewayIdentity))
            {
                throw new AuthenticationException("Invalid identity object received");
            }

            IDeviceListener deviceListener = await this.connectionProvider.GetDeviceListenerAsync(protocolGatewayIdentity.ClientCredentials.Identity);

            IMessagingServiceClient messagingServiceClient = new MessagingServiceClient(deviceListener, this.pgMessageConverter, this.byteBufferConverter);
            IMessagingBridge        messagingBridge        = new SingleClientMessagingBridge(deviceidentity, messagingServiceClient);

            return(messagingBridge);
        }
Exemple #11
0
        public async Task OpenAsync(TimeSpan timeout)
        {
            if (!this.Link.IsCbsLink())
            {
                if (!await this.Authenticate())
                {
                    throw new InvalidOperationException($"Unable to open {this.Type} link as connection is not authenticated");
                }

                this.deviceListener = await this.ConnectionHandler.GetDeviceListener();
            }
            await this.OnOpenAsync(timeout);

            await this.ConnectionHandler.RegisterLinkHandler(this);

            Events.Opened(this);
        }
 static Task AddOrRemoveSubscription(IDeviceListener listener, bool add, DeviceSubscription subscription)
 {
     try
     {
         if (add)
         {
             return(listener.AddSubscription(subscription));
         }
         else
         {
             return(listener.RemoveSubscription(subscription));
         }
     }
     catch (Exception e)
     {
         Events.FailedToChangeSubscriptionState(e, subscription.ToString(), listener.Identity.Id);
         return(Task.CompletedTask);
     }
 }
Exemple #13
0
        async Task EnsureInitialized()
        {
            if (!this.isInitialized)
            {
                using (await this.initializationLock.LockAsync())
                {
                    if (!this.isInitialized)
                    {
                        AmqpAuthentication amqpAuth;
                        // Check if Principal is SaslPrincipal
                        if (this.connection.Principal is SaslPrincipal saslPrincipal)
                        {
                            amqpAuth = saslPrincipal.AmqpAuthentication;
                        }
                        else
                        {
                            // Else the connection uses CBS authentication. Get AmqpAuthentication from the CbsNode
                            var cbsNode = this.connection.FindExtension <ICbsNode>();
                            if (cbsNode == null)
                            {
                                throw new InvalidOperationException("CbsNode is null");
                            }

                            amqpAuth = await cbsNode.GetAmqpAuthentication();
                        }

                        if (!amqpAuth.IsAuthenticated)
                        {
                            throw new InvalidOperationException("Connection not authenticated");
                        }

                        IClientCredentials identity = amqpAuth.ClientCredentials.Expect(() => new InvalidOperationException("Authenticated connection should have a valid identity"));
                        this.deviceListener = await this.connectionProvider.GetDeviceListenerAsync(identity);

                        var deviceProxy = new DeviceProxy(this, identity.Identity);
                        this.deviceListener.BindDeviceProxy(deviceProxy);
                        this.amqpAuthentication = amqpAuth;
                        this.isInitialized      = true;
                        Events.InitializedConnectionHandler(identity.Identity);
                    }
                }
            }
        }
Exemple #14
0
 public Task <IDeviceListener> GetDeviceListener()
 {
     return(this.deviceListener.Map(d => Task.FromResult(d))
            .GetOrElse(
                async() =>
     {
         using (await this.initializationLock.LockAsync())
         {
             return await this.deviceListener.Map(d => Task.FromResult(d))
             .GetOrElse(
                 async() =>
             {
                 IDeviceListener dl = await this.connectionProvider.GetDeviceListenerAsync(this.identity);
                 var deviceProxy = new DeviceProxy(this, this.identity);
                 dl.BindDeviceProxy(deviceProxy);
                 this.deviceListener = Option.Some(dl);
                 return dl;
             });
         }
     }));
 }
 public Task <IDeviceListener> GetDeviceListener()
 {
     return(this.deviceListener.Map(d => Task.FromResult(d))
            .GetOrElse(
                async() =>
     {
         using (await this.initializationLock.LockAsync())
         {
             return await this.deviceListener.Map(d => Task.FromResult(d))
             .GetOrElse(
                 async() =>
             {
                 // TODO: Implement plug and play for AMQP
                 IDeviceListener dl = await this.connectionProvider.GetDeviceListenerAsync(this.identity, Option.None <string>());
                 var deviceProxy = new DeviceProxy(this, this.identity);
                 dl.BindDeviceProxy(deviceProxy);
                 this.deviceListener = Option.Some(dl);
                 Events.InitializedDeviceListener(this.identity);
                 return dl;
             });
         }
     }));
 }
 /// <summary>
 /// Creates a new <see cref="IHub"/> instance.
 /// </summary>
 /// <param name="deviceListener">The device listener.</param>
 /// <returns>A new <see cref="IHub"/> instance.</returns>
 /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
 public static IHub Create(IDeviceListener deviceListener)
 {
     return(new Hub(deviceListener));
 }
Exemple #17
0
 TestDevice(IDeviceIdentity deviceIdentity, IDeviceListener deviceListener)
 {
     this.deviceIdentity = deviceIdentity;
     this.deviceListener = deviceListener;
 }
Exemple #18
0
        /// <summary>
        /// Creates a new <see cref="IHub"/> instance.
        /// </summary>
        /// <param name="deviceListener">The device listener.</param>
        /// <returns>A new <see cref="IHub"/> instance.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the device listener is null.</exception>
        public static IHub Create(IDeviceListener deviceListener)
        {
            Contract.Requires<ArgumentNullException>(deviceListener != null, "deviceListener");
            Contract.Ensures(Contract.Result<IHub>() != null);

            return new Hub(deviceListener);
        }