App.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
  2. using Edge.Core.IndustryStandardInterface.ATG;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Hosting;
  5. using Microsoft.Extensions.Logging;
  6. using Microsoft.Extensions.Logging.Abstractions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace Applications.UniversalApi_WebConsole_App
  13. {
  14. public class App : IAppProcessor
  15. {
  16. private ILogger logger = NullLogger.Instance;
  17. private string baseUrl;
  18. public App(IServiceProvider services, string baseUrl)
  19. {
  20. this.baseUrl = baseUrl;
  21. if (services != null)
  22. {
  23. var loggerFactory = services.GetRequiredService<ILoggerFactory>();
  24. this.logger = loggerFactory.CreateLogger("Application");
  25. }
  26. }
  27. public string MetaConfigName { get; set; }
  28. public void Init(IEnumerable<IProcessor> processors)
  29. {
  30. }
  31. IHost webHost;
  32. public Task<bool> Start()
  33. {
  34. if (string.IsNullOrEmpty(this.baseUrl)) this.baseUrl = "http://localhost:8888/";
  35. this.webHost = Program.CreateHostBuilder(new string[] { this.baseUrl }).Build();
  36. this.webHost.RunAsync();
  37. return Task.FromResult(true);
  38. }
  39. public async Task<bool> Stop()
  40. {
  41. await this.webHost?.StopAsync();
  42. this.webHost?.Dispose();
  43. return true;
  44. }
  45. }
  46. }