private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     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();
     Process.GetCurrentProcess().Kill();
 }
 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 void restore()
 {
     CreatorGroup           = "";
     NameGroup              = "";
     UrlStream              = "";
     MqttConnection.IsGroup = false;
     MqttConnection.MqttDisconnect();
     MqttConnection.setKeyEndToEnd("");
     MqttConnection.setUser("");
     MqttConnection.setAioKey("");
     MqttConnection.IamAdmin        = false;
     LogInContainer.IsEnabled       = true;
     ProgressCircle.IsIndeterminate = false;
     ShowSnackBar("The room does not exist or disabled!");
 }
 private void CloseBtn_Click(object sender, RoutedEventArgs e)
 {
     MqttConnection.MqttDisconnect();
     Process.GetCurrentProcess().Kill();
 }
        private async void GenerateBtn_Click(object sender, RoutedEventArgs e)
        {
            if (NameRoom.Text != "" && !string.IsNullOrWhiteSpace(UsernameTxt.Text) && !string.IsNullOrWhiteSpace(AioKeyTxt.Password) && !string.IsNullOrWhiteSpace(Key_EndToEnd.Text) && !Key_EndToEnd.Text.Contains("GENERATE"))
            {
                HttpRequest req = new HttpRequest();

                string KeyRoomDec = req.getCorretName(NameRoom.Text) + "|" + UsernameTxt.Text + "|" + AioKeyTxt.Password + "|" + Key_EndToEnd.Text + "|" + MqttConnection.NickName + "|" + UrlTxt.Text + "|" + CheckControll.IsChecked + "|" + MqttConnection.MqttServer + "|" + MqttConnection.MqttPort.ToString();
                string KeyRoomEnc = StringCipher.Encrypt(KeyRoomDec, "");

                if (CheckCurrentData.IsChecked == true)
                {
                    if (getNumFeed(req.getAllFeeds()) != 10)
                    {
                        MqttConnection.MqttUnsubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                        if (req.createFeed(NameRoom.Text, DescriptionTxt.Text, Key_EndToEnd.Text, UrlTxt.Text, CheckControll.IsChecked.ToString()))
                        {
                            MqttConnection.setKeyEndToEnd(Key_EndToEnd.Text);
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_ROOMGROUP_" + NameRoom.Text + "_" + UrlTxt.Text);
                            Clipboard.SetText(KeyRoomEnc);
                            MessageBox.Show("Room created!!!" + '\n' + '\n' + "Don't worry, I copy the access key to the group, share it with your friends, you just have to paste and they just have to copy it and click on \"I have a key\"");
                            Close();
                        }
                        else
                        {
                            MqttConnection.setKeyEndToEnd("");
                            MqttConnection.setChatRoomNameKey("chat");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            ShowSnackBar("Error creating room!");
                        }
                    }
                    else
                    {
                        ShowSnackBar("Max number of group created, delete one!");
                    }
                }
                else
                {
                    string tempUser   = MqttConnection.UserName;
                    string tempAioKey = MqttConnection.AioKey;
                    MqttConnection.MqttDisconnect();
                    MqttConnection.setUser(UsernameTxt.Text);
                    MqttConnection.setAioKey(AioKeyTxt.Password);
                    if (!(await MqttConnection.MqttFastConnect()))
                    {
                        MqttConnection.setUser(tempUser);
                        MqttConnection.setAioKey(tempAioKey);
                        ShowSnackBar("Erron to connect with new data!");
                        UsernameTxt.Focus();
                        return;
                    }

                    if (getNumFeed(req.getAllFeeds()) != 10)
                    {
                        if (req.createFeed(NameRoom.Text, DescriptionTxt.Text, Key_EndToEnd.Text, UrlTxt.Text, CheckControll.IsChecked.ToString()))
                        {
                            MqttConnection.setKeyEndToEnd(Key_EndToEnd.Text);
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/clients");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_ROOMGROUP_" + NameRoom.Text + "_" + UrlTxt.Text);
                            Clipboard.SetText(KeyRoomEnc);
                            MessageBox.Show("Room created!!!" + '\n' + '\n' + "Don't worry, I copy the access key to the group, share it with your friends, you just have to paste and they just have to copy it and click on \"I have a key\"");
                            Close();
                        }
                        else
                        {
                            MqttConnection.setKeyEndToEnd("");
                            MqttConnection.setChatRoomNameKey("chat");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/clients");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            ShowSnackBar("Error creating room!");
                        }
                    }
                    else
                    {
                        ShowSnackBar("Max number of group created, delete one!");
                    }
                }
            }
            else
            {
                ShowSnackBar("Complete the box please");
            }
        }