public void MqttMessageAtStartConnection()
 {
     try
     {
         string messageDecrypt = StringCipher.Decrypt(messageEncrypt, MqttConnection.Key_EndToEnd);
         if (messageDecrypt.Contains("RESPONSE"))
         {
             var message = messageDecrypt.Split('_');
             if (message[1] == "NOONLY")
             {
                 OnlyMe           = false;
                 UserOnlineYet[i] = message[2];
                 //MessageBox.Show(MqttConnection.NickName + " --- " + message[2]);
                 if (MqttConnection.NickName == message[2])
                 {
                     //MessageBox.Show("ok");
                     Restore.Stop();
                     LogInContainer.IsEnabled       = true;
                     ProgressCircle.IsIndeterminate = false;
                     MqttConnection.MqttDisconnect();
                     UserOnlineYet = new string[49];
                     i             = 0;
                     if (!SolaceHostPort.Text.Contains("ssl://"))
                     {
                         SolaceHostPort.Text = "ssl://" + SolaceHostPort.Text;
                     }
                     ShowSnackBar("This nickname has already been used");
                     return;
                 }
                 i++;
             }
         }
     }
     catch (Exception)
     {
         Restore.Stop();
         LogInContainer.IsEnabled       = true;
         ProgressCircle.IsIndeterminate = false;
         if (MqttConnection.IsSolace)
         {
             MqttConnection.MqttUnsecurePublish("solace-cloud-client/clients", "{\"status\":\"disconnected\",\"at\":\"2020-10-14T00:23:28.481Z\",\"client\":{\"id\":\"dzbpiydeyvrngch_" + MqttConnection.NickName + "\",\"ip\":\"78.74.65.35\"}}");
         }
         MqttConnection.MqttDisconnect();
         UserOnlineYet = new string[49];
         i             = 0;
         if (!SolaceHostPort.Text.Contains("ssl://"))
         {
             SolaceHostPort.Text = "ssl://" + SolaceHostPort.Text;
         }
         MessageBox.Show("Error, BAD link room", "Bad end to end", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        private async void PasteKey_Click(object sender, RoutedEventArgs e)
        {
            string key_group_enc = Clipboard.GetText();
            string key_group_dec = StringCipher.Decrypt(key_group_enc, "");
            //MessageBox.Show(key_group_dec);
            var var_key_group_dec = key_group_dec.Split('|');

            HttpRequest req = new HttpRequest();

            try
            {
                MqttConnection.IsGroup = true;
                MqttConnection.setChatRoomNameKey(var_key_group_dec[0]);
                MqttConnection.setUser(var_key_group_dec[1]);
                MqttConnection.setAioKey(var_key_group_dec[2]);
                MqttConnection.setKeyEndToEnd(var_key_group_dec[3]);
                CreatorGroup            = var_key_group_dec[4];
                UrlStream               = var_key_group_dec[5];
                MqttConnection.IamAdmin = !bool.Parse(var_key_group_dec[6]);
                MqttConnection.setMqttServer(var_key_group_dec[7]);
                MqttConnection.setMqttPort(var_key_group_dec[8]);
            }
            catch (Exception)
            {
                ShowSnackBar("Invalid Key Room");
                return;
            }
            ProgressCircle.IsIndeterminate = true;
            LogInContainer.IsEnabled       = false;


            if (MqttConnection.MqttServer.Contains("adafruit"))
            {
                AdaServer_Click(sender, e);
                if (NickName.Text.Length < 25)
                {
                    if (string.IsNullOrWhiteSpace(NickName.Text))
                    {
                        ShowSnackBar("Please insert a NickName");
                        ProgressCircle.IsIndeterminate = false;
                        LogInContainer.IsEnabled       = true;
                        return;
                    }
                    MqttConnection.setNickname(NickName.Text);

                    if (await Task.Run(() => MqttConnection.MqttTryToConnect()))
                    {
                        string data = await req.getJsonData("https://io.adafruit.com/api/v2/" + MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey + "?X-AIO-Key=" + MqttConnection.AioKey);

                        if (data != "")
                        {
                            FeedsJson.FeedProprety feedProprety = JsonConvert.DeserializeObject <FeedsJson.FeedProprety>(data);
                            if (feedProprety.enabled)
                            {
                                NameGroup          = feedProprety.name;
                                UsernameTxt.Text   = "";
                                AioKeyTxt.Password = "";
                                MqttConnection.client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
                                MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                                MqttConnection.IsSolace = false;
                                MqttConnection.IsGroup  = true;
                                Restore.Start();
                            }
                            else
                            {
                                restore();
                            }
                        }
                        else
                        {
                            restore();
                        }
                    }
                    else
                    {
                        ShowSnackBar("Error to connect!");
                        LogInContainer.IsEnabled       = true;
                        ProgressCircle.IsIndeterminate = false;
                    }
                }
                else
                {
                    ShowSnackBar("Max 25 char for Nickname");
                    LogInContainer.IsEnabled       = true;
                    ProgressCircle.IsIndeterminate = false;
                }
            }
            else if (MqttConnection.MqttServer.Contains("messaging.solace.cloud"))
            {
                SolaceServer_Click(sender, e);
                if (SolaceNickName.Text.Length < 25)
                {
                    if (string.IsNullOrWhiteSpace(SolaceNickName.Text))
                    {
                        ShowSnackBar("Please insert a NickName");
                        ProgressCircle.IsIndeterminate = false;
                        LogInContainer.IsEnabled       = true;
                        return;
                    }
                    MqttConnection.setNickname(SolaceNickName.Text);

                    if (await Task.Run(() => MqttConnection.MqttTryToConnect()))
                    {
                        MqttConnection.setChatRoomNameKey("SolaceRoom");
                        MqttConnection.client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
                        MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                        MqttConnection.MqttUnsecurePublish(MqttConnection.UserName + "/clients", "{\"status\":\"connected\",\"at\":\"2020-10-14T00:23:28.481Z\",\"client\":{\"id\":\"dzbpiydeyvrngch_" + MqttConnection.NickName + "\",\"ip\":\"78.74.65.35\"}}");
                        MqttConnection.IsSolace = true;
                        MqttConnection.IsGroup  = true;
                        Restore.Start();
                    }
                    else
                    {
                        ShowSnackBar("Error to connect!");
                        LogInContainer.IsEnabled       = true;
                        ProgressCircle.IsIndeterminate = false;
                    }
                }
                else
                {
                    ShowSnackBar("Max 25 char for Nickname");
                    LogInContainer.IsEnabled       = true;
                    ProgressCircle.IsIndeterminate = false;
                }
            }
            else
            {
                ShowSnackBar("Invalid Server!");
                LogInContainer.IsEnabled       = true;
                ProgressCircle.IsIndeterminate = false;
            }
        }