Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

58 rader
1.9 KiB

  1. using BPA.ApolloClient;
  2. using BPA.ApolloClient.Options;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.Hosting;
  7. using System;
  8. using System.Runtime.InteropServices;
  9. namespace DataVAPI
  10. {
  11. public class Program
  12. {
  13. public delegate bool ControlCtrlDelegate(int CtrlType);
  14. [DllImport("kernel32.dll")]
  15. private static extern bool SetConsoleCtrlHandler(ControlCtrlDelegate HandlerRoutine, bool Add);
  16. private static ControlCtrlDelegate cancelHandler = new ControlCtrlDelegate(HandlerRoutine);
  17. public static bool HandlerRoutine(int CtrlType)
  18. {
  19. //数据保存
  20. switch (CtrlType)
  21. {
  22. case 0:
  23. //Console.WriteLine("0工具被强制关闭"); //Ctrl+C关闭
  24. break;
  25. case 2:
  26. //Console.WriteLine("2工具被强制关闭");//按控制台关闭按钮关闭
  27. break;
  28. }
  29. Console.ReadLine();
  30. return false;
  31. }
  32. public static void Main(string[] args)
  33. {
  34. CreateHostBuilder(args).Build().Run();
  35. }
  36. public static IHostBuilder CreateHostBuilder(string[] args) =>
  37. Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
  38. {
  39. //配置阿波罗
  40. webBuilder.ConfigureAppConfiguration((context, builder) =>
  41. {
  42. builder.AddApolloConfiguration(op =>
  43. {
  44. builder.Build().GetSection(nameof(ApolloOptions)).Bind(op);
  45. });
  46. })
  47. .UseUrls("http://*:80")// 这里默认是http://*:5000 .现在改成8003端口
  48. .UseStartup<Startup>();
  49. });
  50. }
  51. }