Exemplo n.º 1
0
        public void GetContact()
        {
            String BASE_URL = "http://baobab.tokidev.fr/";

            var client = new RestClient(BASE_URL);

            var request = new RestRequest("api/fetchMessages", Method.GET);

            request.AddHeader("Accept", "application/json");
            request.AddHeader("Authorization", "Bearer " + token);

            IRestResponse response = client.Execute(request);
            var           content  = response.Content;

            if (content == null || content == "")
            {
                MessageBox.Show("Error.");
            }
            else
            {
                HashSet <String> contacts = new HashSet <String>();
                JArray           contact  = (JArray)JsonConvert.DeserializeObject(content);
                foreach (var con in contact)
                {
                    Personne p = getPersonneByAuthor((String)con["author"]);
                    if (p == null)
                    {
                        p = new Personne((int)con["id"], (String)con["author"], new List <string> {
                            (String)con["msg"]
                        });
                        contactList.Add(p);
                    }
                    else
                    {
                        p.messageList.Add((String)con["msg"]);
                    }

                    id++;
                }
            }
        }
Exemplo n.º 2
0
        public void send(object sender, RoutedEventArgs e)
        {
            Object   receiver = contact.SelectedItem;
            Personne personne = null;

            if (receiver != null)
            {
                personne = (Personne)receiver;
            }
            if (personne != null)
            {
                String BASE_URL = "http://baobab.tokidev.fr/";

                var client = new RestClient(BASE_URL);

                var request = new RestRequest("api/sendMsg", Method.POST);

                request.AddHeader("Accept", "application/json");
                request.AddHeader("Authorization", "Bearer " + token);


                request.AddJsonBody(new
                {
                    message  = vm.Encrypt(messageContent.Text),
                    receiver = personne.nickname
                });

                IRestResponse response = client.Execute(request);
                var           content  = response.Content;
                if (content == null || content == "")
                {
                    MessageBox.Show("Error.");
                }
                else
                {
                }
            }
        }
Exemplo n.º 3
0
 public void sendMessage(Personne from, Personne to, string msg)
 {
     to.addMessage(msg);
 }