Ejemplo n.º 1
0
        public void AddTopic(MqttTopic topic)
        {
            if (!_topics.ContainsKey(topic.Path))
            {
                _topics.Add(topic.Path, topic);

                _subscribetopic(topic);
                if (OnTopicChange != null)
                    OnTopicChange(this, new TopicChangeEventArgs(topic, TopicChangeType.Add));
                topic.PropertyChanged += Topic_PropertyChanged;
            }
        }
Ejemplo n.º 2
0
        public void EqualsTest2()
        {
            MqttTopic obj, target;
            target = new MqttTopic("test/lk", 1, true);
            obj = new MqttTopic("test/lk", 1, true);
            int a = target.GetHashCode();
            int b = obj.GetHashCode();
            Assert.AreEqual(a, b);
            Assert.IsTrue(target.Equals(obj));
            obj = new MqttTopic("test/lk", 2, true);
            Assert.IsFalse(target.Equals(obj));
            obj = new MqttTopic("test/lk1", 1, true);
            Assert.IsFalse(target.Equals(obj));
            obj = new MqttTopic("test/la", 1, true);
            Assert.IsFalse(target.Equals(obj));
            obj = new MqttTopic("test/lk", 1, false);
            Assert.IsFalse(target.Equals(obj));

            // TODO: ajouter des assertions à méthode MqttTopicTest.EqualsTest(MqttTopic, Object)
        }
Ejemplo n.º 3
0
 public void UpdateTopic( MqttTopic newtopic)
 {
     this.Path = newtopic.Path;
     this.Qos = newtopic.Qos;
     this.Subscribed = newtopic.Subscribed;
 }
Ejemplo n.º 4
0
 public void subscribe(string topic, byte qos = MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE)
 {
     MqttTopic to = new MqttTopic(topic, qos, true);
     subscribe(to);
 }
Ejemplo n.º 5
0
 public void subscribe(MqttTopic topic)
 {
     var knowtopic = GetTopic(topic.Path);
     if (knowtopic == null || !knowtopic.Subscribed)
     {
         topic.Subscribed = true;
     }
 }
Ejemplo n.º 6
0
        private void Client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            MqttMessage m = new MqttMessage(e.Topic, e.Message, e.QosLevel, e.Retain);
            var t = new MqttTopic(e.Topic, e.QosLevel, true);
            AddTopic(t);

            if (OnMessageArrived != null)
                OnMessageArrived(this, new MessPublishEventArgs(m, e.DupFlag));
        }
Ejemplo n.º 7
0
 private void _unsubscribetopic(MqttTopic topic)
 {
     if (client != null && !topic.Subscribed)
         client.Unsubscribe(new string[] { topic.Path });
 }
Ejemplo n.º 8
0
 private void _subscribetopic(MqttTopic topic)
 {
     if (client!=null && topic.Subscribed)
         client.Subscribe(new string[] { topic.Path }, new byte[] { topic.Qos });
 }
Ejemplo n.º 9
0
        private void addTopicToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewTopic nt = new NewTopic();
            var res = nt.ShowDialog();

            if (res == DialogResult.OK)
            {
                if (!uitopics.Any(a => a.Path == nt.TopicPath))
                {
                    MqttTopic t = new MqttTopic(nt.TopicPath, (byte)nt.Qos, nt.subscribed);
                    mqtt.AddTopic(t);
                }
                else
                    MessageBox.Show("this topic is already in the topic list");
            }
        }
Ejemplo n.º 10
0
 private void LoadSettings(string settingfilename)
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(SettingsContainer));
         string settingspath = Path.Combine(settingsDirectory, settingfilename);
         SettingsContainer allsettings;
         using (FileStream fs = new FileStream(settingspath, FileMode.Open))
         {
             allsettings = (SettingsContainer)serializer.Deserialize(fs);
         }
         if (allsettings != null)
         {
             this.uitopics.Clear();
             this.serversett = allsettings.BrokerSettings;
             allsettings.Topics.ForEach(t => this.uitopics.Add(t));
             if (allsettings.Topics != null && allsettings.Topics.Any())
                 this.currenttopic = allsettings.Topics.FirstOrDefault(a => a.Path == allsettings.currenttopicpath);
             settingsfilepath = settingspath;
             //MessageBox.Show(string.Format("Settings correctly loaded from file {0}", settingfilename));
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(string.Format("Error while loading settings from file {0} : {1}", settingfilename, e.Message));
     }
 }
Ejemplo n.º 11
0
 private void DataGridView_topics_CurrentCellChanged(object sender, EventArgs e)
 {
     if (this.dataGridView_topics.CurrentRow != null)
     {
         var ct = (MqttTopic)this.dataGridView_topics.CurrentRow.DataBoundItem;
         if (ct != null && (this.currenttopic == null || ct.Path != this.currenttopic.Path))
         {
             currenttopic = ct;
             this.label_curernttopic.Text = currenttopic.Path;
             this.toolStripStatusLabel_curentopic.Text = currenttopic.Path;
         }
     }
 }
Ejemplo n.º 12
0
 public TopicChangeEventArgs(MqttTopic topic, TopicChangeType changetype)
 {
     this.Topic = topic;
     this.ChangeType = changetype;
 }