123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- namespace EVCB_OCPP.WSServer
- {
- public static class GlobalConfig
- {
- public static List<string> ConfigKeys = new List<string>()
- {
- "WSPort",
- "WSSPort",
- "OCPP20_WSUrl",
- "OCPP20_WSSUrl",
- "SecurityProfileLevel",
- "SecurityPassword"
- };
- public static List<string> DenyModelNames = new List<string>();
- public static string UTC_DATETIMEFORMAT = "yyyy-MM-dd'T'HH':'mm':'ss'Z'";
- public static string TCC_API_URL = string.Empty;
- public static string TCC_SALTKEY = string.Empty;
- public static string OCPP20_WSUrl = string.Empty;
- public static string OCPP20_WSSUrl = string.Empty;
- public static int SecurityProfileLevel = 0;
- public static string SecurityPassword = string.Empty;
- public static JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings()
- {
- NullValueHandling = NullValueHandling.Ignore,
- Formatting = Formatting.None,
- DateFormatString = UTC_DATETIMEFORMAT
- };
- /// <summary>
- /// 預設心跳間隔時間 單位:秒
- /// </summary>
- private static int DEFAULT_HEARTBEAT_INTERVAL = 60;
- /// <summary>
- ///WS Port
- /// </summary>
- private static int WS_Port = 2012;
- /// <summary>
- ///WSS Port
- /// </summary>
- private static List<int> WSS_Ports = null;
-
- /// <summary>
- /// Load setting from app.config
- /// </summary>
- public static bool LoadAPPConfig()
- {
- bool result = false;
- string key = string.Empty;
- try
- {
- for (int i = 0; i < ConfigKeys.Count; i++)
- {
- key = ConfigKeys[i];
- switch (key)
- {
- case "WSPort":// convert to int type
- {
- var value = ConfigurationManager.AppSettings[key];
- WS_Port = 0;
- Int32.TryParse(value, out WS_Port);
-
- }
- break;
- case "WSSPort":
- {
- var ports = ConfigurationManager.AppSettings[key].Split(',');
- WSS_Ports = new List<int>();
- foreach(var port in ports)
- {
- WSS_Ports.Add(Convert.ToInt32(port));
- }
-
- }
- break;
- case "OCPP20_WSUrl":// convert to int type
- {
- var value = ConfigurationManager.AppSettings[key];
- OCPP20_WSUrl = value;
- }
- break;
- case "OCPP20_WSSUrl":// convert to int type
- {
- var value = ConfigurationManager.AppSettings[key];
- OCPP20_WSSUrl = value;
- }
- break;
- case "SecurityProfileLevel":
- {
- var value = ConfigurationManager.AppSettings[key];
- SecurityProfileLevel = Convert.ToInt32(value);
- }
- break;
- case "SecurityPassword":
- {
- var value = ConfigurationManager.AppSettings[key];
- SecurityPassword = value;
- }
- break;
- default://convert to string type
- break;
- }
- }
- result = true;
- }
- catch (Exception ex)
- {
- Console.WriteLine(key + " Load from APPConfig " + ex.ToString());
- }
- return result;
- }
- public static int GetWS_Port()
- {
- return WS_Port;
- }
- public static List<int> GetWSS_Ports()
- {
- return WSS_Ports;
- }
-
- public static int GetHEARTBEAT_INTERVAL()
- {
- return DEFAULT_HEARTBEAT_INTERVAL;
- }
- public static readonly int DB_DefaultConnectionTimeout = 60;
- /// <summary>
- /// 預設 Null的 DateTime
- /// </summary>
- public static DateTime DefaultNullTime = new DateTime(1991, 1, 1);
- }
- }
|