Exemplo n.º 1
0
        public void SendMessage(object sender, EventArgs e)
        {
            ChatBubble bubble = new ChatBubble()
            {
                BubbleMsgTime = DateTime.Now.ToString("HH:mm"),
                BubbleMessage = messageSendControl.MessageToSend,
                SentByMe      = true
            };

            if (bubble.BubbleMessage != string.Empty)
            {
                bubbleList.Items.Add(bubble);
                bubbleList.ScrollIntoView(bubbleList.Items[bubbleList.Items.Count - 1]);
                var sendmsg = new ServerJSON()
                {
                    Function        = ServerFunction.SendMessage.ToString(),
                    LoginInfo       = Authentication.UserLogin,
                    MessageReceiver = ((ContactDialog)dialogCart.SelectedItem).UserId,
                    MessageContent  = bubble.BubbleMessage,
                    SentBy          = GetMyId().ToString()
                };
                var    jsonQuery = JsonConvert.SerializeObject(sendmsg);
                var    bytesJson = Encoding.Unicode.GetBytes(jsonQuery);
                string result    = Authentication.ServerQuery(bytesJson);
            }
        }
Exemplo n.º 2
0
        private void SearchUser(object sender, EventArgs e)
        {
            string userSearch = searchControl.SearchInputTxt.Substring(1);

            dialogCart.Items.Clear();
            var json = new ServerJSON()
            {
                Function      = ServerFunction.SearchUser.ToString(),
                LoginInfo     = Authentication.UserLogin,
                NicknameValue = userSearch
            };
            var    jsonQuery = JsonConvert.SerializeObject(json);
            var    data      = Encoding.Unicode.GetBytes(jsonQuery);
            string result    = Authentication.ServerQuery(data);
            var    deResult  = JsonConvert.DeserializeObject <ServerJSON>(result);

            if (deResult.Result.Length > 2)
            {
                var searched = new ContactDialog
                {
                    ContactUsername = deResult.Result,
                    UserId          = deResult.UserId,
                    ContactMsgDate  = DateTime.Now.ToString("HH:mm")
                };
                dialogCart.Items.Add(searched);
            }
        }
Exemplo n.º 3
0
        private void UserAuth_Registration()
        {
            var reg = new ServerJSON()
            {
                Function  = ServerFunction.Registration.ToString(),
                LoginInfo = Authentication.UserLogin,
                PasInfo   = Authentication.UserPassword
            };

            var    jsonReg  = JsonConvert.SerializeObject(reg);
            var    data     = Encoding.Unicode.GetBytes(jsonReg);
            string result   = Authentication.ServerQuery(data);
            var    deResult = JsonConvert.DeserializeObject <ServerJSON>(result);

            if (deResult.Result != "Success")
            {
                loginControl.logFailMessage.Text       = "Введённый Email-адрес уже существует";
                loginControl.logFailMessage.Visibility = Visibility.Visible;
            }
            else
            {
                loginControl.logFailMessage.Visibility = Visibility.Hidden;
                UserAuth_Login();
            }
        }
Exemplo n.º 4
0
        private int GetMyId()
        {
            var myid = new ServerJSON()
            {
                Function  = ServerFunction.GetUserId.ToString(),
                LoginInfo = Authentication.UserLogin,
            };

            var    jsonQuery = JsonConvert.SerializeObject(myid);
            var    bytesJson = Encoding.Unicode.GetBytes(jsonQuery);
            string result    = Authentication.ServerQuery(bytesJson);
            var    deResult  = JsonConvert.DeserializeObject <ServerJSON>(result);

            return(Convert.ToInt32(deResult.Result));
        }
Exemplo n.º 5
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (nicknameInputTxt.Text != string.Empty)
     {
         var nickSet = new ServerJSON()
         {
             Function      = ServerFunction.SetUsername.ToString(),
             LoginInfo     = Authentication.UserLogin,
             NicknameValue = nicknameInputTxt.Text
         };
         var    jsonQuery = JsonConvert.SerializeObject(nickSet);
         var    data      = Encoding.Unicode.GetBytes(jsonQuery);
         string result    = Authentication.ServerQuery(data);
     }
 }
Exemplo n.º 6
0
        private void UserAuth_Login()
        {
            var log = new ServerJSON()
            {
                Function  = ServerFunction.Login.ToString(),
                LoginInfo = Authentication.UserLogin,
                PasInfo   = Authentication.UserPassword
            };

            var    jsonLog   = JsonConvert.SerializeObject(log);
            var    data      = Encoding.Unicode.GetBytes(jsonLog);
            string result    = null;
            bool   exCatcher = false;

            do
            {
                result = Authentication.ServerQuery(data);
                if (result == "SocketException")
                {
                    exCatcher = false;
                }
                else
                {
                    exCatcher = true;
                }
            } while (!exCatcher);
            var deResult = JsonConvert.DeserializeObject <ServerJSON>(result);

            if (deResult.Result != "Success")
            {
                loginControl.logFailMessage.Text       = "Неправильный Email-адрес или пароль";
                loginControl.logFailMessage.Visibility = Visibility.Visible;
            }
            else
            {
                loginControl.logFailMessage.Visibility = Visibility.Hidden;
                var msg = new MsgWindow();
                msg.Show();
                this.Hide();
            }
        }
Exemplo n.º 7
0
        public MsgWindow()
        {
            InitializeComponent();
            var checkUsername = new ServerJSON
            {
                Function  = ServerFunction.CheckUsername.ToString(),
                LoginInfo = Authentication.UserLogin
            };
            var    jsonCheck = JsonConvert.SerializeObject(checkUsername);
            var    data      = Encoding.Unicode.GetBytes(jsonCheck);
            string result    = null;
            bool   exCatcher = false;

            do
            {
                result = Authentication.ServerQuery(data);
                if (result == "SocketException")
                {
                    exCatcher = false;
                }
                else
                {
                    exCatcher = true;
                }
            } while (!exCatcher);
            var deResult = JsonConvert.DeserializeObject <ServerJSON>(result);

            if (deResult.Result != "ok")
            {
                var userCreate = new CreateUsername();
                userCreate.ShowDialog();
            }

            infoPanelControl.DialogNotSelectedMsg.Visibility = Visibility.Visible;
            infoPanelControl.avatarPanel.Visibility          = Visibility.Hidden;
            infoPanelControl.onlineStatus.Visibility         = Visibility.Hidden;
            infoPanelControl.companionNickname.Visibility    = Visibility.Hidden;
            messageSendControl.ButtonClick += new EventHandler(SendMessage);
            searchControl.SearchKeyPressed += new EventHandler(SearchUser);
        }