Usings and namespace cleanup

This commit is contained in:
jetsparrow 2024-11-15 19:19:40 +03:00
parent d2e8ed4d69
commit 2cc286ad9c
29 changed files with 1415 additions and 1530 deletions

View File

@ -1,17 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Perfusion;
using JetKarmaBot.Services.Handling;
using NLog;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NLog;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models; using JetKarmaBot.Models;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
class AwardCommand : IChatCommand
{ {
class AwardCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => new[] { "award", "revoke" }; public IReadOnlyCollection<string> Names => new[] { "award", "revoke" };
[Inject] private Logger log; [Inject] private Logger log;
@ -158,5 +153,4 @@ namespace JetKarmaBot.Commands
DescriptionID="jetkarmabot.award.tohelp" DescriptionID="jetkarmabot.award.tohelp"
} }
}; };
}
} }

View File

@ -1,15 +1,11 @@
using System.Collections.Generic;
using Perfusion;
using JetKarmaBot.Services.Handling;
using NLog; using NLog;
using System.Linq; using JetKarmaBot.Services.Handling;
using System.Threading.Tasks;
using JetKarmaBot.Models; using JetKarmaBot.Models;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
class LocaleCommand : IChatCommand
{ {
class LocaleCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => new[] { "changelocale", "locale" }; public IReadOnlyCollection<string> Names => new[] { "changelocale", "locale" };
[Inject] private Logger log; [Inject] private Logger log;
@ -76,5 +72,4 @@ namespace JetKarmaBot.Commands
DescriptionID="jetkarmabot.changelocale.localehelp" DescriptionID="jetkarmabot.changelocale.localehelp"
} }
}; };
}
} }

View File

@ -1,11 +1,9 @@
using System; using System.Text.RegularExpressions;
using System.Linq;
using System.Text.RegularExpressions;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
public class CommandString
{ {
public class CommandString
{
public CommandString(string command, params string[] parameters) public CommandString(string command, params string[] parameters)
{ {
Command = command; Command = command;
@ -47,5 +45,4 @@ namespace JetKarmaBot.Commands
if (TryParse(s, out var c)) return c; if (TryParse(s, out var c)) return c;
throw new ArgumentException($"\"{s}\" is not a command"); throw new ArgumentException($"\"{s}\" is not a command");
} }
}
} }

View File

@ -1,15 +1,11 @@
using System.Collections.Generic; using Microsoft.EntityFrameworkCore;
using Perfusion;
using JetKarmaBot.Services.Handling; using JetKarmaBot.Services.Handling;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Models; using JetKarmaBot.Models;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
public class CurrenciesCommand : IChatCommand
{ {
public class CurrenciesCommand : IChatCommand
{
[Inject] Localization Locale { get; set; } [Inject] Localization Locale { get; set; }
public IReadOnlyCollection<string> Names => new[] { "currencies", "awardtypes" }; public IReadOnlyCollection<string> Names => new[] { "currencies", "awardtypes" };
@ -29,5 +25,4 @@ namespace JetKarmaBot.Commands
.Select(x => $"{x.Symbol} ({x.CommandName}) <i>{currentLocale["jetkarmabot.awardtypes.nominative." + x.CommandName]}</i>"))); .Select(x => $"{x.Symbol} ({x.CommandName}) <i>{currentLocale["jetkarmabot.awardtypes.nominative." + x.CommandName]}</i>")));
return true; return true;
} }
}
} }

View File

@ -1,14 +1,9 @@
using System.Collections.Generic; using JetKarmaBot.Services.Handling;
using Perfusion;
using JetKarmaBot.Services.Handling;
using Telegram.Bot.Types.Enums;
using System.Threading.Tasks;
using JetKarmaBot.Models;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
public class HelpCommand : IChatCommand
{ {
public class HelpCommand : IChatCommand
{
[Inject] Localization Locale { get; set; } [Inject] Localization Locale { get; set; }
public IReadOnlyCollection<string> Names => new[] { "help" }; public IReadOnlyCollection<string> Names => new[] { "help" };
@ -40,5 +35,4 @@ namespace JetKarmaBot.Commands
return true; return true;
} }
} }
}
} }

View File

@ -1,32 +1,29 @@
using System.Collections.Generic; using JetKarmaBot.Services.Handling;
using System.Threading.Tasks;
using JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
public interface IChatCommand
{ {
public interface IChatCommand
{
IReadOnlyCollection<string> Names { get; } IReadOnlyCollection<string> Names { get; }
string Description { get; } string Description { get; }
string DescriptionID { get; } string DescriptionID { get; }
IReadOnlyCollection<ChatCommandArgument> Arguments { get; } IReadOnlyCollection<ChatCommandArgument> Arguments { get; }
Task<bool> Execute(RequestContext ctx); Task<bool> Execute(RequestContext ctx);
} }
public struct ChatCommandArgument public struct ChatCommandArgument
{ {
public string Name; public string Name;
public bool Required; public bool Required;
public ChatCommandArgumentType Type; public ChatCommandArgumentType Type;
public string Description; public string Description;
public string DescriptionID; public string DescriptionID;
} }
public enum ChatCommandArgumentType public enum ChatCommandArgumentType
{ {
Boolean, Boolean,
String, String,
Integer, Integer,
}
} }

View File

@ -1,15 +1,11 @@
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Perfusion;
using JetKarmaBot.Services.Handling; using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models; using JetKarmaBot.Models;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
class LeaderboardCommand : IChatCommand
{ {
class LeaderboardCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => new[] { "leaderboard" }; public IReadOnlyCollection<string> Names => new[] { "leaderboard" };
public async Task<bool> Execute(RequestContext ctx) public async Task<bool> Execute(RequestContext ctx)
@ -66,5 +62,4 @@ namespace JetKarmaBot.Commands
DescriptionID= "jetkarmabot.leaderboard.awardtypehelp" DescriptionID= "jetkarmabot.leaderboard.awardtypehelp"
} }
}; };
}
} }

View File

@ -1,15 +1,11 @@
using System.Linq;
using System.Collections.Generic;
using Perfusion;
using JetKarmaBot.Services.Handling;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models; using JetKarmaBot.Models;
namespace JetKarmaBot.Commands namespace JetKarmaBot.Commands;
class StatusCommand : IChatCommand
{ {
class StatusCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => ["status"]; public IReadOnlyCollection<string> Names => ["status"];
public async Task<bool> Execute(RequestContext ctx) public async Task<bool> Execute(RequestContext ctx)
@ -52,5 +48,4 @@ namespace JetKarmaBot.Commands
public string DescriptionID => "jetkarmabot.status.help"; public string DescriptionID => "jetkarmabot.status.help";
public IReadOnlyCollection<ChatCommandArgument> Arguments => []; public IReadOnlyCollection<ChatCommandArgument> Arguments => [];
}
} }

View File

@ -2,12 +2,11 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using JsonNet.PrivateSettersContractResolvers; using JsonNet.PrivateSettersContractResolvers;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace JetKarmaBot namespace JetKarmaBot;
public class Config : ConfigBase
{ {
public class Config : ConfigBase
{
public Config(string path) : base(path) { } public Config(string path) : base(path) { }
public string ApiKey { get; private set; } public string ApiKey { get; private set; }
@ -36,10 +35,10 @@ namespace JetKarmaBot
} }
public TimeoutConfig Timeout { get; private set; } = new TimeoutConfig(); public TimeoutConfig Timeout { get; private set; } = new TimeoutConfig();
public bool SqlDebug { get; private set; } = false; public bool SqlDebug { get; private set; } = false;
} }
public abstract class ConfigBase public abstract class ConfigBase
{ {
public ConfigBase(string path) public ConfigBase(string path)
{ {
JObject configJson; JObject configJson;
@ -73,6 +72,5 @@ namespace JetKarmaBot
System.Diagnostics.Debug.WriteLine(e); System.Diagnostics.Debug.WriteLine(e);
} }
} }
}
} }

View File

@ -1,15 +1,12 @@
using System.Collections.Generic; namespace JetKarmaBot;
namespace JetKarmaBot public static class IReadOnlyDictionaryExtensions
{ {
public static class IReadOnlyDictionaryExtensions
{
public static TValue GetOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key) public static TValue GetOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key)
{ {
TValue res = default(TValue); TValue res = default;
if (key != null) if (key != null)
dict.TryGetValue(key, out res); dict.TryGetValue(key, out res);
return res; return res;
} }
}
} }

View File

@ -3,10 +3,10 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace JsonNet.PrivateSettersContractResolvers namespace JsonNet.PrivateSettersContractResolvers;
public class PrivateSetterContractResolver : DefaultContractResolver
{ {
public class PrivateSetterContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{ {
var jProperty = base.CreateProperty(member, memberSerialization); var jProperty = base.CreateProperty(member, memberSerialization);
@ -17,10 +17,10 @@ namespace JsonNet.PrivateSettersContractResolvers
return jProperty; return jProperty;
} }
} }
public class PrivateSetterCamelCasePropertyNamesContractResolver : CamelCasePropertyNamesContractResolver public class PrivateSetterCamelCasePropertyNamesContractResolver : CamelCasePropertyNamesContractResolver
{ {
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{ {
var jProperty = base.CreateProperty(member, memberSerialization); var jProperty = base.CreateProperty(member, memberSerialization);
@ -31,15 +31,14 @@ namespace JsonNet.PrivateSettersContractResolvers
return jProperty; return jProperty;
} }
} }
internal static class MemberInfoExtensions internal static class MemberInfoExtensions
{ {
internal static bool IsPropertyWithSetter(this MemberInfo member) internal static bool IsPropertyWithSetter(this MemberInfo member)
{ {
var property = member as PropertyInfo; var property = member as PropertyInfo;
return property?.GetSetMethod(true) != null; return property?.GetSetMethod(true) != null;
} }
}
} }

View File

@ -0,0 +1,6 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using Perfusion;

View File

@ -3,20 +3,16 @@ using JetKarmaBot.Models;
using JetKarmaBot.Services; using JetKarmaBot.Services;
using JetKarmaBot.Services.Handling; using JetKarmaBot.Services.Handling;
using NLog; using NLog;
using Perfusion;
using System;
using System.Threading;
using System.Threading.Tasks;
using Telegram.Bot; using Telegram.Bot;
using Telegram.Bot.Polling; using Telegram.Bot.Polling;
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
namespace JetKarmaBot namespace JetKarmaBot;
public class JetKarmaBot : IDisposable
{ {
public class JetKarmaBot : IDisposable
{
[Inject] Config Config { get; set; } [Inject] Config Config { get; set; }
[Inject] IContainer Container { get; set; } [Inject] IContainer Container { get; set; }
[Inject] KarmaContextFactory Db { get; set; } [Inject] KarmaContextFactory Db { get; set; }
@ -138,5 +134,4 @@ namespace JetKarmaBot
} }
#endregion #endregion
}
} }

View File

@ -1,11 +1,9 @@
using System; using System.ComponentModel.DataAnnotations.Schema;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace JetKarmaBot.Models namespace JetKarmaBot.Models;
public partial class Award
{ {
public partial class Award
{
public int AwardId { get; set; } public int AwardId { get; set; }
public long ChatId { get; set; } public long ChatId { get; set; }
public long FromId { get; set; } public long FromId { get; set; }
@ -21,5 +19,4 @@ namespace JetKarmaBot.Models
public virtual User From { get; set; } public virtual User From { get; set; }
[ForeignKey("ToId")] [ForeignKey("ToId")]
public virtual User To { get; set; } public virtual User To { get; set; }
}
} }

View File

@ -1,10 +1,7 @@
using System; namespace JetKarmaBot.Models;
using System.Collections.Generic;
namespace JetKarmaBot.Models public partial class AwardType
{ {
public partial class AwardType
{
public AwardType() public AwardType()
{ {
Awards = new HashSet<Award>(); Awards = new HashSet<Award>();
@ -17,5 +14,4 @@ namespace JetKarmaBot.Models
public string Description { get; set; } public string Description { get; set; }
public virtual ICollection<Award> Awards { get; set; } public virtual ICollection<Award> Awards { get; set; }
}
} }

View File

@ -1,10 +1,7 @@
using System; namespace JetKarmaBot.Models;
using System.Collections.Generic;
namespace JetKarmaBot.Models public partial class Chat
{ {
public partial class Chat
{
public Chat() public Chat()
{ {
Awards = new HashSet<Award>(); Awards = new HashSet<Award>();
@ -15,5 +12,4 @@ namespace JetKarmaBot.Models
public bool IsAdministrator { get; set; } public bool IsAdministrator { get; set; }
public virtual ICollection<Award> Awards { get; set; } public virtual ICollection<Award> Awards { get; set; }
}
} }

View File

@ -1,13 +1,10 @@
using System; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Perfusion;
namespace JetKarmaBot.Models namespace JetKarmaBot.Models;
[Transient]
public partial class KarmaContext : DbContext
{ {
[Transient]
public partial class KarmaContext : DbContext
{
public KarmaContext() public KarmaContext()
{ {
} }
@ -179,5 +176,4 @@ namespace JetKarmaBot.Models
.HasDefaultValueSql("CURRENT_TIMESTAMP"); .HasDefaultValueSql("CURRENT_TIMESTAMP");
}); });
} }
}
} }

View File

@ -1,11 +1,9 @@
using System; using System.ComponentModel.DataAnnotations.Schema;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace JetKarmaBot.Models namespace JetKarmaBot.Models;
public partial class User
{ {
public partial class User
{
public User() public User()
{ {
AwardsFrom = new HashSet<Award>(); AwardsFrom = new HashSet<Award>();
@ -19,5 +17,4 @@ namespace JetKarmaBot.Models
public virtual ICollection<Award> AwardsFrom { get; set; } public virtual ICollection<Award> AwardsFrom { get; set; }
[InverseProperty("To")] [InverseProperty("To")]
public virtual ICollection<Award> AwardsTo { get; set; } public virtual ICollection<Award> AwardsTo { get; set; }
}
} }

View File

@ -1,16 +1,11 @@
using System; using Microsoft.EntityFrameworkCore;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading;
using JetKarmaBot.Models;
using Microsoft.EntityFrameworkCore;
using NLog; using NLog;
using Perfusion; using JetKarmaBot.Models;
namespace JetKarmaBot namespace JetKarmaBot;
public static class Program
{ {
public static class Program
{
private static Logger log = LogManager.GetCurrentClassLogger(); private static Logger log = LogManager.GetCurrentClassLogger();
public enum ExitCode : int public enum ExitCode : int
{ {
@ -75,5 +70,4 @@ namespace JetKarmaBot
return (int)ExitCode.Ok; return (int)ExitCode.Ok;
} }
}
} }

View File

@ -1,16 +1,11 @@
using JetKarmaBot.Commands; using NLog;
using NLog;
using Perfusion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Telegram.Bot; using Telegram.Bot;
using JetKarmaBot.Commands;
namespace JetKarmaBot.Services.Handling namespace JetKarmaBot.Services.Handling;
public class ChatCommandRouter : IRequestHandler
{ {
public class ChatCommandRouter : IRequestHandler
{
public class Feature public class Feature
{ {
public Type CommandType; public Type CommandType;
@ -107,5 +102,4 @@ namespace JetKarmaBot.Services.Handling
} }
Dictionary<string, IChatCommand> commands = new Dictionary<string, IChatCommand>(); Dictionary<string, IChatCommand> commands = new Dictionary<string, IChatCommand>();
}
} }

View File

@ -1,12 +1,7 @@
using System; namespace JetKarmaBot.Services.Handling;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Perfusion;
namespace JetKarmaBot.Services.Handling public class DatabaseHandler : IRequestHandler
{ {
public class DatabaseHandler : IRequestHandler
{
[Inject] private KarmaContextFactory Db; [Inject] private KarmaContextFactory Db;
[Inject] private Localization Locale; [Inject] private Localization Locale;
public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next) public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next)
@ -19,5 +14,4 @@ namespace JetKarmaBot.Services.Handling
await db.SaveChangesAsync(); await db.SaveChangesAsync();
} }
} }
}
} }

View File

@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NLog; using NLog;
using Perfusion;
namespace JetKarmaBot.Services.Handling namespace JetKarmaBot.Services.Handling;
public interface IRequestHandler
{ {
public interface IRequestHandler
{
Task Handle(RequestContext ctx, Func<RequestContext, Task> next); Task Handle(RequestContext ctx, Func<RequestContext, Task> next);
} }
public class RequestChain : IRequestHandler public class RequestChain : IRequestHandler
{ {
[Inject] private Logger log; [Inject] private Logger log;
List<IRequestHandler> handlerStack = new List<IRequestHandler>(); List<IRequestHandler> handlerStack = new List<IRequestHandler>();
public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next = null) public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next = null)
@ -38,5 +34,4 @@ namespace JetKarmaBot.Services.Handling
log.ConditionalTrace($"Adding {handler.GetType().Name} to reqchain"); log.ConditionalTrace($"Adding {handler.GetType().Name} to reqchain");
handlerStack.Add(handler); handlerStack.Add(handler);
} }
}
} }

View File

@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetKarmaBot.Commands;
using JetKarmaBot.Models;
using Telegram.Bot; using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types; using Telegram.Bot.Types;
using JetKarmaBot.Commands;
namespace JetKarmaBot.Services.Handling namespace JetKarmaBot.Services.Handling;
public class RequestContext : IServiceProvider
{ {
public class RequestContext : IServiceProvider
{
public ITelegramBotClient Client { get; } public ITelegramBotClient Client { get; }
public Update EventArgs { get; } public Update EventArgs { get; }
public CommandString Command { get; } public CommandString Command { get; }
@ -35,5 +29,4 @@ namespace JetKarmaBot.Services.Handling
parseMode: Telegram.Bot.Types.Enums.ParseMode.Html, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html,
replyParameters: new ReplyParameters { MessageId = EventArgs.Message.MessageId } replyParameters: new ReplyParameters { MessageId = EventArgs.Message.MessageId }
); );
}
} }

View File

@ -1,12 +1,10 @@
using System;
using System.Threading.Tasks;
using JetKarmaBot.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Models;
namespace JetKarmaBot.Services.Handling namespace JetKarmaBot.Services.Handling;
public class SaveData : IRequestHandler
{ {
public class SaveData : IRequestHandler
{
public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next) public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next)
{ {
KarmaContext db = ctx.GetFeature<KarmaContext>(); KarmaContext db = ctx.GetFeature<KarmaContext>();
@ -32,5 +30,4 @@ namespace JetKarmaBot.Services.Handling
else else
(await db.Users.FindAsync(u.Id)).Username = un; (await db.Users.FindAsync(u.Id)).Username = un;
} }
}
} }

View File

@ -1,17 +1,11 @@
using Perfusion;
using System.Collections.Generic;
using System;
using System.Threading.Tasks;
using JetKarmaBot.Models;
using System.Threading;
using System.Linq;
using NLog; using NLog;
using JetKarmaBot.Models;
namespace JetKarmaBot.Services.Handling namespace JetKarmaBot.Services.Handling;
[Singleton]
public class TimeoutManager : IRequestHandler
{ {
[Singleton]
public class TimeoutManager : IRequestHandler
{
public class Feature public class Feature
{ {
public double Multiplier = 1; public double Multiplier = 1;
@ -129,5 +123,4 @@ namespace JetKarmaBot.Services.Handling
return (t.DeclaringType == null ? t.Namespace + "." + t.Name : getTypeName(t.DeclaringType) + "." + t.Name) return (t.DeclaringType == null ? t.Namespace + "." + t.Name : getTypeName(t.DeclaringType) + "." + t.Name)
+ (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : ""); + (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : "");
} }
}
} }

View File

@ -1,12 +1,10 @@
using JetKarmaBot.Models; using JetKarmaBot.Models;
using Perfusion;
namespace JetKarmaBot.Services namespace JetKarmaBot.Services;
public class KarmaContextFactory
{ {
public class KarmaContextFactory
{
[Inject] IContainer C { get; set; } [Inject] IContainer C { get; set; }
public KarmaContext GetContext() => C.GetInstance<KarmaContext>(); public KarmaContext GetContext() => C.GetInstance<KarmaContext>();
}
} }

View File

@ -1,17 +1,13 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLog; using NLog;
using Perfusion;
namespace JetKarmaBot namespace JetKarmaBot;
public class Localization : IReadOnlyDictionary<string, Locale>
{ {
public class Localization : IReadOnlyDictionary<string, Locale>
{
private Dictionary<string, Locale> locales = new Dictionary<string, Locale>(); private Dictionary<string, Locale> locales = new Dictionary<string, Locale>();
public Localization(IContainer c) public Localization(IContainer c)
@ -109,9 +105,9 @@ namespace JetKarmaBot
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
} }
public class Locale : IReadOnlyDictionary<string, string> public class Locale : IReadOnlyDictionary<string, string>
{ {
private Dictionary<string, string> locale; private Dictionary<string, string> locale;
private string localeName; private string localeName;
private string[] commonNames; private string[] commonNames;
@ -157,15 +153,14 @@ namespace JetKarmaBot
{ {
return ((IReadOnlyDictionary<string, string>)locale).GetEnumerator(); return ((IReadOnlyDictionary<string, string>)locale).GetEnumerator();
} }
} }
[System.Serializable] [System.Serializable]
public class LocalizationException : Exception public class LocalizationException : Exception
{ {
public LocalizationException() { } public LocalizationException() { }
public LocalizationException(string message) : base(message) { } public LocalizationException(string message) : base(message) { }
public LocalizationException(string message, Exception inner) : base(message, inner) { } public LocalizationException(string message, Exception inner) : base(message, inner) { }
protected LocalizationException( protected LocalizationException(
SerializationInfo info, SerializationInfo info,
StreamingContext context) : base(info, context) { } StreamingContext context) : base(info, context) { }
}
} }

View File

@ -1,12 +1,9 @@
using System;
using System.Linq;
using NLog; using NLog;
using Perfusion;
namespace JetKarmaBot namespace JetKarmaBot;
public class LogInfo : ObjectInfo
{ {
public class LogInfo : ObjectInfo
{
public override ObjectInfo Clone() => new LogInfo(); public override ObjectInfo Clone() => new LogInfo();
public override object GetInstance(IContainer c, Type requester = null) public override object GetInstance(IContainer c, Type requester = null)
@ -18,5 +15,4 @@ namespace JetKarmaBot
return (t.DeclaringType == null ? t.Namespace + "." + t.Name : getTypeName(t.DeclaringType) + "." + t.Name) return (t.DeclaringType == null ? t.Namespace + "." + t.Name : getTypeName(t.DeclaringType) + "." + t.Name)
+ (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : ""); + (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : "");
} }
}
} }

View File

@ -1,12 +1,10 @@
using System;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog; using NLog;
using Perfusion;
namespace JetKarmaBot namespace JetKarmaBot;
public class NLoggerFactory : ILoggerFactory
{ {
public class NLoggerFactory : ILoggerFactory
{
[Inject] [Inject]
private NLoggerProvider c; private NLoggerProvider c;
public void AddProvider(ILoggerProvider provider) public void AddProvider(ILoggerProvider provider)
@ -18,9 +16,9 @@ namespace JetKarmaBot
public void Dispose() public void Dispose()
{ {
} }
} }
public class NLoggerProvider : ILoggerProvider public class NLoggerProvider : ILoggerProvider
{ {
[Inject] [Inject]
private Container c; private Container c;
@ -29,10 +27,10 @@ namespace JetKarmaBot
public void Dispose() public void Dispose()
{ {
} }
} }
public class LoggerVirtualizer : Microsoft.Extensions.Logging.ILogger public class LoggerVirtualizer : Microsoft.Extensions.Logging.ILogger
{ {
private Logger logger; private Logger logger;
public LoggerVirtualizer(Logger logger) public LoggerVirtualizer(Logger logger)
@ -93,11 +91,10 @@ namespace JetKarmaBot
if (exception != null) logger.Log(getAppropriate(logLevel), exception, formatter(state, exception)); if (exception != null) logger.Log(getAppropriate(logLevel), exception, formatter(state, exception));
else logger.Log(getAppropriate(logLevel), state); else logger.Log(getAppropriate(logLevel), state);
} }
} }
public class SomeDisposable : IDisposable public class SomeDisposable : IDisposable
{ {
public void Dispose() public void Dispose()
{ {
} }
}
} }