ApiConfig.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ApiConfig
  3. * 作者:xulisong
  4. * 创建时间: 2019/7/30 10:14:55
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace MBIRevitBase.Config
  16. {
  17. public class ApiConfig
  18. {
  19. public static string m_AlgorithmUrl;
  20. public static string AlgorithmUrl()
  21. {
  22. if (string.IsNullOrWhiteSpace(m_AlgorithmUrl))
  23. {
  24. string ip=GetAppSettingsConfig("IP");
  25. string port= GetAppSettingsConfig("Port");
  26. //string ip = "http://192.168.20.225";
  27. //string port = "8082";
  28. string path = ApiConfig.GetAppSettingsConfig("Path");
  29. m_AlgorithmUrl = $"{ip}:{port}{path}";
  30. }
  31. return m_AlgorithmUrl;
  32. }
  33. /// <summary>
  34. /// 获取配置文件
  35. /// </summary>
  36. /// <param name="key"></param>
  37. /// <returns></returns>
  38. public static string GetAppSettingsConfig(string key)
  39. {
  40. string codeBase = Assembly.GetExecutingAssembly().CodeBase;
  41. UriBuilder uri = new UriBuilder(codeBase);
  42. string path = Uri.UnescapeDataString(uri.Path);
  43. string addString = ConfigurationManager.OpenExeConfiguration(path).AppSettings.Settings[key].Value.ToString();
  44. return addString;
  45. }
  46. }
  47. }