WebApiServer.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Abp.Dependency;
  2. using Microsoft.AspNetCore.Hosting;
  3. using System.IO;
  4. using Yunda.ISAS.DataMonitoringServer.DataCenter;
  5. namespace Yunda.ISAS.DataMonitoringServer.WebApi
  6. {
  7. public class WebApiServer : ISingletonDependency
  8. {
  9. private IWebHost _host;
  10. private WebApiConfigModel _configModel;
  11. public static CameraDataCenter _cameraDataCenter;
  12. public static RunningDataCache _runningDataCache;
  13. public WebApiServer(WebApiConfigModel webApiConfig,
  14. RunningDataCache runningDataCache,
  15. CameraDataCenter cameraDataCenter)
  16. {
  17. _configModel = webApiConfig;
  18. _cameraDataCenter = cameraDataCenter;
  19. _runningDataCache = runningDataCache;
  20. }
  21. public async void RunServerAsync(int port)
  22. {
  23. if (_host == null)
  24. {
  25. if (_configModel == null)
  26. _configModel = new WebApiConfigModel();
  27. string url = "http://*:" + port;
  28. _host = new WebHostBuilder()
  29. .UseKestrel()
  30. .UseContentRoot(Directory.GetCurrentDirectory())
  31. .UseUrls(url)
  32. .UseStartup<WebApiStartup>()
  33. .Build();
  34. await _host.RunAsync();
  35. }
  36. }
  37. public void ShutdownServer()
  38. {
  39. if (_host != null)
  40. _host.Dispose();
  41. //await _host.WaitForShutdownAsync();
  42. }
  43. }
  44. }