| | |
| | | using System.Threading.Tasks; |
| | | using Rhea.Common; |
| | | using Tiger.IBusiness; |
| | | using System.ServiceProcess; |
| | | using Tiger.Api.DbCache; |
| | | |
| | | namespace Tiger.Api |
| | | { |
| | | public static class WebHostServiceExtensions |
| | | { |
| | | public static void RunAsApiService(this IWebHost host) |
| | | { |
| | | try |
| | | { |
| | | var webHostService = new ApiWebHostService(host); |
| | | ServiceBase.Run(webHostService); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Logger.Console.Fatal(ex, "Windows Services Exception"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | internal class ApiWebHostService : WebHostService |
| | | { |
| | | public ApiWebHostService(IWebHost host) : base(host) |
| | |
| | | //关闭服务总线 |
| | | DI.Resolve<IServicesBus>().StopServices(); |
| | | //关闭DB缓存自动更新 |
| | | DI.Resolve<IDbCacheBus>().StopAutoUpdate(); |
| | | MQTTHelper.MQTTConn?.Close(); |
| | | base.OnStopping(); |
| | | //DI.Resolve<IDbCacheBus>().StopAutoUpdate(); |
| | | DbCacheBus.StopAutoUpdate(); |
| | | //MQTTHelper.MQTTConn?.Close(); |
| | | base.OnStopping(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |