コード例 #1
0
        public async Task <IActionResult> GetDiff([FromRoute] string id)
        {
            IDisposable loggingScope = null;

            try
            {
                loggingScope = _logger.BeginScope("ComparisonID {0}", id);
                _logger.LogInformation("Comparing contents.");

                var content = await _contentRepository.GetContent(id).ConfigureAwait(false);

                if (content == null)
                {
                    _logger.LogInformation("Nothing to compare.");
                    return(NoContent());
                }

                var diffResult = _diffService.SimpleDiff(content.Left, content.Right);

                _logger.LogDebug("Comparision result: {0}", diffResult.ToString());

                var result = new DiffResultDto {
                    Id = id, DiffType = diffResult.Type, Diffs = diffResult.Diffs
                };

                _logger.LogInformation("Comparison completed successfully");

                return(new ObjectResult(result));
            }
            finally
            {
                loggingScope?.Dispose();
            }
        }