public static async Task <UserStatus> GetUserStatusAsync(bool isInitialCall) { bool online = await IsOnlineAsync(); bool softwareSessionFileExists = SoftwareCoUtil.softwareSessionFileExists(); bool jwtExists = SoftwareCoUtil.jwtExists(); if (!isInitialCall && isOnline && !jwtExists) { await SoftwareUserSession.CreateAnonymousUserAsync(online); } bool loggedIn = await IsLoggedOn(online); UserStatus currentUserStatus = new UserStatus(); currentUserStatus.loggedIn = loggedIn; if (online && loggedInCacheState != loggedIn) { // change in logged in state, send heatbeat and fetch kpm SendHeartbeat("STATE_CHANGE:LOGGED_IN:" + loggedIn); try { Thread.Sleep(1000); SoftwareCoPackage.fetchSessionSummaryInfoAsync(); } catch (ThreadInterruptedException e) { // } } loggedInCacheState = loggedIn; SoftwareLaunchCommand.UpdateEnabledState(currentUserStatus); SoftwareLoginCommand.UpdateEnabledState(currentUserStatus); return(currentUserStatus); }
public static async void RefetchUserStatusLazily(int tryCountUntilFoundUser) { checkingLoginState = true; UserStatus userStatus = await GetUserStatusAsync(true); if (!userStatus.loggedIn && tryCountUntilFoundUser > 0) { tryCountUntilFoundUser -= 1; try { Thread.Sleep(1000 * 10); RefetchUserStatusLazily(tryCountUntilFoundUser); } catch (ThreadInterruptedException e) { // } } else { SoftwareCoPackage.fetchSessionSummaryInfoAsync(); checkingLoginState = false; } }