Exemplo n.º 1
0
        /// <summary>
        /// La creation de compte va appeller un webservice dans un
        /// BackgroundWorker pour laisser l'UI disponible
        /// </summary>
        private void CreateAccount()
        {
            BackgroundWorker worker = new BackgroundWorker();

            ServiceUser.User newUser = new ServiceUser.User();

            newUser.Name      = _name;
            newUser.Firstname = _firstname;
            newUser.Connected = false;
            newUser.Picture   = _imagebyte;
            newUser.Login     = _login;
            newUser.Pwd       = _password;
            newUser.Role      = _role;

            worker.DoWork += new DoWorkEventHandler((object s, DoWorkEventArgs e) =>
            {
                ServiceUser.ServiceUserClient serviceUser = new ServiceUser.ServiceUserClient();

                Debug.WriteLine("DEBUT");
                _iscreatingaccount = true;

                BackgroundWorker bg = s as BackgroundWorker;
                e.Result            = serviceUser.AddUser(newUser);
            });

            // TODO penser a mettre un comportement en fonction des differents cas notamment en cas de fail
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((object s, RunWorkerCompletedEventArgs e) =>
            {
                Debug.WriteLine("FIN");
                _iscreatingaccount = false;
                WaitingMessage     = "";

                if (e.Cancelled)
                {
                    Debug.WriteLine("CANCELLED");
                    WaitingMessage = "L'opération a été annulée.";
                }
                if (e.Error != null)
                {
                    Debug.WriteLine("ERROR");
                    WaitingMessage = "Erreur lors de la création : " + e.Error.Message;
                }
                bool?res = e.Result as bool?;

                if (res == null)
                {
                    Debug.WriteLine("ERREUR COTE SERVEUR");
                    WaitingMessage = "Erreur côté serveur lors de la création. Veuillez recommencer";
                }
                if (res == true)
                {
                    /// Juste avant de creer la page de confirmation il faut
                    /// enregister les informations dans le NavigationMessenger
                    NavigationMessenger.GetInstance().TransitCreatedUser = newUser;
                    WaitingMessage = "Création réussie";

                    View.CreateUserSuccessView window       = new View.CreateUserSuccessView();
                    ViewModel.CreateUserSuccessViewModel vm = new CreateUserSuccessViewModel(window);
                    window.DataContext = vm;

                    _ns = NavigationService.GetNavigationService(_linkedView);
                    _ns.Navigate(window);
                    WaitingMessage = "";
                }
                else
                {
                    Debug.WriteLine("ECHEC DE L'INSCRIPTION");
                    WaitingMessage = "L'inscription a échoué. Veuillez recommencer.";
                }
            });

            worker.RunWorkerAsync();
            WaitingMessage = "Création du compte";
        }
Exemplo n.º 2
0
        /// <summary>
        /// La creation de compte va appeller un webservice dans un 
        /// BackgroundWorker pour laisser l'UI disponible
        /// </summary>
        private void CreateAccount()
        {
            BackgroundWorker worker = new BackgroundWorker();

            ServiceUser.User newUser = new ServiceUser.User();

            newUser.Name = _name;
            newUser.Firstname = _firstname;
            newUser.Connected = false;
            newUser.Picture = _imagebyte;
            newUser.Login = _login;
            newUser.Pwd = _password;
            newUser.Role = _role;

            worker.DoWork += new DoWorkEventHandler((object s, DoWorkEventArgs e) =>
            {
                ServiceUser.ServiceUserClient serviceUser = new ServiceUser.ServiceUserClient();

                Debug.WriteLine("DEBUT");
                _iscreatingaccount = true;

                BackgroundWorker bg = s as BackgroundWorker;
                e.Result = serviceUser.AddUser(newUser);
            });

            // TODO penser a mettre un comportement en fonction des differents cas notamment en cas de fail
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((object s, RunWorkerCompletedEventArgs e) =>
            {
                Debug.WriteLine("FIN");
                _iscreatingaccount = false;
                WaitingMessage = "";

                if (e.Cancelled) {
                    Debug.WriteLine("CANCELLED");
                    WaitingMessage = "L'opération a été annulée.";
                }
                if (e.Error != null) {
                    Debug.WriteLine("ERROR");
                    WaitingMessage = "Erreur lors de la création : " + e.Error.Message;
                }
                bool? res = e.Result as bool?;

                if (res == null)
                {
                    Debug.WriteLine("ERREUR COTE SERVEUR");
                    WaitingMessage = "Erreur côté serveur lors de la création. Veuillez recommencer";
                }
                if (res == true)
                {
                    /// Juste avant de creer la page de confirmation il faut
                    /// enregister les informations dans le NavigationMessenger
                    NavigationMessenger.GetInstance().TransitCreatedUser = newUser;
                    WaitingMessage = "Création réussie";

                    View.CreateUserSuccessView window = new View.CreateUserSuccessView();
                    ViewModel.CreateUserSuccessViewModel vm = new CreateUserSuccessViewModel(window);
                    window.DataContext = vm;

                    _ns = NavigationService.GetNavigationService(_linkedView);
                    _ns.Navigate(window);
                    WaitingMessage = "";
                }
                else {
                    Debug.WriteLine("ECHEC DE L'INSCRIPTION");
                    WaitingMessage = "L'inscription a échoué. Veuillez recommencer.";
                }
            });

            worker.RunWorkerAsync();
            WaitingMessage = "Création du compte";
        }