예제 #1
0
 public void Clone(FileChangeInfo info)
 {
     this.add                      = info.add;
     this.close                    = info.close;
     this.delete                   = info.delete;
     this.linesAdded               = info.linesAdded;
     this.linesRemoved             = info.linesRemoved;
     this.open                     = info.open;
     this.paste                    = info.paste;
     this.keystrokes               = info.keystrokes;
     this.netkeys                  = info.netkeys;
     this.syntax                   = info.syntax;
     this.start                    = info.start;
     this.end                      = info.end;
     this.local_start              = info.local_start;
     this.local_end                = info.local_end;
     this.duration_seconds         = info.duration_seconds;
     this.projectDir               = info.projectDir;
     this.fsPath                   = info.fsPath;
     this.name                     = info.name;
     this.update_count             = info.update_count;
     this.fileAgeDays              = info.fileAgeDays;
     this.repoFileContributorCount = info.repoFileContributorCount;
     this.UpdateName();
 }
예제 #2
0
        public List <FileChangeInfo> GetTopKeystrokeFiles()
        {
            List <FileChangeInfo> changeInfos = GetFileChangeInfoSummaryList();

            if (changeInfos == null || changeInfos.Count == 0)
            {
                return(new List <FileChangeInfo>());
            }
            Int32 limit = Math.Min(changeInfos.Count, 3);
            List <FileChangeInfo> orderedInfos = changeInfos.OrderBy(o => o.keystrokes).Reverse().ToList <FileChangeInfo>();
            List <FileChangeInfo> finalList    = new List <FileChangeInfo>();

            for (int i = 0; i < orderedInfos.Count; i++)
            {
                FileChangeInfo info = orderedInfos[i];
                if (info.keystrokes > 0)
                {
                    finalList.Add(info);
                }
                if (finalList.Count >= 3)
                {
                    break;
                }
            }
            return(finalList);
        }
예제 #3
0
        public async Task SaveFileChangeInfoDataSummaryToDisk(FileChangeInfo data)
        {
            string MethodName = "SaveFileChangeInfoDataSummaryToDisk";
            List <FileChangeInfo> changeInfos = GetFileChangeInfoSummaryList();
            bool foundExisting = false;

            foreach (FileChangeInfo changeInfo in changeInfos)
            {
                if (changeInfo.fsPath.Equals(data.fsPath))
                {
                    changeInfo.Clone(data);
                    foundExisting = true;
                    break;
                }
            }
            if (!foundExisting)
            {
                changeInfos.Add(data);
            }
            string file = FileManager.getFileChangeInfoSummaryFile();

            if (FileManager.FileChangeInfoSummaryFileExists())
            {
                File.SetAttributes(file, FileAttributes.Normal);
            }

            JsonObject jsonToSave = BuildJsonObjectFromList(changeInfos);

            try
            {
                string content = jsonToSave.ToString();
                content = content.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("\r", string.Empty);
                File.WriteAllText(file, content, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
                //
            }

            _fileChangeInfos = new List <FileChangeInfo>(changeInfos);
        }
예제 #4
0
        public List <FileChangeInfo> GetFileChangeInfoSummaryList()
        {
            _fileChangeInfos = new List <FileChangeInfo>();
            if (!FileManager.FileChangeInfoSummaryFileExists())
            {
                // create it
                ClearFileChangeInfoDataSummary();
            }

            string fileChangeInfoSummary = FileManager.getFileChangeInfoSummaryData();

            // it'll be a map of file to FileChangeInfo objects
            IDictionary <string, object> jsonObj =
                (IDictionary <string, object>)SimpleJson.DeserializeObject(fileChangeInfoSummary, new Dictionary <string, object>());

            foreach (string key in jsonObj.Keys)
            {
                FileChangeInfo info = new FileChangeInfo();

                jsonObj.TryGetValue(key, out object infoObj);
                try
                {
                    JsonObject infoObjJson = (infoObj == null) ? null : (JsonObject)infoObj;
                    if (infoObjJson != null)
                    {
                        info.CloneFromDictionary(infoObjJson);
                    }
                } catch (Exception e)
                {
                    //
                }

                _fileChangeInfos.Add(info);
            }

            return(_fileChangeInfos);
        }
예제 #5
0
        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());
        }