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
{
///
/// Represents the synchronization module main view, view model.
///
///
public class MainViewVM : ViewModel
{
///
/// Initializes a new instance of the class.
///
public MainViewVM()
{
MainViewLogger logger = new MainViewLogger();
logger.NewLog += (output) =>
{
Log += output + Environment.NewLine;
};
LogManager.RegisterLogger(logger);
}
private String _log;
///
/// Gets or sets the current application log text.
///
public String Log
{
get { return _log; }
set { _log = value; RaisePropertyChanged(nameof(Log)); }
}
#region Custom Logger
///
/// Represents a custom logger.
///
///
public class MainViewLogger : ILogger
{
///
/// Gets or sets a value indicating whether this is enabled.
///
public bool Enabled { get; set; }
///
/// Gets or sets a value indicating whether this will be notified about logs without waiting for the logs queue.
///
public bool Immediate { get; set; }
///
/// Occurs when a new log item is available.
///
public event Action NewLog;
///
/// Initializes a new instance of the class.
///
public MainViewLogger()
{
Enabled = true;
Immediate = true;
}
///
/// Called when a new library exception is available.
///
/// The output.
public void OnError(LogItemBase output)
{
NewLog?.Invoke(output.TimeStamp.ToTimeString() + ": " + output.GetMessage());
}
///
/// Called when a new library trace is available.
///
/// The output.
public void OnTrace(LogItemBase output)
{
NewLog?.Invoke(output.TimeStamp.ToTimeString() + ": " + output.GetMessage());
}
}
#endregion
}
}