コード例 #1
0
        private void getDiffInfo(FileHistoryDTO fileHistory, string newContent, string oldContent)
        {
            var dmp  = new diff_match_patch();
            var diff = dmp.diff_main(newContent, oldContent);

            dmp.diff_cleanupSemantic(diff);
            dmp.diff_prettyHtml(diff);

            var htmlContent    = new StringBuilder("");
            var linesIncreased = 0;
            var linesDecreased = 0;

            for (int i = 0; i < diff.Count; i++)
            {
                htmlContent.Append(diff[i]);
                if (diff[i].operation == Operation.DELETE)
                {
                    linesDecreased++;
                }
                if (diff[i].operation == Operation.INSERT)
                {
                    linesIncreased++;
                }
            }
            fileHistory.ContentDiffHtml = htmlContent.ToString();
            fileHistory.LinesDecreased  = linesDecreased;
            fileHistory.LinesIncreased  = linesIncreased;
            fileHistory.SizeDiff        = newContent.Length - oldContent.Length;
        }
コード例 #2
0
        public async Task <FileHistoryDTO> CreateAsync(FileHistoryDTO item)
        {
            var createdItem = _mapper.Map <FileHistory>(item);
            var fileHistory = await _fileHistoryRepository.CreateAsync(createdItem);

            return(await GetByIdAsync(fileHistory.Id));
        }
コード例 #3
0
        private async Task <FileHistoryDTO> initializeNewFileHistoryDTO(File file, string previousContent, string comment, int userId)
        {
            var fileHistory = new FileHistoryDTO
            {
                FileId         = file.Id,
                AuthorId       = userId,
                AuthorName     = (await _userService.GetUserById(userId)).NickName,
                ChangedAt      = DateTime.Now,
                ChangingAction = comment
            };

            getDiffInfo(fileHistory, file.Content, previousContent);
            return(fileHistory);
        }