aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/MainViewVM.cs
blob: 48a5c64bd42142a4bec0c9eacfbe7c18b8e779f1 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Logging;
using Tango.SharedUI;

namespace Tango.MachineStudio.Synchronization.ViewModels
{
    /// <summary>
    /// Represents the synchronization module main view, view model.
    /// </summary>
    /// <seealso cref="Tango.SharedUI.ViewModel" />
    public class MainViewVM : ViewModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewVM"/> class.
        /// </summary>
        public MainViewVM()
        {
            MainViewLogger logger = new MainViewLogger();
            logger.NewLog += (output) =>
            {
                Log += output + Environment.NewLine;
            };

            LogManager.RegisterLogger(logger);
        }

        private String _log;
        /// <summary>
        /// Gets or sets the current application log text.
        /// </summary>
        public String Log
        {
            get { return _log; }
            set { _log = value; RaisePropertyChanged(nameof(Log)); }
        }

        #region Custom Logger

        /// <summary>
        /// Represents a custom logger.
        /// </summary>
        /// <seealso cref="Tango.Logging.ILogger" />
        public class MainViewLogger : ILogger
        {
            /// <summary>
            /// Gets or sets a value indicating whether this <see cref="T:Tango.Logging.ILogger" /> is enabled.
            /// </summary>
            public bool Enabled { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether this <see cref="T:Tango.Logging.ILogger" /> will be notified about logs without waiting for the logs queue.
            /// </summary>
            public bool Immediate { get; set; }

            /// <summary>
            /// Occurs when a new log item is available.
            /// </summary>
            public event Action<String> NewLog;

            /// <summary>
            /// Initializes a new instance of the <see cref="MainViewLogger"/> class.
            /// </summary>
            public MainViewLogger()
            {
                Enabled = true;
                Immediate = true;
            }

            /// <summary>
            /// Called when a new library exception is available.
            /// </summary>
            /// <param name="output">The output.</param>
            public void OnError(LogItemBase output)
            {
                NewLog?.Invoke(output.TimeStamp.ToTimeString() + ": " + output.GetMessage());
            }

            /// <summary>
            /// Called when a new library trace is available.
            /// </summary>
            /// <param name="output">The output.</param>
            public void OnTrace(LogItemBase output)
            {
                NewLog?.Invoke(output.TimeStamp.ToTimeString() + ": " + output.GetMessage());
            }
        }

        #endregion
    }
}