AppSetting.cs 864 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Mime;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MqttMsgServer.Tools;
  8. namespace MqttMsgServer
  9. {
  10. public class AppSetting
  11. {
  12. public static string AppConfigPath = $"{AppDomain.CurrentDomain.BaseDirectory}/AppConfig.xml";
  13. public static string GetValue(string key)
  14. {
  15. XmlHelper xmlHelper = new XmlHelper();
  16. var xmlNode = xmlHelper.GetXmlNodeByXpath(AppConfigPath, $"root/{key}");
  17. return xmlNode?.InnerText;
  18. }
  19. public static int GetInt(string key)
  20. {
  21. string value = GetValue(key);
  22. if (int.TryParse(value, out var result))
  23. {
  24. return result;
  25. }
  26. return result;
  27. }
  28. }
  29. }