/// <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); }
public void ReadColorInfoXmlNullElementNameTest( ) { var doc = new XmlDocument( ); doc.LoadXml("<xml></xml>"); ColorInfoHelper.ReadColorInfoXml(doc.DocumentElement, null); }
public void ReadColorInfoXmlEmptyElemementNameTest( ) { var doc = new XmlDocument( ); doc.LoadXml("<xml></xml>"); ColorInfoHelper.ReadColorInfoXml(doc.DocumentElement, string.Empty); }
/// <summary> /// Writes the icon formatting rule to the specified XML writer. /// </summary> /// <param name="iconFormattingRule">The icon formatting rule to serialize.</param> /// <param name="xmlWriter">The XML writer used to write the image to.</param> private static void WriteIconFormattingRuleXml(IconFormattingRule iconFormattingRule, XmlWriter xmlWriter) { xmlWriter.WriteStartElement("iconFormattingRule"); xmlWriter.WriteStartElement("rules"); foreach (IconRule rule in iconFormattingRule.Rules) { xmlWriter.WriteStartElement("rule"); ColorInfoHelper.WriteColorInfoXml("color", rule.Color, xmlWriter); xmlWriter.WriteElementString("icon", rule.Icon.ToString()); ConditionHelper.WriteConditionXml("condition", rule.Condition, xmlWriter); // Write out the Icon ID if (rule.IconId.HasValue) { xmlWriter.WriteStartElement("iconId"); xmlWriter.WriteAttributeString("entityRef", "true"); xmlWriter.WriteString(rule.IconId.Value.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); // rule } xmlWriter.WriteEndElement(); // rules xmlWriter.WriteEndElement(); // iconFormattingRule }
public void WriteColorInfoXmlEmptyElementNameTest( ) { var writerText = new StringBuilder( ); XmlWriter writer = XmlWriter.Create(writerText, new XmlWriterSettings { OmitXmlDeclaration = true }); ColorInfoHelper.WriteColorInfoXml(string.Empty, new ColorInfo( ), writer); }
public void WriteColorInfoXmlNullColorInfoTest( ) { var writerText = new StringBuilder( ); XmlWriter writer = XmlWriter.Create(writerText, new XmlWriterSettings { OmitXmlDeclaration = true }); ColorInfoHelper.WriteColorInfoXml("color", null, writer); }
/// <summary> /// Writes the bar formatting rule to the specified XML writer. /// </summary> /// <param name="barFormattingRule">The bar formatting rule to serialize.</param> /// <param name="xmlWriter">The XML writer used to write the image to.</param> private static void WriteBarFormattingRuleXml(BarFormattingRule barFormattingRule, XmlWriter xmlWriter) { xmlWriter.WriteStartElement("barFormattingRule"); ColorInfoHelper.WriteColorInfoXml("color", barFormattingRule.Color, xmlWriter); TypedValueHelper.WriteTypedValueXml("minimum", barFormattingRule.Minimum, xmlWriter); TypedValueHelper.WriteTypedValueXml("maximum", barFormattingRule.Maximum, xmlWriter); xmlWriter.WriteEndElement(); // barFormattingRule }
public void ReadColorInfoXmlInvalidXmlTest( ) { var doc = new XmlDocument( ); doc.LoadXml("<xml><color></color></xml>"); ColorInfo color = ColorInfoHelper.ReadColorInfoXml(doc.DocumentElement, "color"); Assert.AreEqual(0, color.A, "The value of Color.A is invalid."); Assert.AreEqual(0, color.R, "The value of Color.R is invalid."); Assert.AreEqual(0, color.G, "The value of Color.G is invalid."); Assert.AreEqual(0, color.B, "The value of Color.B is invalid."); }
/// <summary> /// Reconstructs a bar formatting rule from the specified XML image. /// </summary> /// <param name="node">The node containing the bar formatting rule XML.</param> /// <returns>The bar formatting rule.</returns> private static BarFormattingRule ReadBarFormattingRuleXml(XmlNode node) { BarFormattingRule formattingRule = new BarFormattingRule(); if (XmlHelper.EvaluateSingleNode(node, "barFormattingRule")) { XmlNode barFormattingRuleNode = XmlHelper.SelectSingleNode(node, "barFormattingRule"); if (barFormattingRuleNode != null) { formattingRule.Color = ColorInfoHelper.ReadColorInfoXml(barFormattingRuleNode, "color"); formattingRule.Minimum = TypedValueHelper.ReadTypedValueXml(barFormattingRuleNode, "minimum"); formattingRule.Maximum = TypedValueHelper.ReadTypedValueXml(barFormattingRuleNode, "maximum"); } } return(formattingRule); }
/// <summary> /// Writes the color formatting rule to the specified XML writer. /// </summary> /// <param name="colorFormattingRule">The color formatting rule to serialize.</param> /// <param name="xmlWriter">The XML writer used to write the image to.</param> private static void WriteColorFormattingRuleXml(ColorFormattingRule colorFormattingRule, XmlWriter xmlWriter) { xmlWriter.WriteStartElement("colorFormattingRule"); xmlWriter.WriteStartElement("rules"); foreach (ColorRule rule in colorFormattingRule.Rules) { xmlWriter.WriteStartElement("rule"); ColorInfoHelper.WriteColorInfoXml("backgroundColor", rule.BackgroundColor, xmlWriter); ColorInfoHelper.WriteColorInfoXml("foregroundColor", rule.ForegroundColor, xmlWriter); ConditionHelper.WriteConditionXml("condition", rule.Condition, xmlWriter); xmlWriter.WriteEndElement(); // rule } xmlWriter.WriteEndElement(); // rules xmlWriter.WriteEndElement(); // colorFormattingRule }
/// <summary> /// Reconstructs a color formatting rule from the specified XML image. /// </summary> /// <param name="node">The node containing the color formatting rule XML.</param> /// <returns>The color formatting rule.</returns> private static ColorFormattingRule ReadColorFormattingRuleXml(XmlNode node) { ColorFormattingRule formattingRule = new ColorFormattingRule(); XmlNodeList ruleNodes = XmlHelper.SelectNodes(node, "colorFormattingRule/rules/rule"); foreach (XmlNode ruleNode in ruleNodes) { ColorRule rule = new ColorRule(); rule.BackgroundColor = ColorInfoHelper.ReadColorInfoXml(ruleNode, "backgroundColor"); rule.ForegroundColor = ColorInfoHelper.ReadColorInfoXml(ruleNode, "foregroundColor"); rule.Condition = ConditionHelper.ReadConditionXml(ruleNode, "condition"); formattingRule.Rules.Add(rule); } return(formattingRule); }
public void ReadColorInfoXmlNullNodeTest( ) { ColorInfoHelper.ReadColorInfoXml(null, "color"); }
public void WriteColorInfoXmlNullXmlWriterTest( ) { ColorInfoHelper.WriteColorInfoXml("color", new ColorInfo( ), null); }