private void sendMessage(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(MessageTextBox.Text))
     {
         socket.Emit("chat message", _username, ChatName.Text, MessageTextBox.Text);
     }
     MessageTextBox.Text = string.Empty;
     MessageTextBox.Focus();
 }
        public MessageBoxControl()
        {
            DataContext = this;
            InitializeComponent();
            _username = user.Username;
            socket    = AppSocket.Instance;
            GetChatRooms();
            currentChannel = "Général";
            socket.Emit("joinChannel", user.Username, "Général");

            socket.On("newChannel", (data) =>
            {
                GetChatRooms();
            });

            socket.On("chat message", (data) =>
            {
                Console.WriteLine("message!");
                Newtonsoft.Json.Linq.JObject obj        = (Newtonsoft.Json.Linq.JObject)data;
                Newtonsoft.Json.Linq.JToken un          = obj.GetValue("username");
                Newtonsoft.Json.Linq.JToken ts          = obj.GetValue("timestamp");
                Newtonsoft.Json.Linq.JToken ms          = obj.GetValue("message");
                Newtonsoft.Json.Linq.JToken channelName = obj.GetValue("channel");
                string newMessage = Environment.NewLine + un.ToString() + ts.ToString() + ":\n" + ms.ToString() + Environment.NewLine;
                updateDictionnary(newMessage.ToString(), channelName.ToString());
                Dispatcher.Invoke(() =>
                {
                    if (currentChannel == channelName.ToString())
                    {
                        messageList.Text += newMessage.ToString();
                    }
                });
            });
        }
        private void joinGame(object sender, RoutedEventArgs e)
        {
            var    button     = (Button)sender;
            string gameJoined = (string)button.Content;

            App.Current.Properties["currentGame"] = gameJoined;
            Global.GameName = gameJoined;

            socket.Emit("joinGame", gameJoined, User.instance.Username);

            //var playerOne = new Joiner
            //{
            //    name = User.instance.Username,
            //    score = 0,
            //    _id = User.instance.Id
            //};

            //var playerList = new Players
            //{
            //    players = playerOne
            //};

            //var HttpClient = new HttpClient();
            //HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", User.instance.Token);

            //var json = await Task.Run(() => JsonConvert.SerializeObject(playerList));
            //Console.WriteLine(json);
            //var httpContent = new StringContent(json, Encoding.UTF8, "application/json");



            ////var res = await HttpClient.PostAsync(Constants.ADDR + "match/:name/player", httpContent);
            //var res = await PatchAsync(HttpClient, new Uri(Constants.ADDR + "match/:name/player"), httpContent);
            //if (res.Content != null)
            //{

            //    var responseContent = await res.Content.ReadAsStringAsync();

            //    Console.WriteLine(responseContent);
            //    Console.WriteLine("on est rendu la");



            //}
            //if (res.StatusCode.ToString() == "201")
            //{

            //}
        }
Esempio n. 4
0
 /// <summary>
 /// Traite les évènements de modifications de propriétés qui ont été lancés à partir
 /// du modèle.
 /// </summary>
 /// <param name="sender">L'émetteur de l'évènement (le modèle)</param>
 /// <param name="e">Les paramètres de l'évènement. PropertyName est celui qui nous intéresse.
 /// Il indique quelle propriété a été modifiée dans le modèle.</param>
 private void EditeurProprieteModifiee(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "CouleurSelectionnee")
     {
         socket.Emit(SocketEvents.STROKE_COLOR, "General", Convert.ToInt64(editeur.CouleurSelectionnee.Substring(1), 16));
         AttributsDessin.Color = (Color)ColorConverter.ConvertFromString(editeur.CouleurSelectionnee);
     }
     else if (e.PropertyName == "OutilSelectionne")
     {
         socket.Emit(SocketEvents.STROKE_TOOL, "General", editeur.OutilSelectionne);
         OutilSelectionne = editeur.OutilSelectionne;
     }
     else if (e.PropertyName == "PointeSelectionnee")
     {
         socket.Emit(SocketEvents.STROKE_TIP, "General", editeur.PointeSelectionnee);
         PointeSelectionnee = editeur.PointeSelectionnee;
         AjusterPointe();
     }
     else // e.PropertyName == "TailleTrait"
     {
         socket.Emit(SocketEvents.STROKE_SIZE, "General", editeur.TailleTrait);
         AjusterPointe();
     }
 }
        private async void testing(object sender, RoutedEventArgs e)
        {
            var HttpClient = new HttpClient();

            HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", User.instance.Token);


            var infos = new gameCreated
            {
                type = "FreeForAll"
            };

            var json = await Task.Run(() => JsonConvert.SerializeObject(infos));

            //Console.WriteLine(json);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            var res = await HttpClient.PostAsync(Constants.ADDR + "match/:type", httpContent);

            if (res.Content != null)
            {
                var responseContent = await res.Content.ReadAsStringAsync();

                //Console.WriteLine(responseContent);
                JavaScriptSerializer js = new JavaScriptSerializer();
                game = js.Deserialize <Match>(responseContent);
                //Button bt = (Button)sender;
                //Console.WriteLine(game.match.name);
                Global.GameName = game.match.name;
                Application.Current.Properties["gameName"] = game.match.name;
                Console.WriteLine("gameChoice: " + Global.GameName);
                ((GameChoiceViewModel)(DataContext)).GiveAccess();
                socket.Emit("joinGame", game.match.name, User.instance.Username);
            }
            if (res.StatusCode.ToString() == "201")
            {
            }
        }
        private void answer(object sender, RoutedEventArgs e)
        {
            string answer = answerTextBox.Text;

            //socket.Emit("answer", Global.GameName, answer);
            answerTextBox.Text = String.Empty;
            answerTextBox.Focus();

            string wordToFind = word.Text;

            Console.WriteLine("wordToFind: " + wordToFind);
            if (answer == wordToFind)
            {
                answerTextBox.IsEnabled = false;
                socket.Emit("answer", Global.GameName, answer);
                answerTextBox.Text = String.Empty;
            }
            else
            {
                answerTextBox.Text = String.Empty;
                answerTextBox.Focus();
            }
        }
Esempio n. 7
0
        private void uploadPoints()
        {
            if (pointsBucket.Count > 0)
            {
                if (OutilSelectionne == Tool.PEN)
                {
                    socket.Emit(SocketEvents.STROKE_DRAWING, MATCH_CHANNEL, JsonConvert.SerializeObject(pointsBucket, new StylusPointConverter()));
                }
                else if (OutilSelectionne == Tool.SEGMENT_ERASER)
                {
                    socket.Emit(SocketEvents.STROKE_SEGMENT_ERASING, MATCH_CHANNEL, JsonConvert.SerializeObject(pointsBucket, new StylusPointConverter()));
                }
                else
                {
                    socket.Emit(SocketEvents.STROKE_ERASING, MATCH_CHANNEL, JsonConvert.SerializeObject(pointsBucket, new StylusPointConverter()));
                }

                pointsBucket.Clear();
            }
        }
 private void quitRoom(object sender, RoutedEventArgs e)
 {
     socket.Emit("stopWaiting", Global.GameName, User.instance.Username);
 }