//This only runs the first time the page is made, so when a user first logs in (due to page caching) protected override async void OnInitialize()// { base.OnInitialize(); currentUserName = AppDataAccessor.GetUsername(); BindableCollection <Season> downloadedSeasons = await DownloadAccessor.Instance.GetDownloadsModel(true); if (ServiceAccessor.ConnectedToInternet()) { SeasonsDropDown = await GetSortedSeasons(); } else { SeasonsDropDown = downloadedSeasons; } string savedSeasonId = AppDataAccessor.GetTeamContext().seasonID; if (savedSeasonId != null && SeasonsDropDown.Any()) { SelectedSeason = SeasonsDropDown.Where(u => u.seasonId == savedSeasonId).FirstOrDefault() ?? SeasonsDropDown[0]; } else { SelectedSeason = SeasonsDropDown.LastOrDefault(u => u.year >= DateTime.Now.Year) ?? SeasonsDropDown[0]; AppDataAccessor.SetTeamContext(SelectedSeason.seasonId, SelectedSeason.owningTeam.teamID); } if (!SeasonsDropDown.Any()) { //show message here if no seasons } }
protected override void OnInitialize() { DownloadAccessor.Instance.DeleteTempData(); base.OnInitialize(); ButtonText = "Login"; FormVisibility = "Visible"; ProgressRingVisibility = "Collapsed"; RememberMe = false; //If Username exists in roaming settings, enter it for user String username = AppDataAccessor.GetUsername(); if (username != null) { UserName = username; // Check to see if a password has been saved PasswordCredential cred = AppDataAccessor.GetPassword(); if (cred != null) { Password = cred.Password; LoginAttempt(); } } }
protected override void OnActivate()//called every page load { base.OnActivate(); if (currentUserName != AppDataAccessor.GetUsername()) { Groups = new BindableCollection <HubGroupViewModel>();//clears old page after logout OnInitialize(); } SettingsPane.GetForCurrentView().CommandsRequested += CharmsData.SettingCharmManager_HubCommandsRequested; ProgressRingVisibility = Visibility.Collapsed; ProgressRingIsActive = false; PageIsEnabled = true; LastViewedResponse response = AppDataAccessor.GetLastViewed(); if (response.ID != null && ServiceAccessor.ConnectedToInternet()) { Game LastViewedGame = new Game { gameId = response.ID, opponent = response.name, date = DateTime.Parse(response.timeStamp) }; //this is actually a playlist - not a game GameViewModel lastViewed = new GameViewModel(LastViewedGame, true, isLastviewed: true); lastViewed.Thumbnail = response.thumbnail; lastViewed.Stretch = "UniformToFill"; LastViewedVM = new HubGroupViewModel() { Name = "Last Viewed", Games = new BindableCollection <GameViewModel>() }; LastViewedVM.Games.Add(lastViewed); if (Groups.Count == 0 && (NoScheduleEntriesText == null || NoScheduleEntriesText == "")) { ProgressRingVisibility = Visibility.Visible; ProgressRingIsActive = true; } if (Groups.Count >= 3) { HubGroupViewModel oldLastViewed = Groups.Where(u => u.Name == "Last Viewed").FirstOrDefault(); if (oldLastViewed != null) { Groups[Groups.IndexOf(oldLastViewed)] = LastViewedVM; } else { Groups.Insert(1, LastViewedVM); } } } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter != null) { SplashScreen splash = (SplashScreen)e.Parameter; splash.Dismissed += new TypedEventHandler <SplashScreen, object>(DismissedEventHandler); AppDataAccessor.SetSplashScreen(splash); loginStackPanel.Margin = new Thickness(0, splash.ImageLocation.Top, 0, 0); } else { loginStackPanel.Margin = new Thickness(0, 0, 0, 0); FadeInForm.Begin(); FadeInBackground.Begin(); } // Set the login image here double height = 0; double width = 0; double x = 0; y = 0; Nullable <SplashScreenResponse> response = AppDataAccessor.GetSplashScreen(); if (response != null) { height = response.Value.Height; width = response.Value.Width; x = response.Value.X; y = response.Value.Y; } loginImage.Height = height; loginImage.Width = Width; //If Username exists in roaming settings, enter it for user String username = AppDataAccessor.GetUsername(); if (username != null) { //UserName.Text = username; UserName.SelectionStart = UserName.Text.ToCharArray().Length; UserName.SelectionLength = 0; } }
public async void LoginAttempt() { // Attempt to get the debug urls from a config file InitResponse initResponse = await ServiceAccessor.Init(); if (initResponse.status == SERVICE_RESPONSE.SUCCESS) { if (Password == null || Password == "") { Password = initResponse.Password; } if (UserName == null || UserName == "") { UserName = initResponse.Username; } } // Get the username and password from the view string loginArgs = JsonConvert.SerializeObject(new LoginSender { Username = UserName, Password = Password }); // Show the user a call is being made in the background ButtonText = "loading"; FormVisibility = "Collapsed"; ProgressRingVisibility = "Visible"; LoginResponse response = await ServiceAccessor.Login(loginArgs); if (response.status == SERVICE_RESPONSE.SUCCESS) { if (AppDataAccessor.GetUsername() != userName) { AppDataAccessor.SetUsername(UserName); } if (RememberMe) { AppDataAccessor.SetPassword(Password); AppDataAccessor.SetLoginDate(DateTime.Now.ToString()); } navigationService.NavigateToViewModel <HubViewModel>(); } else if (response.status == SERVICE_RESPONSE.NULL_RESPONSE) { LoginFeedback = "Connection with server failed, please try again"; } else if (response.status == SERVICE_RESPONSE.CREDENTIALS) { LoginFeedback = "Invalid Username or Password"; } else if (response.status == SERVICE_RESPONSE.NO_CONNECTION) { DateTime LastLogin = new DateTime(); string loginDate = AppDataAccessor.GetLoginDate(); if (loginDate != null) { await Task.Run(() => LastLogin = DateTime.Parse(AppDataAccessor.GetLoginDate()));//need an async task in order to the page to navigate TimeSpan ts = DateTime.Now - LastLogin; if (ts.Days <= 14) { navigationService.NavigateToViewModel <HubViewModel>(); } else { APIExceptionDialog.ShowNoInternetConnectionLoginDialog(null, null); } } else { APIExceptionDialog.ShowNoInternetConnectionLoginDialog(null, null); } } // Dismiss the loading indicator ButtonText = "Login"; FormVisibility = "Visible"; ProgressRingVisibility = "Collapsed"; }