aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Logging/EmbeddedLogItem.cs
blob: 607472e82a989d5ac7f76a32dc2031801e67cdf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Logging;
using Tango.PMR.Debugging;

namespace Tango.Integration.Logging
{
    public class EmbeddedLogItem : MessageLogItem
    {
        /// <summary>
        /// Gets or sets the debug log response.
        /// </summary>
        public StartDebugLogResponse DebugLogResponse { get; set; }

        private int _repeated;
        /// <summary>
        /// Gets or sets the number of times this message has been received continuously.
        /// </summary>
        public int Repeated
        {
            get { return _repeated; }
            set { _repeated = value; RaisePropertyChanged(nameof(Repeated)); RaisePropertyChanged(nameof(MessagePlusRepeated)); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EmbeddedLogItem"/> class.
        /// </summary>
        /// <param name="debugLogResponse">The debug log response.</param>
        public EmbeddedLogItem(StartDebugLogResponse debugLogResponse)
        {
            Repeated = 1;
            DebugLogResponse = debugLogResponse;
            Category = (LogCategory)debugLogResponse.Category;
            Message = debugLogResponse.Message;
            CallerFile = debugLogResponse.FileName;
            CallerLineNumber = (int)debugLogResponse.LineNumber;
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return String.Format("[{0}] [{1}] [{2}] [{3}] [{4}] [{5}]: {6}", TimeStamp.ToString("HH:mm:ss.ff"), DebugLogResponse.Category, Path.GetFileName(DebugLogResponse.FileName), DebugLogResponse.LineNumber, DebugLogResponse.ModuleId, DebugLogResponse.Filter, DebugLogResponse.Message);
        }

        /// <summary>
        /// Gets the message plus repeated.
        /// </summary>
        public String MessagePlusRepeated
        {
            get { return Repeated > 1 ? String.Format("{0} ({1})", Message, Repeated) : Message; }
        }

        /// <summary>
        /// Gets the relative caller file path.
        /// </summary>
        /// <returns></returns>
        protected override string GetRelativeCallerFilePath()
        {
            return CallerFile;
        }
    }
}