Mare 0.9 (#65)
* add jwt expiry * start of 0.9 api impl * some stuff idk * some more impl * some cleanup * remove grouppair, add configuration, rework some pair drawing stuff * do some stuff * rework some ui * I don't even know anymore * add cancellationtoken * token bla * ui fixes etc * probably individual adding/removing now working fully as expected * add working report popup * I guess it's more syncshell shit or so * popup shit idk * work out most of the syncshell bullshit I guess * delete some old crap * are we actually getting closer to the end * update pair info stuff * more fixes/adjustments, idk * refactor some things * some rework * some more cleanup * cleanup * make menu buttons w i d e * better icon text buttons * add all syncshell folder and ordering fixes --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
@@ -8,12 +8,12 @@ namespace MareSynchronos.Services.Mediator;
|
||||
public sealed class MareMediator : IHostedService
|
||||
{
|
||||
private readonly object _addRemoveLock = new();
|
||||
private readonly Dictionary<object, DateTime> _lastErrorTime = new();
|
||||
private readonly Dictionary<object, DateTime> _lastErrorTime = [];
|
||||
private readonly ILogger<MareMediator> _logger;
|
||||
private readonly CancellationTokenSource _loopCts = new();
|
||||
private readonly ConcurrentQueue<MessageBase> _messageQueue = new();
|
||||
private readonly PerformanceCollectorService _performanceCollector;
|
||||
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = new();
|
||||
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = [];
|
||||
|
||||
public MareMediator(ILogger<MareMediator> logger, PerformanceCollectorService performanceCollector)
|
||||
{
|
||||
@@ -23,13 +23,13 @@ public sealed class MareMediator : IHostedService
|
||||
|
||||
public void PrintSubscriberInfo()
|
||||
{
|
||||
foreach (var kvp in _subscriberDict.SelectMany(c => c.Value.Select(v => v))
|
||||
.DistinctBy(p => p.Subscriber).OrderBy(p => p.Subscriber.GetType().FullName, StringComparer.Ordinal).ToList())
|
||||
foreach (var subscriber in _subscriberDict.SelectMany(c => c.Value.Select(v => v.Subscriber))
|
||||
.DistinctBy(p => p).OrderBy(p => p.GetType().FullName, StringComparer.Ordinal).ToList())
|
||||
{
|
||||
_logger.LogInformation("Subscriber {type}: {sub}", kvp.Subscriber.GetType().Name, kvp.Subscriber.ToString());
|
||||
_logger.LogInformation("Subscriber {type}: {sub}", subscriber.GetType().Name, subscriber.ToString());
|
||||
StringBuilder sb = new();
|
||||
sb.Append("=> ");
|
||||
foreach (var item in _subscriberDict.Where(item => item.Value.Any(v => v.Subscriber == kvp.Subscriber)).ToList())
|
||||
foreach (var item in _subscriberDict.Where(item => item.Value.Any(v => v.Subscriber == subscriber)).ToList())
|
||||
{
|
||||
sb.Append(item.Key.Name).Append(", ");
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public sealed class MareMediator : IHostedService
|
||||
{
|
||||
await Task.Delay(100, _loopCts.Token).ConfigureAwait(false);
|
||||
|
||||
HashSet<MessageBase> processedMessages = new();
|
||||
HashSet<MessageBase> processedMessages = [];
|
||||
while (_messageQueue.TryDequeue(out var message))
|
||||
{
|
||||
if (processedMessages.Contains(message)) { continue; }
|
||||
@@ -89,7 +89,7 @@ public sealed class MareMediator : IHostedService
|
||||
{
|
||||
lock (_addRemoveLock)
|
||||
{
|
||||
_subscriberDict.TryAdd(typeof(T), new HashSet<SubscriberAction>());
|
||||
_subscriberDict.TryAdd(typeof(T), []);
|
||||
|
||||
if (!_subscriberDict[typeof(T)].Add(new(subscriber, action)))
|
||||
{
|
||||
@@ -130,20 +130,22 @@ public sealed class MareMediator : IHostedService
|
||||
{
|
||||
if (!_subscriberDict.TryGetValue(message.GetType(), out HashSet<SubscriberAction>? subscribers) || subscribers == null || !subscribers.Any()) return;
|
||||
|
||||
HashSet<SubscriberAction> subscribersCopy = new HashSet<SubscriberAction>();
|
||||
HashSet<SubscriberAction> subscribersCopy = [];
|
||||
lock (_addRemoveLock)
|
||||
{
|
||||
subscribersCopy = subscribers?.Where(s => s.Subscriber != null).ToHashSet() ?? new HashSet<SubscriberAction>();
|
||||
subscribersCopy = subscribers?.Where(s => s.Subscriber != null).ToHashSet() ?? [];
|
||||
}
|
||||
|
||||
foreach (SubscriberAction subscriber in subscribersCopy)
|
||||
{
|
||||
try
|
||||
{
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
typeof(MareMediator)
|
||||
.GetMethod(nameof(ExecuteSubscriber), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?
|
||||
.MakeGenericMethod(message.GetType())
|
||||
.Invoke(this, new object[] { subscriber, message });
|
||||
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user