think I finished reworking the event system

added http log reading support for debugging remotely
started working on unit test framework
This commit is contained in:
RaidMax
2018-08-28 16:32:59 -05:00
parent 56cb8c50e7
commit bbefd53db4
23 changed files with 543 additions and 296 deletions

View File

@ -43,6 +43,8 @@ namespace SharedLibraryCore.Database
currentPath = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
$"{Path.DirectorySeparatorChar}{currentPath}" :
currentPath;
// todo: fix later
var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = $"{currentPath}{Path.DirectorySeparatorChar}Database.db".Substring(6) };
var connectionString = connectionStringBuilder.ToString();
var connection = new SqliteConnection(connectionString);
@ -98,22 +100,28 @@ namespace SharedLibraryCore.Database
// adapted from
// https://aleemkhan.wordpress.com/2013/02/28/dynamically-adding-dbset-properties-in-dbcontext-for-entity-framework-code-first/
#if !DEBUG
foreach (string dllPath in Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins"))
#else
//#if DEBUG == TRUE
// // foreach (string dllPath in Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins"))
//#else
//todo: fix the debug thingie for entity scanning
IEnumerable<string> directoryFiles;
try
string pluginDir = $@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}netcoreapp2.0{Path.DirectorySeparatorChar}Plugins";
if (!Directory.Exists(pluginDir))
{
directoryFiles = Directory.GetFiles($@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}netcoreapp2.0{Path.DirectorySeparatorChar}Plugins").Where(f => f.Contains(".dll"));
pluginDir = $@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}Plugins";
if (!Directory.Exists(pluginDir))
{
pluginDir = Utilities.OperatingDirectory;
}
}
catch (Exception)
{
directoryFiles = Directory.GetFiles($@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}Plugins").Where(f => f.Contains(".dll"));
}
directoryFiles = Directory.GetFiles(pluginDir).Where(f => f.Contains(".dll"));
foreach (string dllPath in directoryFiles)
#endif
//#endif
{
Assembly library;
try

View File

@ -93,6 +93,7 @@ namespace SharedLibraryCore
queuedEvent.Type != EventType.Connect &&
queuedEvent.Type != EventType.Join &&
queuedEvent.Type != EventType.Quit &&
queuedEvent.Type != EventType.Disconnect &&
// we don't care about unknown events
queuedEvent.Origin.NetworkId != 0;
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SharedLibraryCore.Interfaces
{
/// <summary>
/// represents the abtraction of game log reading
/// </summary>
public interface IGameLogReader
{
/// <summary>
/// get new events that have occured since the last poll
/// </summary>
/// <param name="server"></param>
/// <param name="fileSizeDiff"></param>
/// <param name="startPosition"></param>
/// <returns></returns>
ICollection<GameEvent> EventsFromLog(Server server, long fileSizeDiff, long startPosition);
/// <summary>
/// how long the log file is
/// </summary>
long Length { get; }
/// <summary>
/// how often to poll the log file
/// </summary>
int UpdateInterval { get; }
}
}

View File

@ -28,7 +28,10 @@ namespace SharedLibraryCore.Localization
get
{
if (!Set.TryGetValue(key, out string value))
throw new Exception($"Invalid locale key {key}");
{
// throw new Exception($"Invalid locale key {key}");
return $"unknown locale key {key}";
}
return value;
}
}

View File

@ -15,8 +15,21 @@ namespace SharedLibraryCore.Plugins
public static bool Load(IManager Manager)
{
string[] dllFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.dll");
string[] scriptFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.js");
string pluginDir = $"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}";
string[] dllFileNames = null;
string[] scriptFileNames = null;
if (Directory.Exists(pluginDir))
{
dllFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.dll");
scriptFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.js");
}
else
{
dllFileNames = new string[0];
scriptFileNames = new string[0];
}
if (dllFileNames.Length == 0 &&
scriptFileNames.Length == 0)

View File

@ -40,7 +40,7 @@ namespace SharedLibraryCore.RCon
ILogger Log;
int FailedSends;
int FailedReceives;
DateTime LastQuery;
static DateTime LastQuery;
string response;
ManualResetEvent OnConnected;

View File

@ -18,7 +18,7 @@ namespace SharedLibraryCore
{
public static string OperatingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
public static Encoding EncodingType;
public static Localization.Layout CurrentLocalization;
public static Localization.Layout CurrentLocalization = new Localization.Layout(new Dictionary<string, string>());
public static string HttpRequest(string location, string header, string headerValue)
{