/// <summary>
        /// Log configuration from XmlDocument
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static List<NetworkConfiguration> FromXmlDocument(System.Xml.XmlDocument doc)
        {
            List<NetworkConfiguration> configurations = new List<NetworkConfiguration>();

            log.Debug("Loading configurations");

            // Chargement des règles
            foreach (System.Xml.XmlNode networkNode in doc.SelectNodes("/Networks/Network"))
            {
                NetworkRulesSet networkRulesSet = new NetworkRulesSet();
                ProxySettings proxySettings = null;

                networkRulesSet = ReadRules(networkNode.SelectNodes("Rules/*"));

                // Chargement des paramètres du configuration
                System.Xml.XmlNode proxyNode = networkNode.SelectSingleNode("Proxy");

                switch (proxyNode.Attributes["type"].Value)
                {
                    case "PacFile":
                        proxySettings = new ProxyPACSettings(proxyNode.Attributes["url"].Value);
                        break;

                    case "Standard":
                        bool? bypassLocal = proxyNode.Attributes["bypasslocal"] != null ? (bool?)bool.Parse(proxyNode.Attributes["bypasslocal"].Value) : null;
                        string exceptions = proxyNode.Attributes["exceptions"] != null ? proxyNode.Attributes["exceptions"].Value : null;
                        proxySettings = new StandardProxySettings(proxyNode.Attributes["url"].Value, exceptions, bypassLocal);
                        break;

                    case "None":
                        proxySettings = new NoProxySettings();
                        break;

                    default:
                        throw new Exception("Unknown Proxy type " + proxyNode.Attributes["type"].Value);
                }

                // Ajouter la configuration
                configurations.Add(new NetworkConfiguration(networkNode.Attributes["name"].Value, networkRulesSet, proxySettings));
            }

            log.DebugFormat("Configurations loaded: {0}", configurations.Count);

            return configurations;
        }
Esempio n. 2
0
        /// <summary>
        /// Log configuration from XmlDocument
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static List <NetworkConfiguration> FromXmlDocument(System.Xml.XmlDocument doc)
        {
            List <NetworkConfiguration> configurations = new List <NetworkConfiguration>();

            log.Debug("Loading configurations");

            // Chargement des règles
            foreach (System.Xml.XmlNode networkNode in doc.SelectNodes("/Networks/Network"))
            {
                NetworkRulesSet networkRulesSet = new NetworkRulesSet();
                ProxySettings   proxySettings   = null;

                networkRulesSet = ReadRules(networkNode.SelectNodes("Rules/*"));

                // Chargement des paramètres du configuration
                System.Xml.XmlNode proxyNode = networkNode.SelectSingleNode("Proxy");

                switch (proxyNode.Attributes["type"].Value)
                {
                case "PacFile":
                    proxySettings = new ProxyPACSettings(proxyNode.Attributes["url"].Value);
                    break;

                case "Standard":
                    bool?  bypassLocal = proxyNode.Attributes["bypasslocal"] != null ? (bool?)bool.Parse(proxyNode.Attributes["bypasslocal"].Value) : null;
                    string exceptions  = proxyNode.Attributes["exceptions"] != null ? proxyNode.Attributes["exceptions"].Value : null;
                    proxySettings = new StandardProxySettings(proxyNode.Attributes["url"].Value, exceptions, bypassLocal);
                    break;

                case "None":
                    proxySettings = new NoProxySettings();
                    break;

                default:
                    throw new Exception("Unknown Proxy type " + proxyNode.Attributes["type"].Value);
                }

                // Ajouter la configuration
                configurations.Add(new NetworkConfiguration(networkNode.Attributes["name"].Value, networkRulesSet, proxySettings));
            }

            log.DebugFormat("Configurations loaded: {0}", configurations.Count);

            return(configurations);
        }