private WallclockManager() { // fetch the current day from the sessions.json this._currentDay = FileManager.getItemAsString("currentDay"); timer = new System.Threading.Timer( WallclcockTimerHandlerAsync, null, 1000, THIRTY_SECONDS_IN_MILLIS); sessionSummaryMgr = SessionSummaryManager.Instance; newDayTimer = new System.Threading.Timer( GetNewDayChecker, null, 1000, ONE_MINUTE * 10); }
private DocEventManager() { sessionSummaryMgr = SessionSummaryManager.Instance; }
public async void SolutionEventOpenedAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (!PLUGIN_READY) { string solutionDir = await GetSolutionDirectory(); if (solutionDir == null || solutionDir.Equals("")) { Task.Delay(3000).ContinueWith((task) => { SolutionEventOpenedAsync(); }); return; } // init the doc event mgr and inject ObjDte docEventMgr = DocEventManager.Instance; DocEventManager.ObjDte = ObjDte; // init the session summary mgr sessionSummaryMgr = SessionSummaryManager.Instance; sessionSummaryMgr.InjectAsyncPackage(this); // init the event manager and inject this EventManager.Instance.InjectAsyncPackage(this); // update the latestPayloadTimestampEndUtc NowTime nowTime = SoftwareCoUtil.GetNowTime(); FileManager.setNumericItem("latestPayloadTimestampEndUtc", nowTime.now); // init the wallclock WallclockManager wallclockMgr = WallclockManager.Instance; wallclockMgr.InjectAsyncPackage(this, ObjDte); // setup event handlers _textDocKeyEvent.AfterKeyPress += docEventMgr.AfterKeyPressedAsync; _docEvents.DocumentOpened += docEventMgr.DocEventsOnDocumentOpenedAsync; _docEvents.DocumentClosing += docEventMgr.DocEventsOnDocumentClosedAsync; _docEvents.DocumentSaved += docEventMgr.DocEventsOnDocumentSaved; _docEvents.DocumentOpening += docEventMgr.DocEventsOnDocumentOpeningAsync; // init the code metrics tree mgr CodeMetricsTreeManager.Instance.InjectAsyncPackage(this); // initialize the menu commands await SoftwareLaunchCommand.InitializeAsync(this); await SoftwareDashboardLaunchCommand.InitializeAsync(this); await SoftwareTopFortyCommand.InitializeAsync(this); await SoftwareLoginCommand.InitializeAsync(this); await SoftwareToggleStatusInfoCommand.InitializeAsync(this); await SoftwareOpenCodeMetricsTreeCommand.InitializeAsync(this); if (_softwareRepoUtil == null) { _softwareRepoUtil = new SoftwareRepoManager(); } // Create an AutoResetEvent to signal the timeout threshold in the // timer callback has been reached. var autoEvent = new AutoResetEvent(false); offlineDataTimer = new System.Threading.Timer( SendOfflineData, null, ONE_MINUTE, ONE_MINUTE * 15); repoCommitsTimer = new System.Threading.Timer( ProcessRepoJobs, autoEvent, ONE_MINUTE * 5, ONE_MINUTE * 20); keystrokeTimer = new System.Threading.Timer( ProcessKeystrokePayload, autoEvent, ONE_MINUTE, ONE_MINUTE); // initialize the status bar before we fetch the summary data InitializeStatusBar(); // make sure the last payload is in memory FileManager.GetLastSavedKeystrokeStats(); // check if we've shown the readme or not bool initializedVisualStudioPlugin = FileManager.getItemAsBool("visualstudio_CtInit"); if (!initializedVisualStudioPlugin) { DashboardManager.Instance.LaunchReadmeFileAsync(); FileManager.setBoolItem("visualstudio_CtInit", true); // launch the tree view CodeMetricsTreeManager.Instance.OpenCodeMetricsPaneAsync(); } Task.Delay(3000).ContinueWith((task) => { EventManager.Instance.CreateCodeTimeEvent("resource", "load", "EditorActivate"); }); string PluginVersion = GetVersion(); Logger.Info(string.Format("Initialized Code Time v{0}", PluginVersion)); PLUGIN_READY = true; } }
public async Task <string> CompletePayloadAndReturnJsonString() { RepoResourceInfo resourceInfo = null; // make sure we have a valid project and identifier if possible if (this.project == null || this.project.directory == null || this.project.directory.Equals("Untitled")) { // try to get a valid project string projectDir = await DocEventManager.GetSolutionDirectory(); if (projectDir != null && !projectDir.Equals("")) { FileInfo fi = new FileInfo(projectDir); project = new PluginDataProject(fi.Name, projectDir); resourceInfo = GitUtilManager.GetResourceInfo(projectDir, false); } } else { resourceInfo = GitUtilManager.GetResourceInfo(this.project.directory, false); } if (resourceInfo != null && resourceInfo.identifier != null && !resourceInfo.identifier.Equals("")) { project.identifier = resourceInfo.identifier; } SessionSummaryManager summaryMgr = SessionSummaryManager.Instance; TimeGapData eTimeInfo = summaryMgr.GetTimeBetweenLastPayload(); NowTime nowTime = SoftwareCoUtil.GetNowTime(); this.end = nowTime.now; this.local_end = nowTime.local_now; // get the TimeData for this project dir await ValidateAndUpdateCumulativeDataAsync(eTimeInfo.session_seconds); this.elapsed_seconds = eTimeInfo.elapsed_seconds; // make sure all of the end times are set foreach (PluginDataFileInfo pdFileInfo in this.source) { pdFileInfo.EndFileInfoTime(nowTime); } double offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes; this.offset = Math.Abs((int)offset); if (TimeZone.CurrentTimeZone.DaylightName != null && TimeZone.CurrentTimeZone.DaylightName != TimeZone.CurrentTimeZone.StandardName) { this.timezone = TimeZone.CurrentTimeZone.DaylightName; } else { this.timezone = TimeZone.CurrentTimeZone.StandardName; } // update the file metrics used in the tree List <FileInfoSummary> fileInfoList = this.GetSourceFileInfoList(); KeystrokeAggregates aggregates = new KeystrokeAggregates(); aggregates.directory = this.project.directory; foreach (FileInfoSummary fileInfo in fileInfoList) { aggregates.Aggregate(fileInfo); FileChangeInfo fileChangeInfo = FileChangeInfoDataManager.Instance.GetFileChangeInfo(fileInfo.fsPath); if (fileChangeInfo == null) { // create a new entry fileChangeInfo = new FileChangeInfo(); } fileChangeInfo.UpdateFromFileInfo(fileInfo); FileChangeInfoDataManager.Instance.SaveFileChangeInfoDataSummaryToDisk(fileChangeInfo); } // increment the session summary minutes and other metrics summaryMgr.IncrementSessionSummaryData(aggregates, eTimeInfo); // create the json payload JsonObject jsonObj = new JsonObject(); jsonObj.Add("start", this.start); jsonObj.Add("local_start", this.local_start); jsonObj.Add("pluginId", this.pluginId); jsonObj.Add("type", this.type); jsonObj.Add("keystrokes", this.keystrokes); jsonObj.Add("project", this.project.GetAsJson()); jsonObj.Add("timezone", this.timezone); jsonObj.Add("offset", this.offset); jsonObj.Add("version", this.version); jsonObj.Add("os", this.os); jsonObj.Add("end", this.end); jsonObj.Add("local_end", this.local_end); jsonObj.Add("cumulative_editor_seconds", this.cumulative_editor_seconds); jsonObj.Add("cumulative_session_seconds", this.cumulative_session_seconds); jsonObj.Add("elapsed_seconds", this.elapsed_seconds); jsonObj.Add("workspace_name", this.workspace_name); jsonObj.Add("hostname", this.hostname); jsonObj.Add("project_null_error", this.project_null_error); // get the source as json jsonObj.Add("source", BuildSourceJson()); return(jsonObj.ToString()); }