CodeLiturgy.Dashboard/BlueWest.Api/Program.cs

80 lines
2.6 KiB
C#

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using BlueWest.Core;
using BlueWest.Tools;
using BlueWest.WebApi.Interfaces;
namespace BlueWest.WebApi
{
/// <summary>
/// Entry point of the application.
/// </summary>
public class Program
{
/// <summary>
/// Event Manager class
/// </summary>
public static EventManager EventManager { get; set; }
private static ThreadServer _threadServer;
/*private static CSharpCompilation GenerateCode(string sourceCode)
{
var codeString = SourceText.From(sourceCode);
var parsedSyntaxTree = SyntaxFactory.ParseSyntaxTree(codeString, CSharpParseOptions.Default);
return CSharpCompilation.Create("Hello.dll",
new[] { parsedSyntaxTree },
references: ReferenceAssemblies.Net50, // install jared's Basic.Reference.Assemblies for this, otherwise, you are going to manually add the DLLs you want
options: new CSharpCompilationOptions(OutputKind.ConsoleApplication,
optimizationLevel: OptimizationLevel.Release));
}*/
/// <summary>
/// Host Interface of the application.
/// </summary>
public static IHost MainHost { get; private set; }
public static void Main(string[] args)
{
MainHost = CreateHostBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory())
.Build();
MainHost.RunAsync();
var tryGetEventManager = MainHost.Services.GetService(typeof(EventManager));
_ = MainHost.Services.GetService(typeof(ExchangeInterface));
if(tryGetEventManager == null) Console.WriteLine($"Failed to get {nameof(EventManager)} Service.");
if (tryGetEventManager is EventManager eventManager)
{
// Use RunASync
System.Threading.Thread.Sleep(2500);
_threadServer = new ThreadServer(eventManager);
_threadServer.Init();
}
}
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}