Exemple #1
0
        private async void SendMessageButtonClick(object sender, RoutedEventArgs e)
        {
            if ((MessageTextbox.Text == "") || (MessageTextbox.Text == "Type your message here..."))
            {
                return;
            }

            MessageClient messageClient = new MessageClient(AccessToken);
            Message       newMessage    = new Message
            {
                MessageText = MessageTextbox.Text,
                From        = Username
            };

            foreach (var contact in Contacts)
            {
                if (ContactsList.SelectedItem.ToString().Contains(contact.Username))
                {
                    newMessage.To = contact.Username; //checking the contact name
                }
            }

            var isSent = await messageClient.SendMessage(newMessage); //sending a message

            if (isSent)
            {
                MessageTextbox.Text = string.Empty;
                ChatMessages.Items.Add(newMessage.From + ": " + newMessage.MessageText);
            }
        }
        private async void SendMessageButtonClick(object sender, RoutedEventArgs e)
        {
            //string currentPath = Environment.CurrentDirectory + "\\token.txt";
            //string accesstoken = File.ReadAllText(currentPath);
            //var accessTokenDeserialised = JsonConvert.DeserializeObject<AuthServerResponse>(accesstoken);

            MessageClient messageClient = new MessageClient(AccessToken);
            Message       newMessage    = new Message();

            newMessage.MessageText = MessageTextbox.Text;
            newMessage.From        = Username;

            foreach (var contact in Contacts)
            {
                if (ContactsList.SelectedItem.ToString().Contains(contact.Username))
                {
                    newMessage.To = contact.Username;
                }
            }

            var isSent = await messageClient.SendMessage(newMessage);

            if (isSent)
            {
                MessageTextbox.Text = string.Empty;
                ChatMessages.Items.Add(newMessage.From + ": " + newMessage.MessageText);
            }
            //if ((MessageTextbox.Text == "") || (MessageTextbox.Text == "Type your message here...")) return;

            ////Call sendMessageService
            //HttpClient client = new HttpClient();
            ////Post client
            //Message message = new Message(Username, RadGridView.SelectedItem.ToString(), MessageTextbox.Text, false);
            //var Json = JsonConvert.SerializeObject(message);
            //var httpContent = new StringContent(Json, Encoding.UTF8, "application/json");
            //await client.PostAsync(messageapi, httpContent);
            ////post client
            ////Call sendMessageService

            //var response = client.GetAsync(string.Format("{0}/{1}/{2}",messageapi, Username, RadGridView.SelectedItem.ToString()));//.Result.Content.ReadAsStringAsync().Result;
            //var jsonresult = response.Result.Content.ReadAsStringAsync().Result;
            //var result = JsonConvert.DeserializeObject<List<Message>>(jsonresult);

            //foreach (var item in result)
            //{
            //}
            //MessageTextbox.Text = "Type your message here...";
        }