BililiveRecorder/BililiveRecorder.WPF/Models/PollyPolicyModel.cs
Genteure 5ba347cf46 多处修改
polly
弹幕xml
托盘图标
2021-03-01 21:38:13 +08:00

47 lines
1.5 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using BililiveRecorder.Core;
using BililiveRecorder.WPF.Pages;
#nullable enable
namespace BililiveRecorder.WPF.Models
{
public class PollyPolicyModel : INotifyPropertyChanged
{
private readonly PollyPolicy? policy;
public PollyPolicyModel() : this((PollyPolicy?)(RootPage.ServiceProvider?.GetService(typeof(PollyPolicy))))
{
}
public PollyPolicyModel(PollyPolicy? policy)
{
this.policy = policy;
this.ResetAllPolicy = new Commands
{
ExecuteDelegate = _ =>
{
if (this.policy != null)
{
this.policy.IpBlockedHttp412CircuitBreakerPolicy.Reset();
this.policy.RequestFailedCircuitBreakerPolicy.Reset();
}
}
};
}
public ICommand ResetAllPolicy { get; }
public event PropertyChangedEventHandler? PropertyChanged;
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; this.OnPropertyChanged(propertyName); return true;
}
}
}