make some methods public for testing purposes
This commit is contained in:
parent
3c682780a4
commit
5b552ac310
@ -11,12 +11,19 @@ namespace ChaosBot.Attribute
|
|||||||
public static class AssemblyController
|
public static class AssemblyController
|
||||||
{
|
{
|
||||||
private static Logger _logger = Program._logger;
|
private static Logger _logger = Program._logger;
|
||||||
public static void Register()
|
public static void RegisterAll()
|
||||||
{
|
{
|
||||||
Assembly dbEntityAssembly = Assembly.GetAssembly(typeof(DBEntity));
|
Assembly dbEntityAssembly = Assembly.GetAssembly(typeof(DBEntity));
|
||||||
if (dbEntityAssembly != null)
|
if (dbEntityAssembly != null)
|
||||||
{
|
{
|
||||||
foreach (Type type in dbEntityAssembly.GetTypes())
|
foreach (Type type in dbEntityAssembly.GetTypes())
|
||||||
|
{
|
||||||
|
RegisterDBEntityType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterDBEntityType(Type type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -48,6 +55,7 @@ namespace ChaosBot.Attribute
|
|||||||
{
|
{
|
||||||
columnType = DBEntity.DataTypes.GetValueOrDefault(prop.PropertyType).ToString();
|
columnType = DBEntity.DataTypes.GetValueOrDefault(prop.PropertyType).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder constraintNameBuilder = new StringBuilder($"{table}_{columnName}");
|
StringBuilder constraintNameBuilder = new StringBuilder($"{table}_{columnName}");
|
||||||
List<string> constraintsList = new List<string>();
|
List<string> constraintsList = new List<string>();
|
||||||
|
|
||||||
@ -72,8 +80,10 @@ namespace ChaosBot.Attribute
|
|||||||
constraintsList.Insert(0, "CONSTRAINT");
|
constraintsList.Insert(0, "CONSTRAINT");
|
||||||
constraintsList.Insert(1, constraintName);
|
constraintsList.Insert(1, constraintName);
|
||||||
}
|
}
|
||||||
|
|
||||||
string constraints = String.Join(" ", constraintsList);
|
string constraints = String.Join(" ", constraintsList);
|
||||||
columnList.Add(new Tuple<string, string, string, string>(columnName, columnType, constraintName, constraints));
|
columnList.Add(
|
||||||
|
new Tuple<string, string, string, string>(columnName, columnType, constraintName, constraints));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check table exists
|
// Check table exists
|
||||||
@ -112,5 +122,3 @@ namespace ChaosBot.Attribute
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +1,13 @@
|
|||||||
using NLog;
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using ChaosBot.Discord;
|
using ChaosBot.Discord;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ChaosBot.Attribute;
|
using ChaosBot.Attribute;
|
||||||
using ChaosBot.Database.Repository;
|
using ChaosBot.Database.Repository;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("ChaosBot.UnitTests")]
|
||||||
namespace ChaosBot
|
namespace ChaosBot
|
||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
@ -27,27 +28,26 @@ namespace ChaosBot
|
|||||||
/*
|
/*
|
||||||
* Load configuration from AppSettings.Json and save as Cfg
|
* Load configuration from AppSettings.Json and save as Cfg
|
||||||
*/
|
*/
|
||||||
ConfigurationRepository.AppSettingsHandler = new ConfigurationBuilder()
|
LoadConfiguration(appsettingsPath);
|
||||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile(appsettingsPath, optional: false, reloadOnChange: true).Build();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the _logger for logging purposes
|
* Initialize the _logger for logging purposes
|
||||||
*/
|
*/
|
||||||
_logger = Logging.GenLog();
|
LoadLogger();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to load our custom assemblies
|
* Attempt to load our custom assemblies
|
||||||
*/
|
*/
|
||||||
AssemblyController.Register();
|
RegisterAssemblyController();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the Discord Client and Login
|
* Initialize the Discord Client and Login
|
||||||
*/
|
*/
|
||||||
_logger.Info($"Starting Up {ConfigurationRepository.GetValue<string>("Bot:Name")} v{ConfigurationRepository.GetValue<string>("Bot:Version")}");
|
_logger.Info($"Starting Up {ConfigurationRepository.GetValue<string>("Bot:Name")} v{ConfigurationRepository.GetValue<string>("Bot:Version")}");
|
||||||
|
|
||||||
var discordBot = DiscordConnect.StartUp();
|
|
||||||
WebServer.WebServer.Start(new string[]{});
|
var discordBot = LoadDiscord();
|
||||||
|
LoadWebServer();
|
||||||
await discordBot;
|
await discordBot;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -55,5 +55,32 @@ namespace ChaosBot
|
|||||||
_logger.Error(ex, $"Program.MainFunction: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
_logger.Error(ex, $"Program.MainFunction: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LoadConfiguration(string appsettingsPath)
|
||||||
|
{
|
||||||
|
ConfigurationRepository.AppSettingsHandler = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile(appsettingsPath, optional: false, reloadOnChange: true).Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadLogger()
|
||||||
|
{
|
||||||
|
_logger = Logging.GenLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterAssemblyController()
|
||||||
|
{
|
||||||
|
AssemblyController.RegisterAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadWebServer()
|
||||||
|
{
|
||||||
|
WebServer.WebServer.Start(new string[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task LoadDiscord()
|
||||||
|
{
|
||||||
|
return DiscordConnect.StartUp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user