Beispiel #1
0
        /// <summary>
        ///     获取网络配置
        /// </summary>
        public static void GetNetConfig()
        {
            #region Config

            string          url    = "https://gitee.com/yangd4/ph/raw/master/Config.json";
            ProxyHeroEntity result = GetConfig(url);


            if (result.Sites == null || result.Sites.Length == 0)
            {
                Config.InitErrorInfo = Config.LocalLanguage.Messages.InitializeFailed;
                throw new Exception(Config.InitErrorInfo);
            }

            Config.ProxyHeroCloudSetting = result;

            if (Config.ProxyHeroCloudSetting == null)
            {
                Config.InitErrorInfo = Config.LocalLanguage.Messages.InitializeFailed;
                throw new Exception(Config.InitErrorInfo);
            }

            #endregion

            #region get proxyPageList


            for (int i = 0; i < result.Sites.Length; i++)
            {
                Config.ProxySiteUrlList.Add(result.Sites[i]);
            }

            #endregion
        }
Beispiel #2
0
        private static ProxyHeroEntity GetConfig(string url)
        {
            var result = new ProxyHeroEntity();

            try
            {
                var httpHelper = new HttpHelper();

                string html;

                if (Config.LocalSetting.IsUseSystemProxy)
                {
                    httpHelper.IsUseDefaultProxy = true;
                    html = httpHelper.GetHtml(url, Encoding.GetEncoding("UTF-8"));
                }
                else
                {
                    httpHelper.IsUseDefaultProxy = false;
                    html = httpHelper.GetHtml(url, Encoding.GetEncoding("UTF-8"));
                }

                ProxyHeroEntity proxyHeroEntity = JsonHelper.JsonToModel <ProxyHeroEntity>(html);

                result = proxyHeroEntity;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex, "初始化配置异常");
            }

            return(result);
        }