Ejemplo n.º 1
0
        private async void ApplicationRoutine(object sender, EventArgs e)
        {
            try
            {
                if (NoRefresh)
                {
                    return;
                }
                // Send new messages
                if (MessagesQueue.Count != 0)
                {
                    var temp = new List <SendMessageBindingModel>(MessagesQueue);
                    MessagesQueue.Clear();
                    await TwatsAppService.SendMessages(temp);
                }
                await TwatsAppService.GetUpdates(success : GetUpdateSuccess);

                if (TokenExpired())
                {
                    var logged = await Authenticate();

                    if (!logged)
                    {
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.InnerException.Message);
                Close();
            }
        }
Ejemplo n.º 2
0
        private async void LoginBtnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Spinner.Work();
                UserForm.Password = Password.Password;
                if (!isLogin)
                {
                    UserForm.ConfirmPassword = ConfirmPassword.Password;
                    await TwatsAppService.Register(UserForm, HandleRegisterError);
                }
                await TwatsAppService.Login(UserForm, HandleLoginError);

                DialogResult = true;
                Close();
            }
            catch (LoginException)
            {
            }
            catch (Exception ex)
            {
                AlertLabel.Visibility = Visibility.Visible;
                AlertContent.Text     = ex.Message;
            }
            finally
            {
                Spinner.Stop();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the initial data needed for the chat to start
        /// </summary>
        private async Task InitializeApp()
        {
            Spinner.Work();
            Hide();
            bool logged = await Authenticate();

            if (!logged)
            {
                Close();
                return;
            }
            Show();
            await TwatsAppService.GetContactsAndMessages(error : GetContactsError, success : GetContactsSuccess);

            Spinner.Stop();
            NoRefresh = false;
            return;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Authenticates the user, if it is his first launch it will take him to login screen
        /// else, it would authenticate  based on Properties.settings.default
        /// </summary>
        /// <returns> a boolean indicating if the user successfully logged in</returns>
        private async Task <bool> Authenticate()
        {
            NoRefresh = true;
            try
            {
                if (HasAllSettings())
                {
                    await TwatsAppService.Login(new AccountBindingModel { UserName = Properties.Settings.Default.Username, Password = Properties.Settings.Default.Password }, ex => { throw new LoginException(); });

                    NoRefresh = false;
                    return(true);
                }
                return(RequestLoginInNewWindow());
            }
            catch (LoginException)
            {
                return(RequestLoginInNewWindow());
            }
        }