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;
|
|
|
|
|
2021-05-01 17:57:43 +08:00
|
|
|
#nullable enable
|
2020-11-27 18:51:02 +08:00
|
|
|
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;
|
2021-05-01 17:57:43 +08:00
|
|
|
private IRecorder? recorder;
|
2020-11-28 13:02:57 +08:00
|
|
|
|
2021-05-01 17:57:43 +08:00
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
2020-11-27 18:51:02 +08:00
|
|
|
|
2021-05-01 17:57:43 +08:00
|
|
|
public IRecorder? Recorder { get => this.recorder; internal set => this.SetField(ref this.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; }
|
2021-01-01 14:46:27 +08:00
|
|
|
field = value; this.OnPropertyChanged(propertyName); return true;
|
2020-11-27 18:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
{
|
2021-01-01 14:46:27 +08:00
|
|
|
if (!this.disposedValue)
|
2020-11-27 18:51:02 +08:00
|
|
|
{
|
|
|
|
if (disposing)
|
|
|
|
{
|
|
|
|
// dispose managed state (managed objects)
|
2021-01-01 14:46:27 +08:00
|
|
|
this.Recorder?.Dispose();
|
2020-11-27 18:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// free unmanaged resources (unmanaged objects) and override finalizer
|
|
|
|
// set large fields to null
|
2021-01-01 14:46:27 +08:00
|
|
|
this.disposedValue = true;
|
2020-11-27 18:51:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2021-01-01 14:46:27 +08:00
|
|
|
this.Dispose(disposing: true);
|
2020-11-27 18:51:02 +08:00
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|