using System; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; namespace NetCore31BACNetTransfor { public static class Settings { public static int BacSplitSize { get; private set; } public static int WaitTime { get; private set; } public static int HeartBeatInterval { get; private set; } public static int LocalBacPort { get; private set; } public static int LocalUdpPort { get; private set; } public static string RemoteUdpIP { get; private set; } public static int RemoteUdpPort { get; private set; } public static int AcquisitionFrequency { get; private set; } public static string BuildingSign { get; private set; } public static int Gateway { get; private set; } public static string SendType { get; private set; } public static string MeterSignPre { get; private set; } public static string FuncId { get; private set; } public static bool IgnoreFirstValue { get; private set; } public static bool Localdebug { get; private set; } public static bool RollCall { get; private set; } public static void InitSettings(string[] args) { IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(System.IO.Directory.GetCurrentDirectory()).AddJsonFile("appsetting.json", true, reloadOnChange: true); IConfigurationRoot Configuration = builder.Build(); //conStrings = Configuration.GetConnectionString("SqlServerConnection"); // Application code should start here. IConfigurationSection section = Configuration.GetSection("appSettings"); LocalUdpPort = int.Parse(section.GetSection("LocalUdpPort").Value); BacSplitSize = int.Parse(section.GetSection("BacSplitSize").Value); WaitTime = int.Parse(section.GetSection("WaitTime").Value); HeartBeatInterval = int.Parse(section.GetSection("HeartBeatInterval").Value); LocalBacPort = int.Parse(section.GetSection("LocalBacPort").Value); RemoteUdpIP = section.GetSection("RemoteUdpIP").Value; RemoteUdpPort = int.Parse(section.GetSection("RemoteUdpPort").Value); AcquisitionFrequency = int.Parse(section.GetSection("AcquisitionFrequency").Value); BuildingSign = section.GetSection("BuildingSign").Value; Gateway = int.Parse(section.GetSection("Gateway").Value); SendType = section.GetSection("SendType").Value; MeterSignPre = section.GetSection("MeterSignPre").Value; FuncId = section.GetSection("FuncId").Value; IgnoreFirstValue = string.Equals("true", section.GetSection("IgnoreFirstValue").Value, StringComparison.CurrentCultureIgnoreCase); Localdebug = string.Equals("true", section.GetSection("Localdebug").Value, StringComparison.CurrentCultureIgnoreCase); RollCall = string.Equals("true", section.GetSection("RollCall").Value, StringComparison.CurrentCultureIgnoreCase); Logger.Log("InitSettings Finished"); } } }