public async Task <TimeData> GetTodayTimeDataSummary(PluginDataProject proj) { NowTime nowTime = SoftwareCoUtil.GetNowTime(); List <TimeData> list = GetTimeDataList(); if (proj == null || proj.directory == null || proj.directory.Equals("")) { proj = await PluginData.GetPluginProject(); } if (proj == null || proj.directory == null || proj.directory.Equals("")) { proj = new PluginDataProject("Unnamed", "Untitled"); } if (list != null && list.Count > 0) { foreach (TimeData td in list) { if (td.day.Equals(nowTime.local_day) && td.project.directory.Equals(proj.directory)) { return(td); } } } return(await GetNewTimeDataSummary(proj)); }
public static PluginDataProject GetPluginDataFromDictionary(IDictionary <string, object> dict) { string projName = SoftwareCoUtil.ConvertObjectToString(dict, "name"); string projDir = SoftwareCoUtil.ConvertObjectToString(dict, "directory"); string identifierVal = SoftwareCoUtil.ConvertObjectToString(dict, "identifier"); PluginDataProject project = new PluginDataProject(projName, projDir); project.identifier = identifierVal; return(project); }
public async Task UpdateEditorSeconds(long editor_seconds) { PluginDataProject project = await PluginData.GetPluginProject(); TimeData td = await GetTodayTimeDataSummary(project); td.editor_seconds += editor_seconds; td.editor_seconds = Math.Max(td.editor_seconds, td.session_seconds); SaveTimeDataSummaryToDisk(td); }
public async Task <TimeData> GetNewTimeDataSummary(PluginDataProject project) { NowTime nowTime = SoftwareCoUtil.GetNowTime(); TimeData td = new TimeData(); td.day = nowTime.local_day; td.timestamp = nowTime.utc_end_of_day; td.timestamp_local = nowTime.local_end_of_day; td.project = project; return(td); }
public TimeData GeTimeSummaryFromDictionary(IDictionary <string, object> dict) { TimeData summary = new TimeData(); summary.timestamp = SoftwareCoUtil.ConvertObjectToLong(dict, "timestamp"); summary.timestamp_local = SoftwareCoUtil.ConvertObjectToLong(dict, "timestamp_local"); summary.editor_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "editor_seconds"); summary.session_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "session_seconds"); summary.file_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "file_seconds"); summary.day = SoftwareCoUtil.ConvertObjectToString(dict, "day"); summary.project = PluginDataProject.GetPluginDataFromDictionary(dict); return(summary); }
public async Task <TimeData> UpdateSessionAndFileSecondsAsync(PluginDataProject project, long session_seconds) { TimeData td = await GetTodayTimeDataSummary(project); if (td != null) { td.file_seconds += 60; td.session_seconds += session_seconds; td.editor_seconds = Math.Max(td.editor_seconds, td.session_seconds); td.file_seconds = Math.Min(td.file_seconds, td.session_seconds); SaveTimeDataSummaryToDisk(td); } return(td); }
public async Task UpdateSessionFromSummaryApiAsync(long currentDayMinutes) { NowTime nowTime = SoftwareCoUtil.GetNowTime(); CodeTimeSummary ctSummary = this.GetCodeTimeSummary(); long diff = ctSummary.activeCodeTimeMinutes < currentDayMinutes ? currentDayMinutes - ctSummary.activeCodeTimeMinutes : 0; PluginDataProject project = await PluginData.GetPluginProject(); TimeData td = null; if (project != null) { td = await GetTodayTimeDataSummary(project); } else { List <TimeData> list = GetTimeDataList(); if (list != null && list.Count > 0) { foreach (TimeData timeData in list) { if (timeData.day.Equals(nowTime.local_day)) { td = timeData; break; } } } } if (td == null) { project = new PluginDataProject("Unnamed", "Untitled"); td = new TimeData(); td.day = nowTime.local_day; td.timestamp_local = nowTime.local_now; td.timestamp = nowTime.now; td.project = project; } long secondsToAdd = diff * 60; td.session_seconds += secondsToAdd; td.editor_seconds += secondsToAdd; SaveTimeDataSummaryToDisk(td); }
public static PluginDataProject ConvertObjectToProject(IDictionary <string, object> dict) { dict.TryGetValue("project", out object projJson); try { JsonObject projJsonObj = (projJson == null) ? null : (JsonObject)projJson; if (projJson != null) { return(PluginDataProject.GetPluginDataFromDictionary(projJsonObj)); } } catch (Exception e) { // } return(new PluginDataProject("Unnamed", "Untitled")); }
public static PluginDataProject GetPluginProjectUsingDir(string projectDir) { string name = "Unnamed"; PluginDataProject project; if (projectDir != null && !projectDir.Equals("")) { FileInfo fi = new FileInfo(projectDir); name = fi.Name; project = new PluginDataProject(name, projectDir); } else { project = new PluginDataProject(name, "Untitled"); } return(project); }
public static PluginData BuildFromDictionary(IDictionary <string, object> dict) { PluginDataProject proj = SoftwareCoUtil.ConvertObjectToProject(dict); PluginData pd = new PluginData(proj.name, proj.directory); pd.end = SoftwareCoUtil.ConvertObjectToLong(dict, "end"); pd.start = SoftwareCoUtil.ConvertObjectToLong(dict, "start"); pd.local_end = SoftwareCoUtil.ConvertObjectToLong(dict, "local_end"); pd.local_start = SoftwareCoUtil.ConvertObjectToLong(dict, "local_start"); pd.keystrokes = SoftwareCoUtil.ConvertObjectToLong(dict, "keystrokes"); pd.cumulative_editor_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "cumulative_editor_seconds"); pd.os = SoftwareCoUtil.ConvertObjectToString(dict, "os"); pd.offset = SoftwareCoUtil.ConvertObjectToDouble(dict, "offset"); pd.version = SoftwareCoUtil.ConvertObjectToString(dict, "version"); pd.timezone = SoftwareCoUtil.ConvertObjectToString(dict, "timezone"); pd.cumulative_session_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "cumulative_session_seconds"); pd.pluginId = SoftwareCoUtil.ConvertObjectToInt(dict, "pluginId"); pd.elapsed_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "elapsed_seconds"); pd.workspace_name = SoftwareCoUtil.ConvertObjectToString(dict, "workspace_name"); pd.hostname = SoftwareCoUtil.ConvertObjectToString(dict, "hostname"); pd.project_null_error = SoftwareCoUtil.ConvertObjectToString(dict, "project_null_error"); pd.project = proj; IDictionary <string, object> sourceDict = SoftwareCoUtil.ConvertObjectToSource(dict); if (sourceDict != null && sourceDict.Count > 0) { foreach (KeyValuePair <string, object> entry in sourceDict) { IDictionary <string, object> fileInfoDict = new Dictionary <string, object>(); try { PluginDataFileInfo fileInfo = PluginDataFileInfo.GetPluginDataFromDict((JsonObject)entry.Value); pd.source.Add(fileInfo); } catch (Exception e) { // } } } return(pd); }
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 = ""; }
public void CloneFromDictionary(IDictionary <string, object> dict) { this.timestamp = SoftwareCoUtil.ConvertObjectToLong(dict, "timestamp"); this.timestamp_local = SoftwareCoUtil.ConvertObjectToLong(dict, "timestamp_local"); this.editor_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "editor_seconds"); this.session_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "session_seconds"); this.file_seconds = SoftwareCoUtil.ConvertObjectToLong(dict, "file_seconds"); this.day = SoftwareCoUtil.ConvertObjectToString(dict, "day"); dict.TryGetValue("project", out object projJson); try { JsonObject projJsonObj = (projJson == null) ? null : (JsonObject)projJson; if (projJson != null) { this.project = PluginDataProject.GetPluginDataFromDictionary(projJsonObj); } } catch (Exception e) { // } }
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()); }