Example #1
0
        public async Task uploadImage(bool simulation)
        {
            byte[]        data          = File.ReadAllBytes(this.file);
            string        base64String  = Convert.ToBase64String(data);
            var           content       = JsonConvert.SerializeObject(new ImageToServer(base64String));
            StringContent stringContent = new StringContent(content, Encoding.UTF8, "application/json");
            var           resp          = await Http.Client.PostAsync(this.setQuerry(), stringContent);

            var responseString = await resp.Content.ReadAsStringAsync();

            if ((int)resp.StatusCode == 200)
            {
                this.id = (string)JObject.Parse(responseString)["id"];
                using (var client = new WebClient())
                {
                    client.DownloadFile(Http.UrlServer + "image/" + id, id);
                }
                if (!simulation)
                {
                    this.createGame(this.id);
                }
            }
            else
            {
                var popup = new GameCreationFeedback_window("Image saving error please try again", false);
                popup.ShowDialog();
            }
        }
Example #2
0
        public HomePage_ViewModel(UserControl_HomePage homePage)
        {
            this._homePageView = homePage;
            this._myChat       = new UserControl_ChatControl(this.HomePageView.user);
            this._gameModeView = new UserControl_GameMode(this);

            this.ExtractChat        = new GeneralCommands <object>(Extract_Chat, CanExtractChat);
            this.LogOut             = new GeneralCommands <object>(Log_out, CanLogOut);
            this.Create             = new GeneralCommands <object>(CreateGame, CanCreateGame);
            this.CreateAssisted     = new GeneralCommands <object>(CreatGameAssisted, CanCreateGame);
            this.OpenGalleryCommand = new GeneralCommands <object>(OpenGallery, CanOpenGallery);
            this.ShowUserProfil     = new GeneralCommands <object>(Show_user_profil, Can_Show_Profil);
            this.UpdateUserProfil   = new GeneralCommands <object>(Show_update_user_profil, Can_Show_update_profil);
            this._homePageView.MyChat.Children.Add(_myChat);
            this._homePageView.MiddleView.Children.Add(_gameModeView);
            this.loggedOut = false;
            SocketService.MySocket.Off("disconnect");
            SocketService.MySocket.On("disconnect", () =>
            {
                _homePageView.Dispatcher.Invoke(() =>
                {
                    if (!loggedOut)
                    {
                        GameCreationFeedback_window a = new GameCreationFeedback_window("Connexion perdue", false);
                        a.ShowDialog();
                    }

                    SocketService.MySocket.Close();
                    SocketService.ResetSocket();
                    _homePageView.SwitchToLogin();
                });
            });
            getInfo();
        }
Example #3
0
        public async void createGame(string id)
        {
            var gameToServer = JsonConvert.SerializeObject(new GameToServer(step1_Attribute.name, step1_Attribute.expression, Hints, id, step1_Attribute.difficulty, step1_Attribute.drawingMode));
            var responseGame = await Http.Client.PostAsync(Http.UrlServer + "game", new StringContent(gameToServer, Encoding.UTF8, "application/json"));

            var responseStringGame = await responseGame.Content.ReadAsStringAsync();

            dynamic respGame = JObject.Parse(responseStringGame);
            var     popup    = new GameCreationFeedback_window((string)respGame.msg, (string)respGame.msg == "Game created!");

            popup.ShowDialog();
        }
        public async Task RequestPostImageData(ArrayList a, bool simulation)
        {
            var pointToServer = JsonConvert.SerializeObject(new DrowPoints(a));
            var response      = await Http.Client.PostAsync(Http.UrlServer + "image/data", new StringContent(pointToServer, Encoding.UTF8, "application/json"));

            var responseString = await response.Content.ReadAsStringAsync();

            if ((int)response.StatusCode == 200)
            {
                string id = (string)JObject.Parse(responseString)["id"];
                this.idImage = id;
                if (!simulation)
                {
                    this.createGame(id);
                }
            }
            else
            {
                var popup = new GameCreationFeedback_window("Image saving error please try again", false);
                popup.ShowDialog();
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.MessageBoxResult dialogResult = MessageBox.Show("Voulez supprimer votre Compte", "Supprimer compte", System.Windows.MessageBoxButton.YesNo);
            if (dialogResult == System.Windows.MessageBoxResult.Yes)
            {
                var response = await Http.Client.PostAsync(Http.UrlServer + "user/delete/" + GlobalUser.User.user.username, new StringContent("", Encoding.UTF8, "application/json"));

                var responseString = await response.Content.ReadAsStringAsync();

                if (((int)response.StatusCode) == 200)
                {
                    GameCreationFeedback_window a = new GameCreationFeedback_window("Votre Compte a ete supprimer", true);
                    a.ShowDialog();
                    object o = new object();
                    this.home.Log_out(o);
                }
                else
                {
                    GameCreationFeedback_window a = new GameCreationFeedback_window("Votre Compte n'a pas ete supprimer, veuillez reesseyer", true);
                    a.ShowDialog();
                }
            }
        }