示例#1
0
        public override bool Connect(string deviceId, MqttChannel channel)
        {
            var mqttChannel = GetMqttChannel(deviceId);

            if (mqttChannel != null)
            {
                if (mqttChannel.IsOnine())
                {
                    return(false);
                }
                else if (!mqttChannel.IsOnine())
                {
                    if (mqttChannel.SubscribeStatus == SubscribeStatus.Yes)
                    {
                        var topics = RemoveSubTopic(mqttChannel);
                        foreach (var topic in topics)
                        {
                            Topics.TryGetValue(topic, out IEnumerable <MqttChannel> comparisonValue);
                            var newValue = comparisonValue.Concat(new[] { channel });
                            Topics.AddOrUpdate(topic, newValue, (key, value) => newValue);
                        }
                    }
                }
            }
            MqttChannels.AddOrUpdate(deviceId, channel, (k, v) => channel);
            return(true);
        }