public void Login(bool offline) { ToggleControls(); if (string.IsNullOrEmpty(Email)) { MessageBox.Show(string.Format("{0} is required!", _useSession ? "Alias" : "Email"), "Error logging in", MessageBoxButton.OK, MessageBoxImage.Stop); ToggleControls(); return; } if (!offline) { // Prevents the event from being registered doubly if the login fails prematurely. ApplicationState.Model.StashLoading -= Model_StashLoading; ApplicationState.Model.ImageLoading -= Model_ImageLoading; ApplicationState.Model.StashLoading += Model_StashLoading; ApplicationState.Model.ImageLoading += Model_ImageLoading; } Task.Factory.StartNew(() => { // If offline == true, the password is never checked to know if it is correct, but if // passwordChanged == true, the new value is saved to the settings file. This might not be the // behavior the user expects. SecureString password = _passwordChanged ? this._view.txtPassword.SecurePassword : Settings.UserSettings["AccountPassword"].Decrypt(); ApplicationState.CurrentRealm = SelectedRealm; ApplicationState.Model.Authenticate(Email, password, offline, ApplicationState.CurrentRealm); if (_formChanged) { SaveSettings(password); } if (!offline) { _statusController.DisplayMessage("Fetching account name..."); ApplicationState.AccountName = ApplicationState.Model.GetAccountName(ApplicationState.CurrentRealm); _statusController.Ok(); if (ForceRefresh) { ApplicationState.Model.ForceRefresh(); } _statusController.DisplayMessage("Loading characters..."); } else { _statusController.DisplayMessage("Loading Procurement in offline mode..."); } List <Character> chars; try { chars = ApplicationState.Model.GetCharacters(ApplicationState.CurrentRealm); } catch (WebException wex) { Logger.Log(wex); _statusController.NotOK(); throw new Exception("Failed to load characters", wex.InnerException); } _statusController.Ok(); UpdateCharactersByLeague(chars); var items = LoadItems(offline, chars).ToList(); ApplicationState.Model.GetImages(items); ApplicationState.SetDefaults(); if (!offline) { _statusController.DisplayMessage("\nDone!"); PoeTradeOnlineHelper.Instance.Start(); } ApplicationState.Model.Authenticating -= Model_Authenticating; ApplicationState.Model.StashLoading -= Model_StashLoading; ApplicationState.Model.ImageLoading -= Model_ImageLoading; ApplicationState.Model.Throttled -= Model_Throttled; OnLoginCompleted(); }).ContinueWith(t => { Logger.Log(t.Exception.InnerException.ToString()); _statusController.HandleError(t.Exception.InnerException.Message, ToggleControls); }, TaskContinuationOptions.OnlyOnFaulted); }
public void Login(bool offline) { toggleControls(); if (string.IsNullOrEmpty(Email)) { MessageBox.Show(string.Format("{0} is required!", useSession ? "Alias" : "Email"), "Error logging in", MessageBoxButton.OK, MessageBoxImage.Stop); toggleControls(); return; } if (!offline) { ApplicationState.Model.StashLoading += model_StashLoading; ApplicationState.Model.ImageLoading += model_ImageLoading; } Task.Factory.StartNew(() => { SecureString password = formChanged ? this.view.txtPassword.SecurePassword : Settings.UserSettings["AccountPassword"].Decrypt(); ApplicationState.Model.Authenticate(Email, password, offline, useSession); if (formChanged) { saveSettings(password); } if (!offline) { ApplicationState.Model.ForceRefresh(); statusController.DisplayMessage("Loading characters..."); } else { statusController.DisplayMessage("Loading Procurement in offline mode..."); } List <Character> chars; try { chars = ApplicationState.Model.GetCharacters(); } catch (WebException wex) { Logger.Log(wex); statusController.NotOK(); throw new Exception("Failed to load characters", wex.InnerException); } statusController.Ok(); updateCharactersByLeague(chars); var items = LoadItems(offline, chars).ToList(); ApplicationState.Model.GetImages(items); ApplicationState.SetDefaults(); if (!offline) { statusController.DisplayMessage("\nDone!"); } ApplicationState.Model.Authenticating -= model_Authenticating; ApplicationState.Model.StashLoading -= model_StashLoading; ApplicationState.Model.ImageLoading -= model_ImageLoading; ApplicationState.Model.Throttled -= model_Throttled; OnLoginCompleted(); }).ContinueWith(t => { Logger.Log(t.Exception.InnerException.ToString()); statusController.HandleError(t.Exception.InnerException.Message, toggleControls); }, TaskContinuationOptions.OnlyOnFaulted); }
public void Login(bool offline) { authOffLine = offline; toggleControls(); Task.Factory.StartNew(() => { if (useSession) { ApplicationState.Model.Authenticate(Email, this.view.txtPassword.SecurePassword, authOffLine, useSession, this.view.txtPassword.Password); } else { SecureString password = formChanged ? this.view.txtPassword.SecurePassword : Settings.UserSettings["AccountPassword"].Decrypt(); ApplicationState.Model.Authenticate(Email, password, authOffLine, useSession); saveSettings(password); } if (!authOffLine) { ApplicationState.Model.ForceRefresh(); } statusController.DisplayMessage("Loading characters..."); List <Character> chars; try { chars = ApplicationState.Model.GetCharacters(); } catch (WebException wex) { Logger.Log(wex); statusController.NotOK(); throw new Exception("Failed to load characters", wex.InnerException); } statusController.Ok(); bool downloadOnlyMyLeagues = false; downloadOnlyMyLeagues = (Settings.UserSettings.ContainsKey("DownloadOnlyMyLeagues") && bool.TryParse(Settings.UserSettings["DownloadOnlyMyLeagues"], out downloadOnlyMyLeagues) && downloadOnlyMyLeagues && Settings.Lists.ContainsKey("MyLeagues") && Settings.Lists["MyLeagues"].Count > 0 ); foreach (var character in chars) { if (character.League == "Void") { continue; } if (downloadOnlyMyLeagues && !Settings.Lists["MyLeagues"].Contains(character.League)) { continue; } ApplicationState.Characters.Add(character); loadCharacterInventory(character); loadStash(character); } if (downloadOnlyMyLeagues && ApplicationState.Characters.Count == 0) { throw new Exception("No characters found in the leagues specified. Check spelling or try setting DownloadOnlyMyLeagues to false in settings"); } ApplicationState.SetDefaults(); statusController.DisplayMessage("\nDone!"); OnLoginCompleted(); }).ContinueWith((t) => { Logger.Log(t.Exception.InnerException.ToString()); statusController.HandleError(t.Exception.InnerException.Message, toggleControls); }, TaskContinuationOptions.OnlyOnFaulted); }