ApiConfig.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. File.AppendAllText("D:\\log.txt",m_AlgorithmUrl);
  31. }
  32. return m_AlgorithmUrl;
  33. }
  34. /// <summary>
  35. /// 获取配置文件
  36. /// </summary>
  37. /// <param name="key"></param>
  38. /// <returns></returns>
  39. public static string GetAppSettingsConfig(string key)
  40. {
  41. string codeBase = Assembly.GetExecutingAssembly().CodeBase;
  42. UriBuilder uri = new UriBuilder(codeBase);
  43. string path = Uri.UnescapeDataString(uri.Path);
  44. string addString = ConfigurationManager.OpenExeConfiguration(path).AppSettings.Settings[key].Value.ToString();
  45. return addString;
  46. }
  47. }
  48. }