Exemplo n.º 1
0
        public MqttBroker(MqttBrokerNode Node, string Host, int Port, bool Tls, string UserName, string Password,
                          string WillTopic, string WillData, bool WillRetain, MqttQualityOfService WillQoS)
        {
            this.node       = Node;
            this.host       = Host;
            this.port       = Port;
            this.tls        = Tls;
            this.userName   = UserName;
            this.password   = Password;
            this.willTopic  = WillTopic;
            this.willData   = WillData;
            this.willRetain = WillRetain;
            this.willQoS    = WillQoS;

            this.Open();
        }
Exemplo n.º 2
0
        public static MqttBroker GetBroker(MqttBrokerNode Node, string Key, string Host, int Port, bool Tls, string UserName, string Password,
                                           string WillTopic, string WillData, bool WillRetain, MqttQualityOfService WillQoS)
        {
            MqttBroker Broker;

            lock (brokers)
            {
                if (!brokers.TryGetValue(Key, out Broker))
                {
                    Broker = null;
                }
            }

            if (Broker != null)
            {
                Broker.SetWill(WillTopic, WillData, WillRetain, WillQoS);
                return(Broker);
            }
            else
            {
                Broker = new MqttBroker(Node, Host, Port, Tls, UserName, Password, WillTopic, WillData, WillRetain, WillQoS);

                lock (brokers)
                {
                    if (brokers.ContainsKey(Key))
                    {
                        Broker.Dispose();
                        return(brokers[Key]);
                    }
                    else
                    {
                        brokers[Key] = Broker;
                        return(Broker);
                    }
                }
            }
        }