实现提供了完整的弹幕功能,包括多行显示、不同颜色、头像支持、防重叠、椭圆形边框、透明度渐变、点击事件、字体样式设置、暂停/继续功能、过滤功能等。还包含了批处理队列处理逻辑、速率限制、错误处理和性能监控等功能。
This commit is contained in:
32
YwxAppWpfDanMu/Services/DanMuDispatcher.cs
Normal file
32
YwxAppWpfDanMu/Services/DanMuDispatcher.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace YwxAppWpfDanMu.Services
|
||||
{
|
||||
public class DanMuDispatcher
|
||||
{
|
||||
private readonly Dispatcher _dispatcher;
|
||||
|
||||
public DanMuDispatcher(Dispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
|
||||
}
|
||||
|
||||
public void Invoke(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
if (_dispatcher.CheckAccess())
|
||||
{
|
||||
action();
|
||||
}
|
||||
else
|
||||
{
|
||||
_dispatcher.Invoke(action, priority);
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginInvoke(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
_dispatcher.BeginInvoke(action, priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
75
YwxAppWpfDanMu/Services/DanMuPerformanceMonitor.cs
Normal file
75
YwxAppWpfDanMu/Services/DanMuPerformanceMonitor.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace YwxAppWpfDanMu.Services
|
||||
{
|
||||
public class DanMuPerformanceMonitor
|
||||
{
|
||||
private readonly Stopwatch _stopwatch = new Stopwatch();
|
||||
private readonly List<Exception> _errors = new List<Exception>();
|
||||
|
||||
private int _totalDanMuAdded;
|
||||
private int _totalDanMuFiltered;
|
||||
private int _totalDanMuRemoved;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_stopwatch.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_stopwatch.Stop();
|
||||
}
|
||||
|
||||
public void RecordAddedDanMu()
|
||||
{
|
||||
_totalDanMuAdded++;
|
||||
}
|
||||
|
||||
public void RecordFilteredDanMu()
|
||||
{
|
||||
_totalDanMuFiltered++;
|
||||
}
|
||||
|
||||
public void RecordRemovedDanMu()
|
||||
{
|
||||
_totalDanMuRemoved++;
|
||||
}
|
||||
|
||||
public void RecordClear()
|
||||
{
|
||||
_totalDanMuRemoved += _totalDanMuAdded - _totalDanMuRemoved;
|
||||
}
|
||||
|
||||
public void RecordError(Exception ex)
|
||||
{
|
||||
_errors.Add(ex);
|
||||
}
|
||||
|
||||
public PerformanceStats GetStats()
|
||||
{
|
||||
return new PerformanceStats
|
||||
{
|
||||
TotalTime = _stopwatch.Elapsed,
|
||||
TotalDanMuAdded = _totalDanMuAdded,
|
||||
TotalDanMuFiltered = _totalDanMuFiltered,
|
||||
TotalDanMuRemoved = _totalDanMuRemoved,
|
||||
Errors = _errors.ToArray(),
|
||||
DanMuPerSecond = _stopwatch.Elapsed.TotalSeconds > 0 ?
|
||||
_totalDanMuAdded / _stopwatch.Elapsed.TotalSeconds : 0
|
||||
};
|
||||
}
|
||||
|
||||
public class PerformanceStats
|
||||
{
|
||||
public TimeSpan TotalTime { get; set; }
|
||||
public int TotalDanMuAdded { get; set; }
|
||||
public int TotalDanMuFiltered { get; set; }
|
||||
public int TotalDanMuRemoved { get; set; }
|
||||
public Exception[] Errors { get; set; }
|
||||
public double DanMuPerSecond { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
13
YwxAppWpfDanMu/Services/IDanMuService.cs
Normal file
13
YwxAppWpfDanMu/Services/IDanMuService.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using YwxAppWpfDanMu.Models;
|
||||
|
||||
namespace YwxAppWpfDanMu.Services
|
||||
{
|
||||
public interface IDanMuService
|
||||
{
|
||||
void AddDanMu(DanMuMessage message);
|
||||
void AddDanMuBatch(IEnumerable<DanMuMessage> messages);
|
||||
void ClearAll();
|
||||
void Pause();
|
||||
void Resume();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user