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(); } }
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(); } }
/// <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; }
/// <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()); } }