コード例 #1
0
        private async void BtnJoin_Click(object sender, RoutedEventArgs e)
        {
            var KeyRoomSelected = selectRoom.Name.Split('_');

            FeedsJson.FeedProprety feedProprety = await getDataJson(KeyRoomSelected[2]);

            if (MqttConnection.ChatRoomNameKey != feedProprety.key)
            {
                MqttConnection.MqttUnsubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                var valuedata = feedProprety.license.Split('*');
                MqttConnection.ChatRoomNameKey = feedProprety.key;
                MqttConnection.Key_EndToEnd    = valuedata[0];
                MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_JOINGROUP_" + feedProprety.name + "_" + valuedata[1]);
                DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnJoin);
                ShowSnackBar("Joined successfully!");
            }
            else
            {
                DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnJoin);
                ShowSnackBar("You are already joined!");
            }
        }
コード例 #2
0
        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");
            }
        }