コード例 #1
0
        private async void InitializeUserInfo()
        {
            bool online = await SoftwareUserSession.IsOnlineAsync();

            bool softwareSessionFileExists = SoftwareCoUtil.softwareSessionFileExists();
            bool jwtExists       = SoftwareCoUtil.jwtExists();
            bool initializedUser = false;

            if (!softwareSessionFileExists || !jwtExists)
            {
                string result = await SoftwareUserSession.CreateAnonymousUserAsync(online);

                if (result != null)
                {
                    initializedUser = true;
                }
            }

            SoftwareUserSession.UserStatus status = await SoftwareUserSession.GetUserStatusAsync(true);

            SoftwareLoginCommand.UpdateEnabledState(status);

            if (initializedUser)
            {
                LaunchLoginPrompt();
            }

            if (online)
            {
                fetchSessionSummaryInfoAsync();

                // send heartbeat
                SoftwareUserSession.SendHeartbeat("INITIALIZED");
            }
        }
コード例 #2
0
        private async Task InitializeUserInfoAsync()
        {
            try
            {
                string MethodName = "InitializeUserInfo";
                Logger.FileLog("Initializing User", MethodName);
                bool online = await SoftwareUserSession.IsOnlineAsync();

                bool   softwareSessionFileExists = FileManager.softwareSessionFileExists();
                object jwt = FileManager.getItem("jwt");
                if (!softwareSessionFileExists || jwt == null || jwt.ToString().Equals(""))
                {
                    string result = await SoftwareUserSession.CreateAnonymousUserAsync(online);
                }

                // check if the "name" is set. if not, get the user
                string name = FileManager.getItemAsString("name");
                if (name == null || name.Equals(""))
                {
                    await SoftwareUserSession.IsLoggedOn(online);

                    SoftwareLoginCommand.UpdateEnabledState(true);
                    SoftwareLaunchCommand.UpdateEnabledState(true);
                }

                long sessionTresholdSeconds = FileManager.getItemAsLong("sessionThresholdInSec");
                if (sessionTresholdSeconds == 0)
                {
                    // update the session threshold in seconds config
                    FileManager.setNumericItem("sessionThresholdInSec", Constants.DEFAULT_SESSION_THRESHOLD_SECONDS);
                }

                if (online)
                {
                    // send heartbeat
                    SoftwareUserSession.SendHeartbeat("INITIALIZED");
                }

                // fetch the session summary
                WallclockManager.Instance.UpdateSessionSummaryFromServerAsync();
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing UserInfo", ex);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public static async void RefetchUserStatusLazily(int tryCountUntilFoundUser)
        {
            try
            {
                bool loggedIn = await IsLoggedOn(true);

                if (!loggedIn && tryCountUntilFoundUser > 0)
                {
                    tryCountUntilFoundUser -= 1;

                    Task.Delay(1000 * 10).ContinueWith((task) => { RefetchUserStatusLazily(tryCountUntilFoundUser); });
                }
                else
                {
                    checkingLoginState = false;
                    if (loggedIn)
                    {
                        SoftwareLoginCommand.UpdateEnabledState(true);
                        SoftwareLaunchCommand.UpdateEnabledState(true);
                        // show they've logged on
                        string       msg     = "Successfully logged on to Code Time.";
                        const string caption = "Code Time";
                        MessageBox.Show(msg, caption, MessageBoxButtons.OK);
                        SoftwareUserSession.SendHeartbeat("STATE_CHANGE: LOGGED_IN:true");

                        // fetch the session summary to get the user's averages
                        WallclockManager.Instance.UpdateSessionSummaryFromServerAsync();

                        SoftwareCoPackage.SendOfflinePluginBatchData();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("RefetchUserStatusLazily ,error : " + ex.Message, ex);
            }
        }