Applied codestyle to all .cs files

This commit is contained in:
Kwoth
2021-12-29 06:07:16 +01:00
parent 723447c7d4
commit 82000c97a4
543 changed files with 13221 additions and 14059 deletions

View File

@@ -33,15 +33,10 @@ public class EventPubSub : IPubSub
lock (_locker)
{
if (_actions.TryGetValue(key.Key, out var actions))
{
// if this class ever gets used, this needs to be properly implemented
// 1. ignore all valuetasks which are completed
// 2. run all other tasks in parallel
return actions
.SelectMany(kvp => kvp.Value)
.Select(action => action(data).AsTask())
.WhenAll();
}
return actions.SelectMany(kvp => kvp.Value).Select(action => action(data).AsTask()).WhenAll();
return Task.CompletedTask;
}
@@ -53,7 +48,6 @@ public class EventPubSub : IPubSub
{
// get subscriptions for this action
if (_actions.TryGetValue(key.Key, out var actions))
{
// get subscriptions which have the same action hash code
// note: having this as a list allows for multiple subscriptions of
// the same insance's/static method
@@ -71,15 +65,11 @@ public class EventPubSub : IPubSub
// if our dictionary has no more elements after
// removing the entry
// it's safe to remove it from the key's subscriptions
if (actions.Count == 0)
{
_actions.Remove(key.Key);
}
if (actions.Count == 0) _actions.Remove(key.Key);
}
}
}
return Task.CompletedTask;
}
}
}
}

View File

@@ -4,4 +4,4 @@ public interface IPubSub
{
public Task Pub<TData>(in TypedKey<TData> key, TData data);
public Task Sub<TData>(in TypedKey<TData> key, Func<TData?, ValueTask> action);
}
}

View File

@@ -4,4 +4,4 @@ public interface ISeria
{
byte[] Serialize<T>(T data);
T? Deserialize<T>(byte[]? data);
}
}

View File

@@ -1,5 +1,5 @@
using System.Text.Json;
using NadekoBot.Common.JsonConverters;
using System.Text.Json;
namespace NadekoBot.Common;
@@ -7,7 +7,7 @@ public class JsonSeria : ISeria
{
private readonly JsonSerializerOptions _serializerOptions = new()
{
Converters = { new Rgba32Converter(), new CultureInfoConverter(), }
Converters = { new Rgba32Converter(), new CultureInfoConverter() }
};
public byte[] Serialize<T>(T data)
@@ -20,4 +20,4 @@ public class JsonSeria : ISeria
return JsonSerializer.Deserialize<T>(data, _serializerOptions);
}
}
}

View File

@@ -4,9 +4,9 @@ namespace NadekoBot.Common;
public sealed class RedisPubSub : IPubSub
{
private readonly IBotCredentials _creds;
private readonly ConnectionMultiplexer _multi;
private readonly ISeria _serializer;
private readonly IBotCredentials _creds;
public RedisPubSub(ConnectionMultiplexer multi, ISeria serializer, IBotCredentials creds)
{
@@ -19,7 +19,7 @@ public sealed class RedisPubSub : IPubSub
{
var serialized = _serializer.Serialize(data);
return _multi.GetSubscriber()
.PublishAsync($"{_creds.RedisKey()}:{key.Key}", serialized, CommandFlags.FireAndForget);
.PublishAsync($"{_creds.RedisKey()}:{key.Key}", serialized, CommandFlags.FireAndForget);
}
public Task Sub<TData>(in TypedKey<TData> key, Func<TData?, ValueTask> action)
@@ -41,4 +41,4 @@ public sealed class RedisPubSub : IPubSub
return _multi.GetSubscriber().SubscribeAsync($"{_creds.RedisKey()}:{eventName}", OnSubscribeHandler);
}
}
}

View File

@@ -27,4 +27,4 @@ public readonly struct TypedKey<TData>
public override string ToString()
=> Key;
}
}

View File

@@ -1,19 +1,18 @@
using System.Text.RegularExpressions;
using NadekoBot.Common.Yml;
using NadekoBot.Common.Configs;
using NadekoBot.Common.Yml;
using System.Text.RegularExpressions;
using YamlDotNet.Serialization;
namespace NadekoBot.Common;
public class YamlSeria : IConfigSeria
{
private readonly ISerializer _serializer;
private readonly IDeserializer _deserializer;
private static readonly Regex _codePointRegex =
new(@"(\\U(?<code>[a-zA-Z0-9]{8})|\\u(?<code>[a-zA-Z0-9]{4})|\\x(?<code>[a-zA-Z0-9]{2}))",
RegexOptions.Compiled
);
RegexOptions.Compiled);
private readonly IDeserializer _deserializer;
private readonly ISerializer _serializer;
public YamlSeria()
{
@@ -22,7 +21,7 @@ public class YamlSeria : IConfigSeria
}
public string Serialize<T>(T obj)
where T: notnull
where T : notnull
{
var escapedOutput = _serializer.Serialize(obj);
var output = _codePointRegex.Replace(escapedOutput,
@@ -31,11 +30,10 @@ public class YamlSeria : IConfigSeria
var str = me.Groups["code"].Value;
var newString = YamlHelper.UnescapeUnicodeCodePoint(str);
return newString;
}
);
});
return output;
}
public T Deserialize<T>(string data)
=> _deserializer.Deserialize<T>(data);
}
}