Exemplo n.º 1
0
        public void BindMessagingChannel(IMessagingChannel <IProtocolGatewayMessage> channel)
        {
            IDeviceProxy deviceProxy = new DeviceProxy(channel, this.deviceListener.Identity, this.messageConverter, this.byteBufferConverter);

            this.deviceListener.BindDeviceProxy(deviceProxy);
            Events.BindMessageChannel(this.deviceListener.Identity);
        }
Exemplo n.º 2
0
        public void BindMessagingChannel(IMessagingChannel <IProtocolGatewayMessage> channel)
        {
            var sessionStateQuery = this.sessionStatePersistenceProvider.GetAsync(new AuthenticatedIdentity(this.deviceListener.Identity.Id));

            IDeviceProxy deviceProxy = new DeviceProxy(channel, this.deviceListener.Identity, this.messageConverter, this.byteBufferConverter);

            this.deviceListener.BindDeviceProxy(
                deviceProxy,
                async() =>
            {
                var sessionState = await sessionStateQuery;

                if (sessionState is SessionState registrationSessionState)
                {
                    var subscriptions = SessionStateParser.GetDeviceSubscriptions(registrationSessionState.SubscriptionRegistrations, this.deviceListener.Identity.Id);

                    foreach ((DeviceSubscription deviceSubscription, bool addSubscription) in subscriptions)
                    {
                        if (deviceSubscription == DeviceSubscription.Unknown)
                        {
                            continue;
                        }

                        if (addSubscription)
                        {
                            await this.deviceListener.AddSubscription(deviceSubscription);
                        }
                        else
                        {
                            await this.deviceListener.RemoveSubscription(deviceSubscription);
                        }
                    }
                }
            });