Settings.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.Hosting;
  5. namespace NetCore31BACNetTransfor
  6. {
  7. public static class Settings
  8. {
  9. public static int BacSplitSize { get; private set; }
  10. public static int WaitTime { get; private set; }
  11. public static int HeartBeatInterval { get; private set; }
  12. public static int LocalBacPort { get; private set; }
  13. public static int LocalUdpPort { get; private set; }
  14. public static string RemoteUdpIP { get; private set; }
  15. public static int RemoteUdpPort { get; private set; }
  16. public static int AcquisitionFrequency { get; private set; }
  17. public static string BuildingSign { get; private set; }
  18. public static int Gateway { get; private set; }
  19. public static string SendType { get; private set; }
  20. public static string MeterSignPre { get; private set; }
  21. public static string FuncId { get; private set; }
  22. public static bool IgnoreFirstValue { get; private set; }
  23. public static bool Localdebug { get; private set; }
  24. public static bool RollCall { get; private set; }
  25. public static void InitSettings(string[] args)
  26. {
  27. IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(System.IO.Directory.GetCurrentDirectory()).AddJsonFile("appsetting.json", true, reloadOnChange: true);
  28. IConfigurationRoot Configuration = builder.Build();
  29. //conStrings = Configuration.GetConnectionString("SqlServerConnection");
  30. // Application code should start here.
  31. IConfigurationSection section = Configuration.GetSection("appSettings");
  32. LocalUdpPort = int.Parse(section.GetSection("LocalUdpPort").Value);
  33. BacSplitSize = int.Parse(section.GetSection("BacSplitSize").Value);
  34. WaitTime = int.Parse(section.GetSection("WaitTime").Value);
  35. HeartBeatInterval = int.Parse(section.GetSection("HeartBeatInterval").Value);
  36. LocalBacPort = int.Parse(section.GetSection("LocalBacPort").Value);
  37. RemoteUdpIP = section.GetSection("RemoteUdpIP").Value;
  38. RemoteUdpPort = int.Parse(section.GetSection("RemoteUdpPort").Value);
  39. AcquisitionFrequency = int.Parse(section.GetSection("AcquisitionFrequency").Value);
  40. BuildingSign = section.GetSection("BuildingSign").Value;
  41. Gateway = int.Parse(section.GetSection("Gateway").Value);
  42. SendType = section.GetSection("SendType").Value;
  43. MeterSignPre = section.GetSection("MeterSignPre").Value;
  44. FuncId = section.GetSection("FuncId").Value;
  45. IgnoreFirstValue = string.Equals("true", section.GetSection("IgnoreFirstValue").Value, StringComparison.CurrentCultureIgnoreCase);
  46. Localdebug = string.Equals("true", section.GetSection("Localdebug").Value, StringComparison.CurrentCultureIgnoreCase);
  47. RollCall = string.Equals("true", section.GetSection("RollCall").Value, StringComparison.CurrentCultureIgnoreCase);
  48. Logger.Log("InitSettings Finished");
  49. }
  50. }
  51. }