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 async void LogInBtn_Click(object sender, RoutedEventArgs e) { if (ServerAdafruit) { if (!string.IsNullOrWhiteSpace(NickName.Text) && !string.IsNullOrWhiteSpace(UsernameTxt.Text) && !string.IsNullOrWhiteSpace(AioKeyTxt.Password)) { if (NickName.Text.Length < 25 && !NickName.Text.Contains("_")) { ProgressCircle.IsIndeterminate = true; LogInContainer.IsEnabled = false; NickName.Text = NickName.Text.Trim(); UsernameTxt.Text = UsernameTxt.Text.Trim(); AioKeyTxt.Password = AioKeyTxt.Password.Trim(); MqttConnection.setNickname(NickName.Text); MqttConnection.setUser(UsernameTxt.Text); MqttConnection.setAioKey(AioKeyTxt.Password); HttpRequest req = new HttpRequest(); string response = await Task.Run(() => req.getJsonData("https://io.adafruit.com/api/v2/user?X-AIO-Key=" + MqttConnection.AioKey)); if (response != "") { UserDataJsonReceive.Rootobject UserData = JsonConvert.DeserializeObject <UserDataJsonReceive.Rootobject>(response); if (UsernameTxt.Text == UserData.user.username) { if (await Task.Run(() => MqttConnection.MqttTryToConnect())) { SaveConnectDataFile("", Directory.GetCurrentDirectory() + "\\Data", "\\AdaDataConnection.dt"); MqttConnection.setChatRoomNameKey("chat"); MqttConnection.client.MqttMsgPublishReceived += client_MqttMsgPublishReceived; MqttConnection.MqttSubscribe(UsernameTxt.Text + "/feeds/" + MqttConnection.ChatRoomNameKey); MqttConnection.IsSolace = false; MqttConnection.IsGroup = false; MqttConnection.IamAdmin = true; Restore.Start(); } else { ShowSnackBar("Error to connect with server!"); LogInContainer.IsEnabled = true; ProgressCircle.IsIndeterminate = false; } } else { ShowSnackBar("Bad Username or Aio Key"); ProgressCircle.IsIndeterminate = false; LogInContainer.IsEnabled = true; } } else { ShowSnackBar("Bad internet connection!"); ProgressCircle.IsIndeterminate = false; LogInContainer.IsEnabled = true; } } else { ShowSnackBar("Max 25 char for Nickname and not '_'"); } } else { ShowSnackBar("Please, insert data!"); } } else if (ServerSolace) { if (!string.IsNullOrWhiteSpace(SolaceNickName.Text) && !string.IsNullOrWhiteSpace(SolaceHostPort.Text) && !string.IsNullOrWhiteSpace(SolacePassword.Password)) { if (SolaceNickName.Text.Length < 25 && !SolaceNickName.Text.Contains("_")) { ProgressCircle.IsIndeterminate = true; LogInContainer.IsEnabled = false; SolaceNickName.Text = SolaceNickName.Text.Trim(); SolacePassword.Password = SolacePassword.Password.Trim(); SolaceHostPort.Text = SolaceHostPort.Text.Trim(); SolaceHostPort.Text = SolaceHostPort.Text.Remove(0, 6); var SplitAddressPort = SolaceHostPort.Text.Split(':'); MqttConnection.setMqttServer(SplitAddressPort[0]); MqttConnection.setMqttPort(SplitAddressPort[1]); MqttConnection.setNickname(SolaceNickName.Text); MqttConnection.setUser("solace-cloud-client"); MqttConnection.setAioKey(SolacePassword.Password); if (await Task.Run(() => MqttConnection.MqttTryToConnect())) { SaveConnectDataFile("", Directory.GetCurrentDirectory() + "\\Data", "\\SolaceDataConnection.dt"); 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 = false; MqttConnection.IamAdmin = true; Restore.Start(); } else { ShowSnackBar("Error to connect with server!"); LogInContainer.IsEnabled = true; ProgressCircle.IsIndeterminate = false; } } else { ShowSnackBar("Max 25 char for Nickname and not '_'"); } } else { ShowSnackBar("Please, insert data!"); } } }
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; } }