huge commit for advanced stats feature.

broke data out into its own library.
may be breaking changes with existing plugins
This commit is contained in:
RaidMax 2021-03-22 11:09:25 -05:00
parent db2e1deb2f
commit c5375b661b
505 changed files with 13671 additions and 3271 deletions

View File

@ -56,7 +56,7 @@
<ItemGroup>
<None Update="DefaultSettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Configuration\LoggingConfiguration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -6,7 +6,6 @@ using SharedLibraryCore;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Configuration.Validation;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Helpers;
@ -21,6 +20,8 @@ using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Context;
using IW4MAdmin.Application.Migration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -291,6 +292,15 @@ namespace IW4MAdmin.Application
IsRunning = true;
ExternalIPAddress = await Utilities.GetExternalIP();
#region DATABASE
_logger.LogInformation("Beginning database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_START"]);
await ContextSeed.Seed(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
await DatabaseHousekeeping.RemoveOldRatings(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
_logger.LogInformation("Finished database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_END"]);
#endregion
#region PLUGINS
foreach (var plugin in Plugins)
{
@ -331,7 +341,7 @@ namespace IW4MAdmin.Application
// copy over default config if it doesn't exist
if (!_appConfig.Servers?.Any() ?? true)
{
var defaultConfig = new BaseConfigurationHandler<DefaultConfiguration>("DefaultSettings").Configuration();
var defaultConfig = new BaseConfigurationHandler<DefaultSettings>("DefaultSettings").Configuration();
//ConfigHandler.Set((ApplicationConfiguration)new ApplicationConfiguration().Generate());
//var newConfig = ConfigHandler.Configuration();
@ -424,15 +434,6 @@ namespace IW4MAdmin.Application
#endregion
#region DATABASE
_logger.LogInformation("Beginning database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_START"]);
await ContextSeed.Seed(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
await DatabaseHousekeeping.RemoveOldRatings(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
_logger.LogInformation("Finished database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_END"]);
#endregion
#region COMMANDS
if (await ClientSvc.HasOwnerAsync(_tokenSource.Token))
{
@ -517,7 +518,7 @@ namespace IW4MAdmin.Application
// add the start event for this server
var e = new GameEvent()
{
Type = GameEvent.EventType.Start,
Type = EventType.Start,
Data = $"{ServerInstance.GameName} started",
Owner = ServerInstance
};

View File

@ -16,7 +16,13 @@
"Keep grenade launcher use to a minimum",
"Balance teams at ALL times"
],
"DisallowedClientNames": [ "Unknown Soldier", "VickNet", "UnknownSoldier", "CHEATER", "Play77" ],
"DisallowedClientNames": [
"Unknown Soldier",
"VickNet",
"UnknownSoldier",
"CHEATER",
"Play77"
],
"QuickMessages": [
{
"Game": "IW4",
@ -248,222 +254,178 @@
"Alias": "Rust",
"Name": "mp_rust"
},
{
"Alias": "Terminal",
"Name": "mp_terminal"
},
{
"Alias": "Crash",
"Name": "mp_crash"
},
{
"Alias": "Afghan",
"Name": "mp_afghan"
},
{
"Alias": "Derail",
"Name": "mp_derail"
},
{
"Alias": "Estate",
"Name": "mp_estate"
},
{
"Alias": "Favela",
"Name": "mp_favela"
},
{
"Alias": "Highrise",
"Name": "mp_highrise"
},
{
"Alias": "Invasion",
"Name": "mp_invasion"
},
{
"Alias": "Karachi",
"Name": "mp_checkpoint"
},
{
"Alias": "Quarry",
"Name": "mp_quarry"
},
{
"Alias": "Rundown",
"Name": "mp_rundown"
},
{
"Alias": "Scrapyard",
"Name": "mp_boneyard"
},
{
"Alias": "Skidrow",
"Name": "mp_nightshift"
},
{
"Alias": "Sub Base",
"Name": "mp_subbase"
},
{
"Alias": "Underpass",
"Name": "mp_underpass"
},
{
"Alias": "Wasteland",
"Name": "mp_brecourt"
},
{
"Alias": "Overgrown",
"Name": "mp_overgrown"
},
{
"Alias": "Strike",
"Name": "mp_strike"
},
{
"Alias": "Vacant",
"Name": "mp_vacant"
},
{
"Alias": "Carnival",
"Name": "mp_abandon"
},
{
"Alias": "Trailer Park",
"Name": "mp_trailerpark"
},
{
"Alias": "Fuel",
"Name": "mp_fuel2"
},
{
"Alias": "Storm",
"Name": "mp_storm"
},
{
"Alias": "Bailout",
"Name": "mp_complex"
},
{
"Alias": "Salvage",
"Name": "mp_compact"
},
{
"Alias": "Nuketown",
"Name": "mp_nuked"
},
{
"Alias": "Test map",
"Name": "iw4_credits"
},
{
"Alias": "Killhouse",
"Name": "mp_killhouse"
},
{
"Alias": "Bog",
"Name": "mp_bog_sh"
},
{
"Alias": "Freighter",
"Name": "mp_cargoship_sh"
},
{
"Alias": "Cargoship",
"Name": "mp_cargoship"
},
{
"Alias": "Shipment",
"Name": "mp_shipment"
},
{
"Alias": "Shipment - Long",
"Name": "mp_shipment_long"
},
{
"Alias": "Rust - Long",
"Name": "mp_rust_long"
},
{
"Alias": "Firing Range",
"Name": "mp_firingrange"
},
{
"Alias": "Chemical Plant",
"Name": "mp_storm_spring"
},
{
"Alias": "Tropical Favela",
"Name": "mp_fav_tropical"
},
{
"Alias": "Tropical Estate",
"Name": "mp_estate_tropical"
},
{
"Alias": "Tropical Crash",
"Name": "mp_crash_tropical"
},
{
"Alias": "Forgotten City",
"Name": "mp_bloc_sh"
},
{
"Alias": "Crossfire",
"Name": "mp_cross_fire"
},
{
"Alias": "Bloc",
"Name": "mp_bloc"
},
{
"Alias": "Oilrig",
"Name": "oilrig"
},
{
"Name": "Village",
"Alias": "co_hunted"
@ -519,7 +481,7 @@
},
{
"Alias": "Havana",
"Name": "mp_cairo"
"Name": "mp_cairo"
},
{
"Alias": "Hazard",
@ -885,5 +847,79 @@
}
]
}
]
],
"GameStrings": {
"IW4": {
"torso_upper": "Upper Torso",
"torso_lower": "Lower Torso",
"right_leg_upper": "Upper Right Leg",
"right_leg_lower": "Lower Right Leg",
"right_hand": "Right Hand",
"right_foot": "Right Foot",
"right_arm_upper": "Upper Right Arm",
"right_arm_lower": "Lower Right Arm",
"left_leg_upper": "Upper Left Leg",
"left_leg_lower": "Lower Left Leg",
"left_hand": "Left Hand",
"left_foot": "Left Foot",
"left_arm_upper": "Upper Left Arm",
"left_arm_lower": "Lower Left Arm",
"acog": "ACOG Sight",
"eotech": "Holographic Sight",
"fmj": "FMJ",
"gl": "Grenade Launcher",
"heartbeat": "Heartbeat Sensor",
"reflex": "Red Dot Sight",
"rof": "Rapid Fire",
"thermal": "Thermal",
"xmags": "Extended Mags",
"m4": "M4A1",
"m40a3": "M40A3",
"ak47": "AK-47",
"ak47classic": "AK-47 Classic",
"fn2000": "F2000",
"masada": "ACR",
"famas": "FAMAS",
"fal": "FAL",
"scar": "SCAR-H",
"tavor": "TAR-21",
"m16": "M16A4",
"mp5k": "MP5K",
"ump45": "UMP45",
"kriss": "Vector",
"uzi": "Mini-Uzi",
"rpd": "RPD",
"sa80": "L86 LSW",
"mg4": "MG4",
"aug": "AUG HBAR",
"cheytac": "Intervention",
"barrett": "Barrett .50cal",
"wa2000": "WA2000",
"m21": "M21 EBR",
"pp2000": "PP2000",
"glock": "G18",
"beretta": "M93 Raffica",
"tmp": "TMP",
"spas12": "SPAS-12",
"aa12": "AA-12",
"model1887": "Model 1887",
"usp": "USP .45",
"coltanaconda": ".44 Magnum",
"deserteagle": "Desert Eagle",
"deserteaglegold": "Desert Eagle Gold",
"at4": "AT4-HS",
"m79": "Thumper",
"rpg": "RPG-7",
"concussion": "Stun",
"throwingknife": "Throwing Knife",
"ffar": "Airstrike",
"pavelow": "Pave Low",
"cobra": "Attack Helicopter",
"ac130": "AC-130",
"remotemissile": "Predator Missile",
"artillery": "Precision Airstrike",
"player": "",
"attach": ""
}
}
}

View File

@ -5,6 +5,7 @@ using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using Data.Models;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;
@ -310,7 +311,7 @@ namespace IW4MAdmin.Application.EventParsers
}
}
if (eventType.Contains("ExitLevel"))
if (eventType.Contains("ExitLevel") || eventType.Contains("ShutdownGame"))
{
return new GameEvent()
{

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Data.MigrationContext;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@ -10,7 +11,6 @@ using Serilog;
using Serilog.Events;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.MigrationContext;
using ILogger = Serilog.ILogger;
namespace IW4MAdmin.Application.Extensions
@ -32,13 +32,12 @@ namespace IW4MAdmin.Application.Extensions
.ReadFrom.Configuration(configuration)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning);
if (Utilities.IsDevelopment)
{
loggerConfig = loggerConfig.WriteTo.Console(
outputTemplate:
"[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Server} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Debug();
}
@ -67,10 +66,10 @@ namespace IW4MAdmin.Application.Extensions
{DataSource = Path.Join(currentPath, "Database", "Database.db")};
var connectionString = connectionStringBuilder.ToString();
var builder = new DbContextOptionsBuilder<SqliteDatabaseContext>()
.UseSqlite(connectionString);
services.AddSingleton((DbContextOptions) builder.Options);
services.AddSingleton(sp => (DbContextOptions) new DbContextOptionsBuilder<SqliteDatabaseContext>()
.UseSqlite(connectionString)
.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>())
.EnableSensitiveDataLogging().Options);
return services;
}
@ -90,7 +89,11 @@ namespace IW4MAdmin.Application.Extensions
services.AddSingleton(sp =>
(DbContextOptions) new DbContextOptionsBuilder<PostgresqlDatabaseContext>()
.UseNpgsql(appConfig.ConnectionString + (appendTimeout ? ";Command Timeout=0" : ""),
postgresqlOptions => postgresqlOptions.EnableRetryOnFailure())
postgresqlOptions =>
{
postgresqlOptions.EnableRetryOnFailure();
postgresqlOptions.SetPostgresVersion(new Version("9.4"));
})
.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>()).Options);
return services;
default:

View File

@ -1,9 +1,9 @@
using System;
using Data.Abstractions;
using Data.Context;
using Data.MigrationContext;
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.MigrationContext;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Factories
{

View File

@ -1,4 +1,6 @@
using System;
using Data.Abstractions;
using Data.Models.Server;
using Microsoft.Extensions.DependencyInjection;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
@ -37,7 +39,7 @@ namespace IW4MAdmin.Application.Factories
/// <returns></returns>
public Server CreateServer(ServerConfiguration config, IManager manager)
{
return new IW4MServer(config, _translationLookup, _metaService, _serviceProvider, _serviceProvider.GetRequiredService<IClientNoticeMessageFormatter>());
return new IW4MServer(config, _translationLookup, _metaService, _serviceProvider, _serviceProvider.GetRequiredService<IClientNoticeMessageFormatter>(), _serviceProvider.GetRequiredService<ILookupCache<EFServer>>());
}
}
}

View File

@ -6,9 +6,9 @@ using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using Data.Models.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Database.Models.EFClient;
namespace IW4MAdmin.Application.Factories
{
@ -32,7 +32,7 @@ namespace IW4MAdmin.Application.Factories
public IManagerCommand CreateScriptCommand(string name, string alias, string description, string permission,
bool isTargetRequired, IEnumerable<(string, bool)> args, Action<GameEvent> executeAction)
{
var permissionEnum = Enum.Parse<Permission>(permission);
var permissionEnum = Enum.Parse<EFClient.Permission>(permission);
var argsArray = args.Select(_arg => new CommandArgument
{
Name = _arg.Item1,

View File

@ -15,10 +15,14 @@ using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using static SharedLibraryCore.Database.Models.EFClient;
using Data.Models;
using Data.Models.Server;
using static Data.Models.Client.EFClient;
namespace IW4MAdmin
{
@ -34,13 +38,15 @@ namespace IW4MAdmin
public int Id { get; private set; }
private readonly IServiceProvider _serviceProvider;
private readonly IClientNoticeMessageFormatter _messageFormatter;
private readonly ILookupCache<EFServer> _serverCache;
public IW4MServer(
ServerConfiguration serverConfiguration,
ITranslationLookup lookup,
IMetaService metaService,
IServiceProvider serviceProvider,
IClientNoticeMessageFormatter messageFormatter) : base(serviceProvider.GetRequiredService<ILogger<Server>>(),
IClientNoticeMessageFormatter messageFormatter,
ILookupCache<EFServer> serverCache) : base(serviceProvider.GetRequiredService<ILogger<Server>>(),
serviceProvider.GetRequiredService<SharedLibraryCore.Interfaces.ILogger>(),
serverConfiguration,
serviceProvider.GetRequiredService<IManager>(),
@ -51,6 +57,7 @@ namespace IW4MAdmin
_metaService = metaService;
_serviceProvider = serviceProvider;
_messageFormatter = messageFormatter;
_serverCache = serverCache;
}
public override async Task<EFClient> OnClientConnected(EFClient clientFromLog)
@ -250,6 +257,28 @@ namespace IW4MAdmin
{
ServerLogger.LogDebug("processing event of type {type}", E.Type);
if (E.Type == GameEvent.EventType.Start)
{
var existingServer = (await _serverCache
.FirstAsync(server => server.Id == EndPoint));
var serverId = await GetIdForServer(E.Owner);
if (existingServer == null)
{
var server = new EFServer()
{
Port = Port,
EndPoint = ToString(),
ServerId = serverId,
GameName = (Reference.Game?)GameName,
HostName = Hostname
};
await _serverCache.AddAsync(server);
}
}
if (E.Type == GameEvent.EventType.ConnectionLost)
{
var exception = E.Extra as Exception;
@ -734,6 +763,25 @@ namespace IW4MAdmin
updatedClients.ToList()
};
}
private async Task<long> GetIdForServer(Server server)
{
if ($"{server.IP}:{server.Port.ToString()}" == "66.150.121.184:28965")
{
return 886229536;
}
// todo: this is not stable and will need to be migrated again...
long id = HashCode.Combine(server.IP, server.Port);
id = id < 0 ? Math.Abs(id) : id;
var serverId = (await _serverCache
.FirstAsync(_server => _server.ServerId == server.EndPoint ||
_server.EndPoint == server.ToString() ||
_server.ServerId == id))?.ServerId;
return !serverId.HasValue ? id : serverId.Value;
}
private void UpdateMap(string mapname)
{
@ -1113,6 +1161,7 @@ namespace IW4MAdmin
this,
GenerateUriForLog(LogPath, ServerConfig.GameLogServerUrl?.AbsoluteUri), gameLogReaderFactory);
await _serverCache.InitializeAsync();
_ = Task.Run(() => LogEvent.PollForChanges());
if (!Utilities.IsDevelopment)

View File

@ -23,10 +23,18 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Helpers;
using IW4MAdmin.Application.Extensions;
using IW4MAdmin.Application.Localization;
using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using IW4MAdmin.Plugins.Stats.Client.Abstractions;
using IW4MAdmin.Plugins.Stats.Client;
using IW4MAdmin.Plugins.Stats.Client.Game;
using Stats.Client.Abstractions;
using Stats.Client;
using Stats.Helpers;
namespace IW4MAdmin.Application
{
@ -80,13 +88,13 @@ namespace IW4MAdmin.Application
/// <returns></returns>
private static async Task LaunchAsync(string[] args)
{
restart:
restart:
ITranslationLookup translationLookup = null;
var logger = BuildDefaultLogger<Program>(new ApplicationConfiguration());
Utilities.DefaultLogger = logger;
IServiceCollection services = null;
logger.LogInformation("Begin IW4MAdmin startup. Version is {version} {@args}", Version, args);
try
{
// do any needed housekeeping file/folder migrations
@ -96,7 +104,7 @@ namespace IW4MAdmin.Application
services = ConfigureServices(args);
serviceProvider = services.BuildServiceProvider();
var versionChecker = serviceProvider.GetRequiredService<IMasterCommunication>();
ServerManager = (ApplicationManager)serviceProvider.GetRequiredService<IManager>();
ServerManager = (ApplicationManager) serviceProvider.GetRequiredService<IManager>();
translationLookup = serviceProvider.GetRequiredService<ITranslationLookup>();
await versionChecker.CheckVersion();
@ -105,8 +113,12 @@ namespace IW4MAdmin.Application
catch (Exception e)
{
string failMessage = translationLookup == null ? "Failed to initialize IW4MAdmin" : translationLookup["MANAGER_INIT_FAIL"];
string exitMessage = translationLookup == null ? "Press enter to exit..." : translationLookup["MANAGER_EXIT"];
string failMessage = translationLookup == null
? "Failed to initialize IW4MAdmin"
: translationLookup["MANAGER_INIT_FAIL"];
string exitMessage = translationLookup == null
? "Press enter to exit..."
: translationLookup["MANAGER_EXIT"];
logger.LogCritical(e, "Failed to initialize IW4MAdmin");
Console.WriteLine(failMessage);
@ -120,7 +132,8 @@ namespace IW4MAdmin.Application
{
if (translationLookup != null)
{
Console.WriteLine(translationLookup[configException.Message].FormatExt(configException.ConfigurationFileName));
Console.WriteLine(translationLookup[configException.Message]
.FormatExt(configException.ConfigurationFileName));
}
foreach (string error in configException.Errors)
@ -148,7 +161,9 @@ namespace IW4MAdmin.Application
catch (Exception e)
{
logger.LogCritical(e, "Failed to launch IW4MAdmin");
string failMessage = translationLookup == null ? "Failed to launch IW4MAdmin" : translationLookup["MANAGER_INIT_FAIL"];
string failMessage = translationLookup == null
? "Failed to launch IW4MAdmin"
: translationLookup["MANAGER_INIT_FAIL"];
Console.WriteLine($"{failMessage}: {e.GetExceptionInfo()}");
}
@ -166,9 +181,9 @@ namespace IW4MAdmin.Application
/// <returns></returns>
private static async Task RunApplicationTasksAsync(ILogger logger, IServiceCollection services)
{
var webfrontTask = ServerManager.GetApplicationSettings().Configuration().EnableWebFront ?
WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken) :
Task.CompletedTask;
var webfrontTask = ServerManager.GetApplicationSettings().Configuration().EnableWebFront
? WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken)
: Task.CompletedTask;
// we want to run this one on a manual thread instead of letting the thread pool handle it,
// because we can't exit early from waiting on console input, and it prevents us from restarting
@ -179,7 +194,8 @@ namespace IW4MAdmin.Application
{
ServerManager.Start(),
webfrontTask,
serviceProvider.GetRequiredService<IMasterCommunication>().RunUploadStatus(ServerManager.CancellationToken)
serviceProvider.GetRequiredService<IMasterCommunication>()
.RunUploadStatus(ServerManager.CancellationToken)
};
logger.LogDebug("Starting webfront and input tasks");
@ -231,11 +247,12 @@ namespace IW4MAdmin.Application
}
}
catch (OperationCanceledException)
{ }
{
}
}
private static IServiceCollection HandlePluginRegistration(ApplicationConfiguration appConfig,
IServiceCollection serviceCollection,
private static IServiceCollection HandlePluginRegistration(ApplicationConfiguration appConfig,
IServiceCollection serviceCollection,
IMasterApi masterApi)
{
var defaultLogger = BuildDefaultLogger<Program>(appConfig);
@ -248,33 +265,44 @@ namespace IW4MAdmin.Application
.BuildServiceProvider();
var pluginImporter = pluginServiceProvider.GetRequiredService<IPluginImporter>();
// we need to register the rest client with regular collection
serviceCollection.AddSingleton(masterApi);
// register the native commands
foreach (var commandType in typeof(SharedLibraryCore.Commands.QuitCommand).Assembly.GetTypes()
.Where(_command => _command.BaseType == typeof(Command)))
.Where(_command => _command.BaseType == typeof(Command)))
{
defaultLogger.LogDebug("Registered native command type {name}", commandType.Name);
serviceCollection.AddSingleton(typeof(IManagerCommand), commandType);
}
// register the plugin implementations
var pluginImplementations = pluginImporter.DiscoverAssemblyPluginImplementations();
foreach (var pluginType in pluginImplementations.Item1)
var (plugins, commands, configurations) = pluginImporter.DiscoverAssemblyPluginImplementations();
foreach (var pluginType in plugins)
{
defaultLogger.LogDebug("Registered plugin type {name}", pluginType.FullName);
serviceCollection.AddSingleton(typeof(IPlugin), pluginType);
}
// register the plugin commands
foreach (var commandType in pluginImplementations.Item2)
foreach (var commandType in commands)
{
defaultLogger.LogDebug("Registered plugin command type {name}", commandType.FullName);
serviceCollection.AddSingleton(typeof(IManagerCommand), commandType);
}
foreach (var configurationType in configurations)
{
defaultLogger.LogDebug("Registered plugin config type {name}", configurationType.Name);
var configInstance = (IBaseConfiguration) Activator.CreateInstance(configurationType);
var handlerType = typeof(BaseConfigurationHandler<>).MakeGenericType(configurationType);
var handlerInstance = Activator.CreateInstance(handlerType, new[] {configInstance.Name()});
var genericInterfaceType = typeof(IConfigurationHandler<>).MakeGenericType(configurationType);
serviceCollection.AddSingleton(genericInterfaceType, handlerInstance);
}
// register any script plugins
foreach (var scriptPlugin in pluginImporter.DiscoverScriptPlugins())
{
@ -284,10 +312,9 @@ namespace IW4MAdmin.Application
// register any eventable types
foreach (var assemblyType in typeof(Program).Assembly.GetTypes()
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))
.Union(pluginImplementations
.Item1.SelectMany(_asm => _asm.Assembly.GetTypes())
.Distinct()
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))))
.Union(plugins.SelectMany(_asm => _asm.Assembly.GetTypes())
.Distinct()
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))))
{
var instance = Activator.CreateInstance(assemblyType) as IRegisterEvent;
serviceCollection.AddSingleton(instance);
@ -295,7 +322,7 @@ namespace IW4MAdmin.Application
return serviceCollection;
}
/// <summary>
/// Configures the dependency injection services
@ -310,7 +337,7 @@ namespace IW4MAdmin.Application
? new Uri("http://127.0.0.1:8080")
: appConfig?.MasterUrl ?? new ApplicationConfiguration().MasterUrl;
var masterRestClient = RestClient.For<IMasterApi>(masterUri);
var translationLookup = Configure.Initialize(Utilities.DefaultLogger, masterRestClient, appConfig);
var translationLookup = Configure.Initialize(Utilities.DefaultLogger, masterRestClient, appConfig);
if (appConfig == null)
{
@ -327,13 +354,14 @@ namespace IW4MAdmin.Application
Utilities.PermissionLevelOverrides.Add(key, value);
}
}
// build the dependency list
HandlePluginRegistration(appConfig, serviceCollection, masterRestClient);
serviceCollection
.AddBaseLogger(appConfig)
.AddSingleton<IServiceCollection>(_serviceProvider => serviceCollection)
.AddSingleton<IConfigurationHandler<DefaultSettings>, BaseConfigurationHandler<DefaultSettings>>()
.AddSingleton((IConfigurationHandler<ApplicationConfiguration>) appConfigHandler)
.AddSingleton(
new BaseConfigurationHandler<CommandConfiguration>("CommandConfiguration") as
@ -372,6 +400,12 @@ namespace IW4MAdmin.Application
.AddSingleton<IManager, ApplicationManager>()
.AddSingleton<SharedLibraryCore.Interfaces.ILogger, Logger>()
.AddSingleton<IClientNoticeMessageFormatter, ClientNoticeMessageFormatter>()
.AddSingleton<IClientStatisticCalculator, HitCalculator>()
.AddSingleton<IServerDistributionCalculator, ServerDistributionCalculator>()
.AddSingleton<IWeaponNameParser, WeaponNameParser>()
.AddSingleton<IHitInfoBuilder, HitInfoBuilder>()
.AddSingleton(typeof(ILookupCache<>), typeof(LookupCache<>))
.AddSingleton(typeof(IDataValueCache<,>), typeof(DataValueCache<,>))
.AddSingleton(translationLookup)
.AddDatabaseContextOptions(appConfig);
@ -386,7 +420,7 @@ namespace IW4MAdmin.Application
return serviceCollection;
}
private static ILogger BuildDefaultLogger<T>(ApplicationConfiguration appConfig)
{
var collection = new ServiceCollection()
@ -396,4 +430,4 @@ namespace IW4MAdmin.Application
return collection.GetRequiredService<ILogger<T>>();
}
}
}
}

View File

@ -1,8 +1,9 @@
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos.Meta.Responses;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;

View File

@ -1,10 +1,10 @@
using System;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos.Meta.Responses;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;

View File

@ -6,6 +6,7 @@ using SharedLibraryCore.Interfaces;
using SharedLibraryCore.QueryHelper;
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;

View File

@ -2,7 +2,8 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using IW4MAdmin.Plugins.Stats.Models;
using Data.Abstractions;
using Data.Models.Client.Stats;
using SharedLibraryCore.Database;
using SharedLibraryCore.Interfaces;

View File

@ -22,6 +22,11 @@ namespace IW4MAdmin.Application.Misc
Build();
}
public BaseConfigurationHandler() : this(typeof(T).Name)
{
}
public string FileName { get; }
public void Build()

View File

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data.Models;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Misc

View File

@ -7,8 +7,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using Data.Models;
namespace IW4MAdmin.Application.Misc
{

View File

@ -63,11 +63,12 @@ namespace IW4MAdmin.Application.Misc
/// discovers all the C# assembly plugins and commands
/// </summary>
/// <returns></returns>
public (IEnumerable<Type>, IEnumerable<Type>) DiscoverAssemblyPluginImplementations()
public (IEnumerable<Type>, IEnumerable<Type>, IEnumerable<Type>) DiscoverAssemblyPluginImplementations()
{
string pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}";
var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}";
var pluginTypes = Enumerable.Empty<Type>();
var commandTypes = Enumerable.Empty<Type>();
var configurationTypes = Enumerable.Empty<Type>();
if (Directory.Exists(pluginDir))
{
@ -92,10 +93,17 @@ namespace IW4MAdmin.Application.Misc
.Where(_assemblyType => _assemblyType.IsClass && _assemblyType.BaseType == typeof(Command));
_logger.LogDebug("Discovered {count} plugin commands", commandTypes.Count());
configurationTypes = assemblies
.SelectMany(asm => asm.GetTypes())
.Where(asmType =>
asmType.IsClass && asmType.GetInterface(nameof(IBaseConfiguration), false) != null);
_logger.LogDebug("Discovered {count} configuration implementations", configurationTypes.Count());
}
}
return (pluginTypes, commandTypes);
return (pluginTypes, commandTypes, configurationTypes);
}
private IEnumerable<Assembly> GetRemoteAssemblies()

View File

@ -4,6 +4,7 @@ using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using System;
using System.Threading.Tasks;
using Data.Models.Client;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Database.Models.EFClient;
using ILogger = Microsoft.Extensions.Logging.ILogger;
@ -18,7 +19,7 @@ namespace IW4MAdmin.Application.Misc
private readonly Action<GameEvent> _executeAction;
private readonly ILogger _logger;
public ScriptCommand(string name, string alias, string description, bool isTargetRequired, Permission permission,
public ScriptCommand(string name, string alias, string description, bool isTargetRequired, EFClient.Permission permission,
CommandArgument[] args, Action<GameEvent> executeAction, CommandConfiguration config, ITranslationLookup layout, ILogger<ScriptCommand> logger)
: base(config, layout)
{

View File

@ -4,6 +4,7 @@ using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using System;
using System.Net;
using Data.Models;
using static SharedLibraryCore.Database.Models.EFClient;
using static SharedLibraryCore.GameEvent;

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Data.Models;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;

View File

@ -0,0 +1,12 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace Data.Abstractions
{
public interface IDataValueCache<T, V> where T : class
{
void SetCacheItem(Func<DbSet<T>, Task<V>> itemGetter, string keyName, TimeSpan? expirationTime = null);
Task<V> GetCacheItem(string keyName);
}
}

View File

@ -1,6 +1,6 @@
using SharedLibraryCore.Database;
using Data.Context;
namespace SharedLibraryCore.Interfaces
namespace Data.Abstractions
{
/// <summary>
/// describes the capabilities of the database context factory

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Data.Abstractions
{
public interface ILookupCache<T> where T : class
{
Task InitializeAsync();
Task<T> AddAsync(T item);
Task<T> FirstAsync(Func<T, bool> query);
IEnumerable<T> GetAll();
}
}

View File

@ -1,4 +1,4 @@
namespace SharedLibraryCore.Interfaces
namespace Data.Abstractions
{
/// <summary>
/// describes the capability of extending properties by name

View File

@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Data.Abstractions
{
public interface IUniqueId
{
[NotMapped]
long Id { get; }
[NotMapped]
string Value { get; }
}
}

View File

@ -1,13 +1,12 @@
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Database.Models;
using System;
using System.Linq;
using System;
using System.Threading;
using System.Threading.Tasks;
using SharedLibraryCore.Interfaces;
using static SharedLibraryCore.Database.Models.EFClient;
using Data.Abstractions;
using Data.Models;
using Data.Models.Client;
using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database
namespace Data.Context
{
public static class ContextSeed
{
@ -30,7 +29,7 @@ namespace SharedLibraryCore.Database
Connections = 0,
FirstConnection = DateTime.UtcNow,
LastConnection = DateTime.UtcNow,
Level = Permission.Console,
Level = EFClient.Permission.Console,
Masked = true,
NetworkId = 0,
AliasLink = link,

View File

@ -0,0 +1,135 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Threading;
using System.Threading.Tasks;
using Data.Extensions;
using Data.Models;
using Data.Models.Client;
using Data.Models.Client.Stats;
using Data.Models.Client.Stats.Reference;
using Data.Models.Server;
namespace Data.Context
{
public abstract class DatabaseContext : DbContext
{
public DbSet<EFClient> Clients { get; set; }
public DbSet<EFAlias> Aliases { get; set; }
public DbSet<EFAliasLink> AliasLinks { get; set; }
public DbSet<EFPenalty> Penalties { get; set; }
public DbSet<EFMeta> EFMeta { get; set; }
public DbSet<EFChangeHistory> EFChangeHistory { get; set; }
#region STATS
public DbSet<Models.Vector3> Vector3s { get; set; }
public DbSet<EFACSnapshotVector3> SnapshotVector3s { get; set; }
public DbSet<EFACSnapshot> ACSnapshots { get; set; }
public DbSet<EFServer> Servers { get; set; }
public DbSet<EFClientKill> ClientKills { get; set; }
public DbSet<EFClientMessage> ClientMessages { get; set; }
public DbSet<EFServerStatistics> ServerStatistics { get; set; }
public DbSet<EFHitLocation> HitLocations { get; set; }
public DbSet<EFClientHitStatistic> HitStatistics { get; set; }
public DbSet<EFWeapon> Weapons { get; set; }
public DbSet<EFWeaponAttachment> WeaponAttachments { get; set; }
public DbSet<EFMap> Maps { get; set; }
#endregion
private void SetAuditColumns()
{
return;
}
public DatabaseContext()
{
if (!MigrationExtensions.IsMigration)
{
throw new InvalidOperationException();
}
}
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
protected DatabaseContext(DbContextOptions options) : base(options)
{
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = default)
{
SetAuditColumns();
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
public override int SaveChanges()
{
SetAuditColumns();
return base.SaveChanges();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// make network id unique
modelBuilder.Entity<EFClient>(entity => { entity.HasIndex(e => e.NetworkId).IsUnique(); });
modelBuilder.Entity<EFPenalty>(entity =>
{
entity.HasOne(p => p.Offender)
.WithMany(c => c.ReceivedPenalties)
.HasForeignKey(c => c.OffenderId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne(p => p.Punisher)
.WithMany(p => p.AdministeredPenalties)
.HasForeignKey(c => c.PunisherId)
.OnDelete(DeleteBehavior.Restrict);
entity.Property(p => p.Expires)
.IsRequired(false);
});
modelBuilder.Entity<EFAliasLink>(entity =>
{
entity.HasMany(e => e.Children)
.WithOne(a => a.Link)
.HasForeignKey(k => k.LinkId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<EFAlias>(ent =>
{
ent.Property(a => a.IPAddress).IsRequired(false);
ent.HasIndex(a => a.IPAddress);
ent.Property(a => a.Name).HasMaxLength(24);
ent.HasIndex(a => a.Name);
ent.Property(_alias => _alias.SearchableName).HasMaxLength(24);
ent.HasIndex(_alias => _alias.SearchableName);
ent.HasIndex(_alias => new {_alias.Name, _alias.IPAddress}).IsUnique();
});
modelBuilder.Entity<EFMeta>(ent =>
{
ent.HasIndex(_meta => _meta.Key);
ent.HasIndex(_meta => _meta.LinkedMetaId);
ent.HasOne(_meta => _meta.LinkedMeta)
.WithMany()
.OnDelete(DeleteBehavior.SetNull);
});
// force full name for database conversion
modelBuilder.Entity<EFClient>().ToTable("EFClients");
modelBuilder.Entity<EFAlias>().ToTable("EFAlias");
modelBuilder.Entity<EFAliasLink>().ToTable("EFAliasLinks");
modelBuilder.Entity<EFPenalty>().ToTable("EFPenalties");
Models.Configuration.StatsModelConfiguration.Configure(modelBuilder);
base.OnModelCreating(modelBuilder);
}
}
}

82
Data/Data.csproj Normal file
View File

@ -0,0 +1,82 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;Prerelease</Configurations>
<Platforms>AnyCPU</Platforms>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>RaidMax.IW4MAdmin.Data</PackageId>
<Title>RaidMax.IW4MAdmin.Data</Title>
<Authors />
</PropertyGroup>
<ItemGroup>
<Compile Remove="Migrations\MySql\20210210221342_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\MySql\20210210221342_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210224014503_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210224014503_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210224030227_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210224030227_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210224031245_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210224031245_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210227041237_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210227041237_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210227161333_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210227161333_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210307163752_AddRankingHistory.cs" />
<Compile Remove="Migrations\Postgresql\20210307163752_AddRankingHistory.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209205243_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209205243_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209205948_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209205948_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209211745_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209211745_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209212725_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209212725_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210020314_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210020314_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210140835_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210140835_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210154738_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210154738_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210163803_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210163803_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210193852_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210193852_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210211033835_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210211033835_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210219013429_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210219013429_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210220171950_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210220171950_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210223163022_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210223163022_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210226215929_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210226215929_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210227160800_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210227160800_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210305033616_AddRankingHistory.cs" />
<Compile Remove="Migrations\Sqlite\20210305033616_AddRankingHistory.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210305033846_AddRankingHistory.cs" />
<Compile Remove="Migrations\Sqlite\20210305033846_AddRankingHistory.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210306223712_AddRankingHistory.cs" />
<Compile Remove="Migrations\Sqlite\20210306223712_AddRankingHistory.Designer.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="4.1.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.10" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.10" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
namespace Data.Extensions
{
public static class MigrationExtensions
{
public static bool IsMigration => Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Migration";
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Data.Helpers
{
public class DataValueCache<T, V> : IDataValueCache<T, V> where T : class
{
private readonly ILogger _logger;
private readonly IDatabaseContextFactory _contextFactory;
private readonly Dictionary<string, CacheState> _cacheStates = new Dictionary<string, CacheState>();
private const int DefaultExpireMinutes = 15;
private class CacheState
{
public string Key { get; set; }
public DateTime LastRetrieval { get; set; }
public TimeSpan ExpirationTime { get; set; }
public Func<DbSet<T>, Task<V>> Getter { get; set; }
public V Value { get; set; }
public bool IsExpired => (DateTime.Now - LastRetrieval.Add(ExpirationTime)).TotalSeconds > 0;
}
public DataValueCache(ILogger<DataValueCache<T, V>> logger, IDatabaseContextFactory contextFactory)
{
_logger = logger;
_contextFactory = contextFactory;
}
public void SetCacheItem(Func<DbSet<T>, Task<V>> getter, string key, TimeSpan? expirationTime = null)
{
if (_cacheStates.ContainsKey(key))
{
_logger.LogDebug("Cache key {key} is already added", key);
return;
}
var state = new CacheState()
{
Key = key,
Getter = getter,
ExpirationTime = expirationTime ?? TimeSpan.FromMinutes(DefaultExpireMinutes)
};
_cacheStates.Add(key, state);
}
public async Task<V> GetCacheItem(string keyName)
{
if (!_cacheStates.ContainsKey(keyName))
{
throw new ArgumentException("No cache found for key {key}", keyName);
}
var state = _cacheStates[keyName];
if (state.IsExpired)
{
await RunCacheUpdate(state);
}
return state.Value;
}
private async Task RunCacheUpdate(CacheState state)
{
try
{
await using var context = _contextFactory.CreateContext(false);
var set = context.Set<T>();
var value = await state.Getter(set);
state.Value = value;
state.LastRetrieval = DateTime.Now;
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not get cached value for {key}", state.Key);
}
}
}
}

114
Data/Helpers/LookupCache.cs Normal file
View File

@ -0,0 +1,114 @@
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Data.Helpers
{
public class LookupCache<T> : ILookupCache<T> where T : class, IUniqueId
{
private readonly ILogger _logger;
private readonly IDatabaseContextFactory _contextFactory;
private Dictionary<long, T> _cachedItems;
private readonly SemaphoreSlim _onOperation = new SemaphoreSlim(1, 1);
public LookupCache(ILogger<LookupCache<T>> logger, IDatabaseContextFactory contextFactory)
{
_logger = logger;
_contextFactory = contextFactory;
}
public async Task<T> AddAsync(T item)
{
await _onOperation.WaitAsync();
T existingItem = null;
if (_cachedItems.ContainsKey(item.Id))
{
existingItem = _cachedItems[item.Id];
}
if (existingItem != null)
{
_logger.LogDebug("Cached item already added for {type} {id} {value}", typeof(T).Name, item.Id,
item.Value);
_onOperation.Release();
return existingItem;
}
try
{
_logger.LogDebug("Adding new {type} with {id} {value}", typeof(T).Name, item.Id, item.Value);
await using var context = _contextFactory.CreateContext();
context.Set<T>().Add(item);
await context.SaveChangesAsync();
_cachedItems.Add(item.Id, item);
return item;
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not add item to cache for {type}", typeof(T).Name);
throw new Exception("Could not add item to cache");
}
finally
{
if (_onOperation.CurrentCount == 0)
{
_onOperation.Release();
}
}
}
public async Task<T> FirstAsync(Func<T, bool> query)
{
await _onOperation.WaitAsync();
try
{
var cachedResult = _cachedItems.Values.Where(query);
if (cachedResult.Any())
{
return cachedResult.FirstOrDefault();
}
}
catch
{
}
finally
{
if (_onOperation.CurrentCount == 0)
{
_onOperation.Release(1);
}
}
return null;
}
public IEnumerable<T> GetAll()
{
return _cachedItems.Values;
}
public async Task InitializeAsync()
{
try
{
await using var context = _contextFactory.CreateContext();
_cachedItems = await context.Set<T>().ToDictionaryAsync(item => item.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not initialize caching for {cacheType}", typeof(T).Name);
}
}
}
}

View File

@ -1,13 +1,15 @@
using System;
using Data.Context;
using Data.Extensions;
using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database.MigrationContext
namespace Data.MigrationContext
{
public class MySqlDatabaseContext : DatabaseContext
{
public MySqlDatabaseContext()
{
if (!Utilities.IsMigration)
if (!MigrationExtensions.IsMigration)
{
throw new InvalidOperationException();
}
@ -20,7 +22,7 @@ namespace SharedLibraryCore.Database.MigrationContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (Utilities.IsMigration)
if (MigrationExtensions.IsMigration)
{
optionsBuilder.UseMySql("Server=127.0.0.1;Database=IW4MAdmin_Migration;Uid=root;Pwd=password;")
.EnableDetailedErrors(true)

View File

@ -1,33 +1,34 @@
using System;
using Data.Context;
using Data.Extensions;
using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database.MigrationContext
namespace Data.MigrationContext
{
public class PostgresqlDatabaseContext : DatabaseContext
{
public PostgresqlDatabaseContext()
{
if (!Utilities.IsMigration)
if (!MigrationExtensions.IsMigration)
{
throw new InvalidOperationException();
}
}
public PostgresqlDatabaseContext(DbContextOptions options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (Utilities.IsMigration)
if (MigrationExtensions.IsMigration)
{
optionsBuilder.UseNpgsql(
"Host=127.0.0.1;Database=IW4MAdmin_Migration;Username=postgres;Password=password;")
"Host=127.0.0.1;Database=IW4MAdmin_Migration;Username=postgres;Password=password;",
options => options.SetPostgresVersion(new Version("9.4")))
.EnableDetailedErrors(true)
.EnableSensitiveDataLogging(true);
}
}
}
}

View File

@ -1,13 +1,15 @@
using System;
using Data.Context;
using Data.Extensions;
using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database.MigrationContext
namespace Data.MigrationContext
{
public class SqliteDatabaseContext : DatabaseContext
{
public SqliteDatabaseContext()
{
if (!Utilities.IsMigration)
if (!MigrationExtensions.IsMigration)
{
throw new InvalidOperationException();
}
@ -20,7 +22,7 @@ namespace SharedLibraryCore.Database.MigrationContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (Utilities.IsMigration)
if (MigrationExtensions.IsMigration)
{
optionsBuilder.UseSqlite("Data Source=IW4MAdmin_Migration.db")
.EnableDetailedErrors(true)

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.MigrationContext;
using Data;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180409183408_InitialCreate")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class InitialCreate : Migration
{

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.MigrationContext;
using Data;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180502195450_Update")]

View File

@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class Update : Migration
{

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.MigrationContext;
using Data;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180516023249_AddEloField")]

View File

@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddEloField : Migration
{

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.MigrationContext;
using Data;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180517223349_AddRollingKDR")]

View File

@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddRollingKDR : Migration
{

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180531212903_AddAutomatedOffenseAndRatingHistory")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddAutomatedOffenseAndRatingHistory : Migration
{

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180601172317_AddActivityAmount")]

View File

@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddActivityAmount : Migration
{

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180602041758_AddClientMeta")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddClientMeta : Migration
{

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180605191706_AddEFACSnapshots")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddEFACSnapshots : Migration
{

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
using System;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180614014303_IndexForEFAlias")]

View File

@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class IndexForEFAlias : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180902035612_AddFractionAndIsKill")]

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddFractionAndIsKill : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180904154622_AddVisibilityPercentage")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddVisibilityPercentage : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180907020706_AddVision")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddVision : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180908004053_AddWhenToRating")]

View File

@ -1,7 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddWhenToRating : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180910221749_AddRatingIndexes")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddRatingIndexes : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180911184224_AddEFAliasNameIndex")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddEFAliasNameIndex : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180911190823_AddEFAliasNameMaxLength24")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddEFAliasNameMaxLength24 : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180912015012_AddPreviousCurrentValueToEFChangeHistory")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddPreviousCurrentValueToEFChangeHistory : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180915163111_AddIndexToMessageTimeSent")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddIndexToMessageTimeSent : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180922231310_RemoveACSnapShot")]

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class RemoveACSnapShot : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180922231600_ReaddACSnapshot")]

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class ReaddACSnapshot : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181014171848_MakePenaltyExpirationNullable")]

View File

@ -1,7 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class MakePenaltyExpirationNullable : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181125193243_MakeClientIPNullable")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class MakeClientIPNullable : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181127144417_AddEndpointToEFServerUpdateServerIdType")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddEndpointToEFServerUpdateServerIdType : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181216214513_AddEvadePenaltyFlag")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddEvadePenaltyFlag : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190222234742_AddIndexToEFMeta-KeyAndClientId")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddIndexToEFMetaKeyAndClientId : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190423142128_AddGameNameToEFServer")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddGameNameToEFServer : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190615145212_AddAvgRecoilOffset")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddAvgRecoilOffset : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190615214055_AddRecoilOffsetToSnapshot")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddRecoilOffsetToSnapshot : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190725000309_AlterEFRatingIndex")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AlterEFRatingIndex : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190802174908_AddSearchNameToEFAlias")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddSearchNameToEFAlias : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190831210503_AvgSnapValueToClientStatistics")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AvgSnapValueToClientStatistics : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190901180209_AddSnapHitCountToClientStatistics")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
public partial class AddSnapHitCountToClientStatistics : Migration
{

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext;
using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql
namespace Data.Migrations.MySql
{
[DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190901223620_UseJunctionTableForSnapshotVector3")]

Some files were not shown because too many files have changed in this diff Show More