88 lines
2.2 KiB
C#
88 lines
2.2 KiB
C#
using SecondBotEvents.Services;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
|
|
namespace SecondBotEvents
|
|
{
|
|
internal class Startup
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("Welcome to Secondbot [Events build] version: " + AssemblyInfo.GetGitHash());
|
|
EventsSecondBot worker = new EventsSecondBot(args);
|
|
|
|
while(worker.exit() == false)
|
|
{
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class EventsSecondBot
|
|
{
|
|
public http HttpService = null;
|
|
public BotClient botClient = null;
|
|
|
|
public string getVersion()
|
|
{
|
|
return AssemblyInfo.GetGitHash();
|
|
}
|
|
|
|
public bool fromEnv = false;
|
|
public string fromFolder = "";
|
|
public EventsSecondBot(string[] args)
|
|
{
|
|
if (SecondbotHelpers.notempty(Environment.GetEnvironmentVariable("basic_username")) == true)
|
|
{
|
|
fromEnv = true;
|
|
}
|
|
restartServices();
|
|
}
|
|
public void restartServices()
|
|
{
|
|
stopServices();
|
|
startServices();
|
|
}
|
|
protected void startServices()
|
|
{
|
|
HttpService = new http(this);
|
|
HttpService.start();
|
|
botClient = new BotClient(this);
|
|
botClient.start();
|
|
|
|
}
|
|
protected void stopServices()
|
|
{
|
|
if (HttpService != null)
|
|
{
|
|
HttpService.stop();
|
|
}
|
|
if(botClient != null)
|
|
{
|
|
botClient.stop();
|
|
}
|
|
HttpService = null;
|
|
botClient = null;
|
|
}
|
|
|
|
public bool exit()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public static class AssemblyInfo
|
|
{
|
|
/// <summary> Gets the git hash value from the assembly
|
|
/// or null if it cannot be found. </summary>
|
|
public static string GetGitHash()
|
|
{
|
|
var asm = typeof(AssemblyInfo).Assembly;
|
|
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
|
|
return attrs.FirstOrDefault(a => a.Key == "GitHash")?.Value;
|
|
}
|
|
}
|
|
}
|