コード例 #1
0
            private void NodePropertyHandler(SubscriptionMessage message)
            {
                var topic = message.Topic.Replace(MQTTRootTopicLevel, "");

                if (ProccessMQTTMessageForNodeProperties(topic, message.Message))
                {
                    message.Seen = true;
                }
            }
コード例 #2
0
        private void AddMessage(SubscriptionMessage message)
        {
            var id = Guid.NewGuid();

            while (!Messages.TryAdd(id, message))
            {
                Thread.Sleep(100);
            }
            ;
        }
コード例 #3
0
        public void DeviceTopicHandler(SubscriptionMessage message)
        {
            var deviceRootTopic = message.Topic.Replace("/$homie", "");

            if (Devices.Find(device => device.MQTTRootTopicLevel == deviceRootTopic) == null)
            {
                var device = ServiceProvider.GetService <HomieDevice>();
                device.Setup(deviceRootTopic);
                Devices.Add(device);
            }
        }
コード例 #4
0
        private void DeviceNodeHandler(SubscriptionMessage message)
        {
            var nodeRootTopic = message.Topic.Replace("/$type", "");
            var nodeID        = nodeRootTopic.Replace(MQTTRootTopicLevel + "/", "");

            if (Nodes.Find(node => node.MQTTRootTopicLevel == nodeRootTopic) == null)
            {
                var node = new DeviceNode(nodeRootTopic, nodeID, MQTTManager);
                node.ChangeEvent         += OnNodeChange;
                node.PropertyChangeEvent += OnNodePropertyChange;
                Nodes.Add(node);
            }
        }
コード例 #5
0
        public async Task <SubscriptionMessage> WaitForMessage(string topicRegex, TimeSpan timeout = default, bool doSee = true)
        {
            if (timeout.Ticks == 0)
            {
                timeout = TimeSpan.FromSeconds(10);
            }

            SubscriptionMessage message = null;

            AddListner(new Listener(topicRegex, (msg) =>
            {
                message = msg;
            }, true, doSee));

            return(await Task.Run(async() =>
            {
                var start = DateTime.Now;
                while (message == null && (DateTime.Now - start) < timeout)
                {
                    await Task.Delay(100);
                }
                return message;
            }));
        }