string _messagepersistfile = null;     //fichier vers lequel sont éventuellement sauvegardés les messages entratns
        public MqttWinclient()
        {
            InitializeComponent();

            displaystate(false);

            serversett = new serversettings();
            propertyGrid3.SelectedObject = serversett;
            propertyGrid3.PropertyValueChanged += PropertyGrid3_PropertyValueChanged;
            mqtt = new Mqttclient_handler();
            mqtt.OnConnected += Mqtt_OnConnected;
            mqtt.OnDisconnected += Mqtt_OnDisconnected;
            mqtt.OnMessageArrived += Mqtt_OnMessageArrived;
            this.dataGridView_topics.DataSource = topics;
            this.dataGridView_topics.CellContentClick += DataGridView_topics_CellValueChanged;
            this.dataGridView_topics.CellValueChanged += DataGridView_topics_CellValueChanged1;
            //this.dataGridView_topics.SelectionChanged += DataGridView_topics_SelectionChanged;
            this.dataGridView_topics.CurrentCellChanged += DataGridView_topics_CurrentCellChanged;
            this.dataGridView_topics.Columns[0].Width = 130;
            this.dataGridView_topics.Columns[1].Width = 60;
            this.dataGridView_topics.Columns[2].Width = 30;
            this.dataGridView_topics.MouseClick += DataGridView_topics_MouseClick;
            this.dataGridView_topics.CursorChanged += DataGridView_topics_CursorChanged;
            this.FormClosing += MqttManager_FormClosing;
            addExistingsettingsToMenu();
            saveSettingsToolStripMenuItem.Enabled = false;
            this.splitContainer1.Panel1.Click += disableControlClick;
            this.splitContainer2.Panel2.Click += disableControlClick;

        }
 private void Mqtt_OnDisconnected(Mqttclient_handler sender, EventArgs e)
 {
     this.toolStripStatusLabel_server.BackColor = Color.Gray;
     displaystate(false);
 }
        private void Mqtt_OnConnected(Mqttclient_handler sender, EventArgs e)
        {
            foreach (var t in topics.Where(a => a.subscribed))
            {
                mqtt.subscribe(t.path, t.qos);
            }

            this.toolStripStatusLabel_server.BackColor = Color.Green;
            displaystate(true);
        }
 private void Mqtt_OnMessageArrived(Mqttclient_handler sender, MessPublishEventArgs e)
 {
     this.SetText(string.Format("{0}\t{1}\t{2}\t{3}\r\n", DateTime.Now, e.Topic, (int)e.QosLevel, e.StringMessage));
     if (!string.IsNullOrEmpty(MessagepersistFile))
     {
         if (receivedmessages == null)
             receivedmessages = new List<MqttMessage>();
         var im = new MqttMessage()
         {
             message = e.StringMessage,
             qos = (byte)e.QosLevel,
             retained = e.Retain,
             topic = e.Topic
         };
         receivedmessages.Add(im);
         if (receivedmessages.Count > 20)
             PersistsMessages(MessagepersistFile, receivedmessages);
     }
 }