コード例 #1
0
        /// <summary>
        /// Reconstructs an icon formatting rule from the specified XML image.
        /// </summary>
        /// <param name="node">The node containing the icon formatting rule XML.</param>
        /// <returns>The icon formatting rule.</returns>
        private static IconFormattingRule ReadIconFormattingRuleXml(XmlNode node)
        {
            IconFormattingRule formattingRule = new IconFormattingRule();

            XmlNodeList ruleNodes = XmlHelper.SelectNodes(node, "iconFormattingRule/rules/rule");

            foreach (XmlNode ruleNode in ruleNodes)
            {
                IconRule rule = new IconRule();

                rule.Color     = ColorInfoHelper.ReadColorInfoXml(ruleNode, "color");
                rule.Condition = ConditionHelper.ReadConditionXml(ruleNode, "condition");
                rule.Icon      = (IconType)XmlHelper.ReadElementEnum(ruleNode, "icon", typeof(IconType), IconType.None);
                XmlNode iconIdNode = ruleNode.SelectSingleNode("iconId");
                if (iconIdNode != null)
                {
                    long iconId;
                    if (long.TryParse(iconIdNode.InnerText, out iconId))
                    {
                        rule.IconId = iconId;
                    }
                }
                rule.Scale = 1;
                formattingRule.Rules.Add(rule);
            }

            return(formattingRule);
        }
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <param name="index"></param>
        /// <param name="ifr1"></param>
        /// <param name="ifr2"></param>
        private static void CompareIconFormattingRules(int index, IconFormattingRule ifr1, IconFormattingRule ifr2)
        {
            Assert.IsNotNull(ifr1, "Format Index:{0} IconFormattingRule 1 should not be null.", index.ToString(CultureInfo.InvariantCulture));
            Assert.IsNotNull(ifr2, "Format Index:{0} IconFormattingRule 2 should not be null.", index.ToString(CultureInfo.InvariantCulture));

            Assert.IsNotNull(ifr1.Rules, "Format Index:{0} IconFormattingRule.Rules 1 should not be null.", index.ToString(CultureInfo.InvariantCulture));
            Assert.IsNotNull(ifr2.Rules, "Format Index:{0} IconFormattingRule.Rules 2 should not be null.", index.ToString(CultureInfo.InvariantCulture));

            Assert.AreEqual(ifr1.Rules.Count, ifr2.Rules.Count, "Format Index:{0} IconFormattingRule.Rules.Count is invalid.", index.ToString(CultureInfo.InvariantCulture));

            for (int ri = 0; ri < ifr1.Rules.Count; ri++)
            {
                IconRule ir1 = ifr1.Rules[ri];
                IconRule ir2 = ifr2.Rules[ri];

                Assert.AreEqual(ir1.Color.A, ir2.Color.A, "Format Index:{0} Rule Index:{1} Color.A is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual(ir1.Color.R, ir2.Color.R, "Format Index:{0} Rule Index:{1} Color.R is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual(ir1.Color.G, ir2.Color.G, "Format Index:{0} Rule Index:{1} Color.G is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual(ir1.Color.B, ir2.Color.B, "Format Index:{0} Rule Index:{1} Color.B is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));

                Assert.AreEqual(ir1.Icon, ir2.Icon, "Format Index:{0} Rule Index:{1} Icon is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));

                Assert.AreEqual(ir1.Condition.ColumnName, ir2.Condition.ColumnName, "Format Index:{0} Rule Index:{1} Condition.ColumnName is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual(ir1.Condition.ColumnType.GetType( ), ir2.Condition.ColumnType.GetType( ), "Format Index:{0} Rule Index:{1} Condition.ColumnType is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual(ir1.Condition.Operator, ir2.Condition.Operator, "Format Index:{0} Rule Index:{1} Condition.Operator is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));
                Assert.AreEqual(ir1.Condition.Arguments.Count, ir2.Condition.Arguments.Count, "Format Index:{0} Rule Index:{1} Condition.Arguments.Count is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture));

                for (int ti = 0; ti < ir1.Condition.Arguments.Count; ti++)
                {
                    TypedValue tv1 = ir1.Condition.Arguments[ti];
                    TypedValue tv2 = ir1.Condition.Arguments[ti];

                    Assert.AreEqual(tv1.Type, tv2.Type, "Format Index:{0} Rule Index:{1} Arg Index:{2} Argument.Type is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture), ti.ToString(CultureInfo.InvariantCulture));
                    Assert.AreEqual(tv1.Value, tv2.Value, "Format Index:{0} Rule Index:{1} Arg Index:{2} Argument.Value is invalid", index.ToString(CultureInfo.InvariantCulture), ri.ToString(CultureInfo.InvariantCulture), ti.ToString(CultureInfo.InvariantCulture));
                }
            }
        }