Ejemplo n.º 1
0
 TestModule(IModuleIdentity moduleIdentity, string endpointId, IDeviceListener deviceListener, List <IMessage> receivedMessages)
 {
     this.moduleIdentity   = moduleIdentity;
     this.outputName       = endpointId;
     this.deviceListener   = deviceListener;
     this.receivedMessages = receivedMessages;
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 5
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)
        {
            _myos         = new Dictionary <IntPtr, IMyo>();
            _readonlyMyos = new ReadOnlyMyoCollection(_myos);

            _deviceListener           = deviceListener;
            _deviceListener.Paired   += DeviceListener_Paired;
            _deviceListener.Unpaired += DeviceListener_Unpaired;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 7
0
 static Task AddOrRemoveSubscription(IDeviceListener listener, bool add, DeviceSubscription subscription)
 {
     if (add)
     {
         return(listener.AddSubscription(subscription));
     }
     else
     {
         return(listener.RemoveSubscription(subscription));
     }
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
0
 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);
     }
 }
Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 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;
             });
         }
     }));
 }
Ejemplo n.º 15
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() =>
             {
                 // 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;
             });
         }
     }));
 }
Ejemplo n.º 16
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)
 {
     return(new Hub(deviceListener));
 }
Ejemplo n.º 17
0
 TestDevice(IDeviceIdentity deviceIdentity, IDeviceListener deviceListener)
 {
     this.deviceIdentity = deviceIdentity;
     this.deviceListener = deviceListener;
 }
Ejemplo n.º 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);
        }