/*-------------------------------------------------------------------------
 * 功能描述：ApiConfig
 * 作者：xulisong
 * 创建时间： 2019/7/30 10:14:55
 * 版本号：v1.0
 *  -------------------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace MBIRevitBase.Config
{
    public class ApiConfig
    {
        public static string m_AlgorithmUrl;

        public static string AlgorithmUrl()
        {
            if (string.IsNullOrWhiteSpace(m_AlgorithmUrl))
            {
                string ip=GetAppSettingsConfig("IP");
                string port= GetAppSettingsConfig("Port");
                //string ip = "http://192.168.20.225";
                //string port = "8082";
                string path = ApiConfig.GetAppSettingsConfig("Path");
                m_AlgorithmUrl = $"{ip}:{port}{path}";
            }

            return m_AlgorithmUrl;
        }

        /// <summary>
        /// 获取配置文件
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetAppSettingsConfig(string key)
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            string addString = ConfigurationManager.OpenExeConfiguration(path).AppSettings.Settings[key].Value.ToString();

            return addString;
        }
    }
}
