2021-12-06 02:49:27 +03:00
using Microsoft.AspNetCore.Hosting ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.Hosting ;
using Microsoft.Extensions.Logging ;
using System ;
using System.Collections.Generic ;
2022-08-13 20:15:43 +03:00
using System.IO ;
2021-12-06 02:49:27 +03:00
using System.Linq ;
using System.Threading.Tasks ;
using BlueWest.Core ;
using BlueWest.Tools ;
2022-08-19 19:47:35 +03:00
using BlueWest.WebApi.Interfaces ;
2021-12-06 02:49:27 +03:00
namespace BlueWest.WebApi
{
2022-08-22 00:14:50 +03:00
/// <summary>
/// Entry point of the application.
/// </summary>
2021-12-06 02:49:27 +03:00
public class Program
{
2022-08-20 05:47:32 +03:00
/// <summary>
/// Event Manager class
/// </summary>
2022-08-19 19:47:35 +03:00
public static EventManager EventManager { get ; set ; }
2021-12-06 02:49:27 +03:00
private static ThreadServer _threadServer ;
2021-12-08 02:57:27 +03:00
/ * private static CSharpCompilation GenerateCode ( string sourceCode )
{
var codeString = SourceText . From ( sourceCode ) ;
var parsedSyntaxTree = SyntaxFactory . ParseSyntaxTree ( codeString , CSharpParseOptions . Default ) ;
2021-12-06 02:49:27 +03:00
2021-12-08 02:57:27 +03:00
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 ) ) ;
} * /
2022-08-22 00:14:50 +03:00
/// <summary>
/// Host Interface of the application.
/// </summary>
public static IHost MainHost { get ; private set ; }
2021-12-06 02:49:27 +03:00
2022-08-22 02:51:45 +03:00
/// <summary>
/// Entry point of the application
/// </summary>
/// <param name="args">Command line arguments.</param>
2021-12-06 02:49:27 +03:00
public static void Main ( string [ ] args )
{
2022-08-22 00:14:50 +03:00
MainHost = CreateHostBuilder ( args )
2022-08-13 20:15:43 +03:00
. UseContentRoot ( Directory . GetCurrentDirectory ( ) )
. Build ( ) ;
2022-08-19 19:47:35 +03:00
2022-09-10 08:05:24 +03:00
MainHost . Run ( ) ;
2022-08-22 00:14:50 +03:00
2022-09-10 08:05:24 +03:00
//var tryGetEventManager = MainHost.Services.GetService(typeof(EventManager));
// _ = MainHost.Services.GetService(typeof(ExchangeInterface));
2022-08-19 19:47:35 +03:00
2022-09-10 08:05:24 +03:00
/ * if ( tryGetEventManager = = null ) Console . WriteLine ( $"Failed to get {nameof(EventManager)} Service." ) ;
2022-08-19 19:47:35 +03:00
if ( tryGetEventManager is EventManager eventManager )
{
// Use RunASync
System . Threading . Thread . Sleep ( 2500 ) ;
_threadServer = new ThreadServer ( eventManager ) ;
_threadServer . Init ( ) ;
2022-09-10 08:05:24 +03:00
} * /
2022-08-19 19:47:35 +03:00
2021-12-06 02:49:27 +03:00
}
2022-08-22 00:14:50 +03:00
private static IHostBuilder CreateHostBuilder ( string [ ] args ) = >
2021-12-06 02:49:27 +03:00
Host . CreateDefaultBuilder ( args )
2022-08-13 18:21:23 +03:00
2021-12-06 02:49:27 +03:00
. ConfigureWebHostDefaults ( webBuilder = >
{
webBuilder . UseStartup < Startup > ( ) ;
} ) ;
}
}