TeamsNetphoneLink/TeamsNetphoneLinkWPF/WPF/MVVM/LogViewModel.cs
2025-03-25 22:43:13 +01:00

76 lines
2.4 KiB
C#

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
namespace TeamsNetphoneLink.WPF.MVVM
{
public class LogEntry
{
public DateTime Time { get; set; }
public string Subsystem { get; set; }
public string Type { get; set; }
public string Message { get; set; }
}
public class LogViewModel : INotifyPropertyChanged
{
// Collection to hold log entries
public ObservableCollection<LogEntry> LogEntries { get; } = new ObservableCollection<LogEntry>();
// Add a log entry
public void AddLogEntry(string entry)
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
LogEntries.Add(new LogEntry { Time = DateTime.Now, Type = "Info", Subsystem = "NONE", Message = entry });
});
}
// Add a log entry
public void AddLogEntry(string subsystem, string entry)
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
LogEntries.Add(new LogEntry { Time = DateTime.Now, Type = "Info", Subsystem = subsystem, Message = entry });
});
}
// Add a log entry
public void AddLogEntry(string type, string subsystem, string entry)
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
LogEntries.Add(new LogEntry { Time = DateTime.Now, Type = type, Subsystem = subsystem, Message = entry });
});
}
public void AddLogEntry(DateTime time, string subsystem, string message)
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
LogEntries.Add(new LogEntry { Time = time, Type = "Info", Subsystem = subsystem, Message = message });
});
}
// Clear all log entries
public void ClearLogEntries()
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
LogEntries.Clear();
});
}
// Implement INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}