Beispiel #1
0
 public SoftwareData(ProjectInfo projectInfo)
 {
     start   = SoftwareCoUtil.getNowInSeconds();
     project = projectInfo;
     version = SoftwareCoPackage.GetVersion();
     os      = SoftwareCoPackage.GetOs();
 }
        public static async void SendHeartbeat(string reason)
        {
            string jwt    = GetJwt();
            bool   online = await IsOnlineAsync();

            if (online && jwt != null)
            {
                string version = Constants.EditorVersion;

                JsonObject jsonObj = new JsonObject();
                jsonObj.Add("version", SoftwareCoPackage.GetVersion());
                jsonObj.Add("os", SoftwareCoPackage.GetOs());
                jsonObj.Add("pluginId", Constants.PluginId);
                jsonObj.Add("start", SoftwareCoUtil.getNowInSeconds());
                jsonObj.Add("trigger_annotation", reason);
                jsonObj.Add("hostname", SoftwareCoUtil.getHostname());

                string api      = "/data/heartbeat";
                string jsonData = jsonObj.ToString();
                HttpResponseMessage response = await SoftwareHttpManager.SendRequestAsync(HttpMethod.Post, api, jsonData, jwt);

                if (!SoftwareHttpManager.IsOk(response))
                {
                    Logger.Warning("Code Time: Unable to send heartbeat");
                }
            }
        }
Beispiel #3
0
        public PluginData(string projectName, string projectDirectory)
        {
            this.type     = "Events";
            this.pluginId = Constants.PluginId;
            NowTime nowTime = SoftwareCoUtil.GetNowTime();

            start       = nowTime.now;
            local_start = nowTime.local_now;
            offset      = nowTime.offset_minutes;
            version     = SoftwareCoPackage.GetVersion();
            os          = SoftwareCoPackage.GetOs();
            source      = new List <PluginDataFileInfo>();
            project     = GetPluginProjectUsingDir(projectDirectory);
            cumulative_editor_seconds  = 0;
            elapsed_seconds            = 0;
            cumulative_session_seconds = 0;
            project_null_error         = "";
            workspace_name             = "";
            hostname = "";
        }
Beispiel #4
0
        private void InitializeData()
        {
            NowTime nowTime = SoftwareCoUtil.GetNowTime();

            this.timestamp       = nowTime.now;
            this.timestamp_local = nowTime.local_now;
            this.pluginId        = Constants.PluginId;
            this.os       = SoftwareCoPackage.GetOs();
            this.hostname = SoftwareCoUtil.getHostname();
            this.version  = SoftwareCoPackage.GetVersion();
            if (TimeZone.CurrentTimeZone.DaylightName != null &&
                TimeZone.CurrentTimeZone.DaylightName != TimeZone.CurrentTimeZone.StandardName)
            {
                this.timezone = TimeZone.CurrentTimeZone.DaylightName;
            }
            else
            {
                this.timezone = TimeZone.CurrentTimeZone.StandardName;
            }
        }
        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)
        {
            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);
            }
        }
        public async Task GetNewDayCheckerAsync()
        {
            if (SoftwareCoUtil.IsNewDay())
            {
                SessionSummaryManager.Instance.ÇlearSessionSummaryData();

                // send the offline data
                SoftwareCoPackage.SendOfflinePluginBatchData();

                // clear the last payload in memory
                FileManager.ClearLastSavedKeystrokeStats();

                // send the offline events
                EventManager.Instance.SendOfflineEvents();

                // send the offline TimeData payloads
                // this will clear the time data summary as well
                TimeDataManager.Instance.SendTimeDataAsync();

                // day does't match. clear the wall clock time,
                // the session summary, time data summary,
                // and the file change info summary data
                ClearWcTime();

                // set the current day
                NowTime nowTime = SoftwareCoUtil.GetNowTime();
                _currentDay = nowTime.day;

                // update the current day
                FileManager.setItem("currentDay", _currentDay);
                // update the last payload timestamp
                FileManager.setNumericItem("latestPayloadTimestampEndUtc", 0);

                // update the session summary global and averages for the new day
                Task.Delay(ONE_MINUTE).ContinueWith((task) => { WallclockManager.Instance.UpdateSessionSummaryFromServerAsync(); });
            }
        }
        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;
            }
        }
Beispiel #9
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void Execute(object sender, EventArgs e)
 {
     SoftwareCoPackage.LaunchCodeTimeDashboardAsync();
 }
Beispiel #10
0
 public void InjectAsyncPackage(SoftwareCoPackage package)
 {
     this.package = package;
 }
 public void InjectAsyncPackage(SoftwareCoPackage package, DTE2 ObjDte)
 {
     this.package = package;
     this.ObjDte  = ObjDte;
 }
Beispiel #12
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void Execute(object sender, EventArgs e)
 {
     SoftwareCoPackage.ToggleStatusInfo();
 }