Exemple #1
0
        // <summary>
        // Read properties to skip from PropertiesToSkip.xml. If this file
        // exists under the current working directory, use the one there.
        // Otherwise, use the file built in the ClientTestLibrary Assembly.
        // </summary>
        // <param name="fileName">Name of config file for specifying properties.</param>
        // <returns>Hashtable containing properties should be skiped</returns>
        public static Dictionary <string, PropertyToIgnore> ReadSkipProperties(string fileName)
        {
            Dictionary <string, PropertyToIgnore> PropertiesToSkip = new Dictionary <string, PropertyToIgnore>();

            //
            // Load PropertiesToSkip.xml document from assembly resources.
            //
            XmlDocument doc           = new XmlDocument();
            Stream      xmlFileStream = null;

            if (File.Exists(fileName))
            {
                TreeComparer.SendCompareMessage("Opening '" + fileName + "' from the current PartialTrustDirectory.");
                xmlFileStream = File.OpenRead(fileName);
            }
            else
            {
                TreeComparer.SendCompareMessage("Opening '" + fileName + "' from the Assembly.");
                Assembly asm = Assembly.GetAssembly(typeof(TreeComparer));
                xmlFileStream = asm.GetManifestResourceStream(fileName);

                if (xmlFileStream == null)
                {
                    return(PropertiesToSkip);
                }
            }

            try
            {
                StreamReader reader = new StreamReader(xmlFileStream);
                doc.LoadXml(reader.ReadToEnd());
            }
            finally
            {
                xmlFileStream.Close();
            }

            //
            // Store properties to skip in collection.
            //
            XmlNodeList properties = doc.GetElementsByTagName("PropertyToSkip");

            foreach (XmlNode property in properties)
            {
                string propertyName = TreeComparer.GetAttributeValue(property, "PropertyName");
                string ignore       = TreeComparer.GetAttributeValue(property, "Ignore");
                string owner        = TreeComparer.GetAttributeValue(property, "Owner");

                IgnoreProperty whatToIgnore;

                if (null == ignore || 0 == String.Compare(ignore, "ValueOnly"))
                {
                    whatToIgnore = IgnoreProperty.IgnoreValueOnly;
                }
                else if (0 == String.Compare(ignore, "NameAndValue"))
                {
                    whatToIgnore = IgnoreProperty.IgnoreNameAndValue;
                }
                else
                {
                    throw new Exception("'Ignore' attribute value not recognized: " + ignore);
                }

                PropertyToIgnore newItem = new PropertyToIgnore();

                newItem.WhatToIgnore = whatToIgnore;

                if (!String.IsNullOrEmpty(owner))
                {
                    newItem.Owner = owner;
                }

                if (PropertiesToSkip.ContainsKey(propertyName))
                {
                    SendCompareMessage(propertyName);
                }
                PropertiesToSkip.Add(propertyName + "___owner___" + owner, newItem);
            }

            return(PropertiesToSkip);
        }