示例#1
0
        public static UpStreamProxy DeSerializeToUpStream(string xml)
        {
            XmlSerializer ser = new XmlSerializer(typeof(UpStreamProxy));
            StringReader  stringReader;

            stringReader = new StringReader(xml);
            XmlTextReader xmlReader;

            xmlReader = new XmlTextReader(stringReader);
            UpStreamProxy configParams = (UpStreamProxy)ser.Deserialize(xmlReader);

            xmlReader.Close();
            stringReader.Close();

            return(configParams);
        }
示例#2
0
 public static bool ReadProxyConfig()
 {
     try
     {
         string pathOfConfigFile = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
         pathOfConfigFile = Path.Combine(pathOfConfigFile, "ProxyConfig.xml");
         string        text         = File.ReadAllText(pathOfConfigFile);
         UpStreamProxy tempUpStream = DeSerializeToUpStream(text);
         if (IsIPv4(tempUpStream.IPAddress))
         {
             if (tempUpStream.Port > 1 && tempUpStream.Port < 65535)
             {
                 ProxyConfig.UpStream = tempUpStream;
                 ProxyConfig.AssignWebProxy();
             }
         }
     }
     catch (Exception)
     {
         ProxyConfig.UpStream = null;
     }
     return(true);
 }