public static XHeaderRule[] Load()
        {
            string path = Assembly.GetExecutingAssembly().Location;

            path = Path.GetDirectoryName(path);
            path = Path.Combine(path, "configuration.xml");
            XmlSerializer serializer = new XmlSerializer(typeof(XHeaderAgentConfiguration));

            XHeaderAgentConfiguration configuration = null;

            // Deserialize the rules.
            try
            {
                Debug.WriteLine("Reading rules from " + path);
                using (Stream stream = File.OpenRead(path))
                {
                    configuration = serializer.Deserialize(stream) as XHeaderAgentConfiguration;
                }
            }
            catch (System.IO.IOException ex)
            {
                // File not found, or cannot be opened.
                Debug.WriteLine(ex.ToString());
            }
            catch (System.Xml.XmlException ex)
            {
                // Malformed XML.
                Debug.WriteLine(ex.ToString());
            }
            catch (System.InvalidOperationException ex)
            {
                // Failed conversion from XML text to enumeration constant.
                Debug.WriteLine(ex.ToString());
            }

            // If the configuration was not loaded, return an empty rule collection.
            if ((null == configuration) || (null == configuration.Rules))
            {
                return(new XHeaderRule[0]);
            }

            return(configuration.Rules);
        }
Ejemplo n.º 2
0
 static XHeaderAgent()
 {
     rules = XHeaderAgentConfiguration.Load();
 }