コード例 #1
0
    private async void OnPacketArrival(PacketDotNet.Ieee80211.ActionFrame actionFrame)
    {
        if (BufferMatchers.FindPatternEndsWith(actionFrame.PayloadData, this.settings.TogglePacket))
        {
            var addressBytes  = actionFrame.SourceAddress.GetAddressBytes();
            var addressString = BitConverter
                                .ToString(addressBytes)
                                .Replace("-", ":")
                                .ToLower();

            var mappedTarget = this.settings.DeviceMap
                               .SingleOrDefault(x => x.Mac == addressString);

            if (mappedTarget != default(DeviceMap))
            {
                var message = new ManagedMqttApplicationMessage()
                {
                    ApplicationMessage = new MQTTnet.MqttApplicationMessage
                    {
                        Topic   = mappedTarget.Topic,
                        Payload = Encoding.UTF8.GetBytes(mappedTarget.Message)
                    }
                };

                await this.managedMqttClient.PublishAsync(message);
            }
        }
    }
コード例 #2
0
        /// <inheritdoc/>
        /// <exception cref="ArgumentNullException"></exception>
        public Task PublishAsync(ManagedMqttApplicationMessage applicationMessage)
        {
            if (applicationMessage is null)
            {
                throw new ArgumentNullException(nameof(applicationMessage));
            }

            return(InternalClient.PublishAsync(applicationMessage));
        }
コード例 #3
0
        public async void PublishAsync()
        {
            using var mock = AutoMock.GetLoose();
            var message = new ManagedMqttApplicationMessage();

            mock.Mock <IManagedMqttClient>();
            var rxMqttClinet = mock.Create <RxMqttClient>();

            // act
            await rxMqttClinet.PublishAsync(message);

            // test
            mock.Mock <IManagedMqttClient>().Verify(x => x.PublishAsync(message));
        }
コード例 #4
0
        public void ApplicationMessageSkippedHandler()
        {
            using var mock = AutoMock.GetLoose();
            mock.Mock <IManagedMqttClient>()
            .SetupProperty(x => x.ApplicationMessageSkippedHandler);
            var rxMqttClinet = mock.Create <RxMqttClient>();

            var testScheduler = new TestScheduler();

            var message = new ManagedMqttApplicationMessage();
            var @event  = new ApplicationMessageSkippedEventArgs(message);

            testScheduler.ScheduleAsync(TimeSpan.FromTicks(2), (_, __) => mock.Mock <IManagedMqttClient>().Object.ApplicationMessageSkippedHandler.HandleApplicationMessageSkippedAsync(@event));

            // act
            var testObserver = testScheduler.Start(() => rxMqttClinet.ApplicationMessageSkippedEvent, 0, 0, 4);

            Assert.Equal(1, testObserver.Messages.Count);
            Assert.Equal(NotificationKind.OnNext, testObserver.Messages.Last().Value.Kind);
            Assert.Equal(@event, testObserver.Messages.Last().Value.Value);
            Assert.Null(rxMqttClinet.InternalClient.SynchronizingSubscriptionsFailedHandler);
        }
コード例 #5
0
 public Task PublishAsync(ManagedMqttApplicationMessage applicationMessages)
 => Task.CompletedTask;