2020-11-27 18:51:02 +08:00
|
|
|
using System;
|
2020-11-28 13:02:57 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-11-27 18:51:02 +08:00
|
|
|
using BililiveRecorder.Core;
|
|
|
|
|
|
|
|
namespace BililiveRecorder.WPF.Models
|
|
|
|
{
|
2020-11-28 13:02:57 +08:00
|
|
|
internal class RootModel : INotifyPropertyChanged, IDisposable
|
2020-11-27 18:51:02 +08:00
|
|
|
{
|
|
|
|
private bool disposedValue;
|
2020-11-28 13:02:57 +08:00
|
|
|
private IRecorder recorder;
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
2020-11-27 18:51:02 +08:00
|
|
|
|
|
|
|
public LogModel Logs { get; } = new LogModel();
|
|
|
|
|
2020-11-28 13:02:57 +08:00
|
|
|
public IRecorder Recorder { get => recorder; internal set => SetField(ref recorder, value); }
|
2020-11-27 18:51:02 +08:00
|
|
|
|
|
|
|
public RootModel()
|
|
|
|
{
|
2020-11-28 13:02:57 +08:00
|
|
|
}
|
2020-11-27 18:51:02 +08:00
|
|
|
|
2020-11-28 13:02:57 +08:00
|
|
|
protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
|
|
|
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
|
|
|
|
{
|
|
|
|
if (EqualityComparer<T>.Default.Equals(field, value)) { return false; }
|
|
|
|
field = value; OnPropertyChanged(propertyName); return true;
|
2020-11-27 18:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
if (!disposedValue)
|
|
|
|
{
|
|
|
|
if (disposing)
|
|
|
|
{
|
|
|
|
// dispose managed state (managed objects)
|
|
|
|
Recorder?.Dispose();
|
|
|
|
Logs.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// free unmanaged resources (unmanaged objects) and override finalizer
|
|
|
|
// set large fields to null
|
|
|
|
disposedValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
|
|
|
// ~RootModel()
|
|
|
|
// {
|
|
|
|
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
|
// Dispose(disposing: false);
|
|
|
|
// }
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
|
Dispose(disposing: true);
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|