<commit_before>﻿// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.DocAsCode.Build.Engine.Incrementals
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Microsoft.DocAsCode.Common;
    using Microsoft.DocAsCode.Plugins;
    using Microsoft.DocAsCode.Utility;

    public sealed class BuildMessageInfo
    {
        private Listener _listener;
        private readonly Dictionary<string, List<LogItem>> _logs;

        public BuildMessageInfo()
        {
            _logs = new Dictionary<string, List<LogItem>>();
        }

        private BuildMessageInfo(IDictionary<string, List<LogItem>> logs)
        {
            if (logs == null)
            {
                throw new ArgumentNullException(nameof(logs));
            }
            _logs = new Dictionary<string, List<LogItem>>(logs);
        }

        /// <summary>
        /// Get messages logged for file
        /// </summary>
        /// <param name="file">file path from working directory</param>
        /// <returns>logged messages</returns>
        public IEnumerable<ILogItem> GetMessages(string file)
        {
            List<LogItem> messages;
            if (_logs.TryGetValue(file, out messages))
            {
                return messages;
            }
            return Enumerable.Empty<ILogItem>();
        }

        public ILoggerListener GetListener()
        {
            if (_listener == null)
            {
                _listener = new Listener(this);
            }
            return _listener;
        }

        /// <summary>
        /// relay messages for file
        /// </summary>
        /// <param name="file">file path from working directory</param>
        public void Replay(string file)
        {
            foreach (var item in GetMessages(file))
            {
                Logger.Log(item);
            }
        }

        private void WriteLine(ILogItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (item.File == null)
            {
                return;
            }
            string fileFromWorkingDir = item.File;
            if (!PathUtility.IsRelativePath(item.File))
            {
                fileFromWorkingDir = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, item.File);
            }<commit_msg>fix warningrelay bug: format file path (#813)<commit_after>﻿// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.DocAsCode.Build.Engine.Incrementals
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Microsoft.DocAsCode.Common;
    using Microsoft.DocAsCode.Plugins;
    using Microsoft.DocAsCode.Utility;

    public sealed class BuildMessageInfo
    {
        private Listener _listener;
        private readonly Dictionary<string, List<LogItem>> _logs;

        public BuildMessageInfo()
        {
            _logs = new Dictionary<string, List<LogItem>>();
        }

        private BuildMessageInfo(IDictionary<string, List<LogItem>> logs)
        {
            if (logs == null)
            {
                throw new ArgumentNullException(nameof(logs));
            }
            _logs = new Dictionary<string, List<LogItem>>(logs);
        }

        /// <summary>
        /// Get messages logged for file
        /// </summary>
        /// <param name="file">file path from working directory</param>
        /// <returns>logged messages</returns>
        public IEnumerable<ILogItem> GetMessages(string file)
        {
            List<LogItem> messages;
            if (_logs.TryGetValue(file, out messages))
            {
                return messages;
            }
            return Enumerable.Empty<ILogItem>();
        }

        public ILoggerListener GetListener()
        {
            if (_listener == null)
            {
                _listener = new Listener(this);
            }
            return _listener;
        }

        /// <summary>
        /// relay messages for file
        /// </summary>
        /// <param name="file">file path from working directory</param>
        public void Replay(string file)
        {
            foreach (var item in GetMessages(file))
            {
                Logger.Log(item);
            }
        }

        private void WriteLine(ILogItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (item.File == null)
            {
                return;
            }
            string fileFromWorkingDir = item.File.BackSlashToForwardSlash();
            if (!PathUtility.IsRelativePath(item.File))
            {
                fileFromWorkingDir = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, item.File);
            }
{'fraction_non_alphanumeric': 0.09449901768172889, 'fraction_numerical': 0.0005893909626719057, 'mean_word_length': 1.6350931677018634, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5937291', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1243, 'n_words': 312}