Example #1
0
        // <summary>
        //  Shoud ignore this property?
        // </summary>
        // <param name="propertyName">property name</param>
        // <param name="owner">owner</param>
        // <param name="whatToIgnore">Valueonly or Value and name to ignore?</param>
        // <returns></returns>
        private static bool ShouldIgnoreProperty(string propertyName, object owner, IgnoreProperty whatToIgnore)
        {
            PropertyToIgnore property = null;

            foreach (string key in TreeComparer._skipProperties.Keys)
            {
                if (String.Equals(key, propertyName, StringComparison.InvariantCulture) ||
                    key.StartsWith(propertyName + "___owner___"))
                {
                    property = TreeComparer._skipProperties[key];
                    if (whatToIgnore == property.WhatToIgnore && ((null == property.Owner) || TreeComparer._DoesTypeMatch(owner.GetType(), property.Owner)))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #2
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);
        }