public static void InitPACServer(string address)
        {
            try
            {
                if (!pacList.ContainsKey(address))
                {
                    pacList.Add(address, GetPacList(address));
                }

                string prefixes = string.Format("http://{0}:{1}/pac/", address, Global.Settings.Pac_Port);

                HttpWebServer ws = new HttpWebServer(SendResponse, prefixes);
                ws.Run();

                if (!httpWebServer.ContainsKey(address) && ws != null)
                {
                    httpWebServer.Add(address, ws);
                }
                Global.Settings.Pac_Url = GetPacUrl();

                using var service = new ProxyService
                      {
                          AutoConfigUrl = Global.Settings.Pac_Url
                      };
                service.Pac();

                Logging.Info(service.Set(service.Query()) + "");
                Logging.Info($"Webserver InitServer OK: {Global.Settings.Pac_Url}");
            }
            catch (Exception ex)
            {
                Logging.Error("Webserver InitServer " + ex.Message);
            }
        }
        public void GlobalTest()
        {
            using var service = new ProxyService
                  {
                      Server = @"中文测试1919810",
                      Bypass = string.Join(@";", ProxyService.LanIp)
                  };
            var idn = new IdnMapping();
            var old = service.Query();

            try
            {
                Assert.IsTrue(service.Global());
                var status = service.Query();
                Assert.IsTrue(status.IsDirect);
                Assert.IsTrue(status.IsProxy);
                Assert.IsFalse(status.IsAutoProxyUrl);
                Assert.IsFalse(status.IsAutoDetect);
                Assert.AreEqual(idn.GetAscii(service.Server), status.ProxyServer);
                Assert.AreEqual(idn.GetAscii(service.Bypass), status.ProxyBypass);
            }
            finally
            {
                Assert.IsTrue(service.Set(old));
                Assert.AreEqual(old, service.Query());
            }
        }
        public void PacTest(string url)
        {
            using var service = new ProxyService
                  {
                      AutoConfigUrl = url
                  };
            var old = service.Query();
            var idn = new IdnMapping();

            try
            {
                Assert.IsTrue(service.Pac());
                var status = service.Query();
                Assert.IsTrue(status.IsDirect);
                Assert.IsFalse(status.IsProxy);
                Assert.IsTrue(status.IsAutoProxyUrl);
                Assert.IsFalse(status.IsAutoDetect);
                Assert.AreEqual(service.AutoConfigUrl.Replace(@"中文.cn", idn.GetAscii(@"中文.cn")), status.AutoConfigUrl);
            }
            finally
            {
                Assert.IsTrue(service.Set(old));
                Assert.AreEqual(old, service.Query());
            }
        }
 public static void Restore()
 {
     try
     {
         using var proxy = new ProxyService();
         proxy.Set(Old);
     }
     catch (Exception e)
     {
         Logging.LogUsefulException(e);
     }
 }
        public void DirectTest()
        {
            using var service = new ProxyService();
            var old = service.Query();

            try
            {
                Assert.IsTrue(service.Direct());
                var status = service.Query();
                Assert.IsTrue(status.IsDirect);
                Assert.IsFalse(status.IsProxy);
                Assert.IsFalse(status.IsAutoProxyUrl);
                Assert.IsTrue(status.IsAutoDetect);
            }
            finally
            {
                Assert.IsTrue(service.Set(old));
                Assert.AreEqual(old, service.Query());
            }
        }