You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

2 years ago
  1. using System;
  2. using System.Configuration;
  3. using System.IO;
  4. using System.Xml;
  5. namespace SqlSugar
  6. {
  7. public static class DBUnit
  8. {
  9. #region GetAppSettings
  10. /// <summary>
  11. /// 獲取WebService的配置信息
  12. /// </summary>
  13. /// <param name="sKey">todo: describe sKey parameter on GetAppSettings</param>
  14. /// <example></example>
  15. /// <returns>appSettings中配置的value值</returns>
  16. public static string GetAppSettings(string sKey)
  17. {
  18. var sVal = ConfigurationManager.AppSettings[sKey];
  19. return sVal ?? "";
  20. }
  21. #endregion GetAppSettings
  22. #region ConfigGetValue
  23. /// <summary>
  24. /// 读操作
  25. /// </summary>
  26. /// <param name="appKey"></param>
  27. /// <param name="sExecutablePath">todo: describe sExecutablePath parameter on ConfigGetValue</param>
  28. /// <returns></returns>
  29. public static string ConfigGetValue(string sExecutablePath, string appKey)
  30. {
  31. if (!Directory.Exists(sExecutablePath))
  32. {
  33. sExecutablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "");
  34. }
  35. var xDoc = new XmlDocument();
  36. try
  37. {
  38. xDoc.Load(sExecutablePath + "Web.config");
  39. XmlNode xNode;
  40. XmlElement xElem;
  41. xNode = xDoc.SelectSingleNode("//appSettings");
  42. xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
  43. if (xElem != null)
  44. return xElem.GetAttribute("value");
  45. else
  46. return "";
  47. }
  48. catch (Exception)
  49. {
  50. return "";
  51. }
  52. }
  53. #endregion ConfigGetValue
  54. }
  55. }