using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.WindowsServices; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Rhea.Common; using Tiger.IBusiness; namespace Tiger.Api { internal class ApiWebHostService : WebHostService { public ApiWebHostService(IWebHost host) : base(host) { } protected override void OnStarting(string[] args) { Logger.Default.Info("Run Api as Windows Services"); base.OnStarting(args); } protected override void OnStarted() { base.OnStarted(); Logger.Default.Info("Api Service is started"); } protected override void OnStopping() { try { Logger.Default.Info("Stopping Api Service"); //关闭Api监控总线 DI.Resolve().StopMonitors(); //关闭服务总线 DI.Resolve().StopServices(); //关闭DB缓存自动更新 DI.Resolve().StopAutoUpdate(); MQTTHelper.MQTTConn?.Close(); base.OnStopping(); } catch (System.Exception ex) { Logger.Default.Fatal(ex, "Api Service stop exception"); } } protected override void OnStopped() { base.OnStopped(); Logger.Default.Info("Api Service is stopped"); } protected override void OnShutdown() { base.OnShutdown(); Logger.Default.Info("Api Service is shut down"); } } }