private void UpdatePatternTableEntry(ChartStyleModule chartStyleModule) { PatternStyleModule module = chartStyleModule as PatternStyleModule; XDocument document = XDocument.Load(resourceFile); XElement element = document.Root.XPathSelectElements("charts/patterns/patternSymbol").Where(x => x.Attribute("rcid").Value.ToString() == module.Rcid.ToString()).First(); if (element != null) { element.SetElementValue("module", module.ModuleName); element.XPathSelectElement("geometry/pivotX").SetValue(module.Pivot.X.ToString()); element.XPathSelectElement("geometry/pivotY").SetValue(module.Pivot.Y.ToString()); element.XPathSelectElement("geometry/upperLeftX").SetValue(module.UpperLeft.X.ToString()); element.XPathSelectElement("geometry/upperLeftY").SetValue(module.UpperLeft.Y.ToString()); element.XPathSelectElements("colorRefs/colorRef").Remove(); XElement colorRefsElement = element.Element("colorRefs"); foreach (var item in module.ColorReferences) { XElement xElement = new XElement("colorRef"); XAttribute indexAttr = new XAttribute("index", item.Key); XAttribute tokenAttr = new XAttribute("token", item.Value); xElement.Add(indexAttr); xElement.Add(tokenAttr); colorRefsElement.Add(xElement); } element.XPathSelectElements("commands/command").Remove(); XElement commandsElement = element.Element("commands"); foreach (var item in module.Commands) { XElement commandElement = new XElement("command", item); commandsElement.Add(commandElement); } element.Element("fillType").SetValue(module.FillType); element.Element("spacingType").SetValue(module.SymbolSpacingType); element.Element("minimumDistance").SetValue(module.MinDistance.ToString()); element.Element("maximumDistance").SetValue(module.MaxDistance.ToString()); document.Save(resourceFile); } }
internal static Dictionary <string, ChartTable> Read(XmlDocument doc) { Dictionary <string, ChartTable> chartTables = new Dictionary <string, ChartTable>(); // select "charts" node XmlNode chartsNode = doc.DocumentElement.SelectSingleNode("charts"); foreach (XmlNode chartTablesNode in chartsNode.ChildNodes) { ChartTable chartTable = new ChartTable(); chartTable.Name = chartTablesNode.Name; foreach (XmlNode chartTableNode in chartTablesNode.ChildNodes) { ChartStyleModule styleModule = null; switch (chartTable.Name) { case "symbols": styleModule = new SymbolStyleModule() { CommandType = chartTableNode.Attributes["type"].Value[0] }; break; case "lines": styleModule = new LineStyleModule(); break; case "patterns": styleModule = new PatternStyleModule() { CommandType = chartTableNode.Attributes["type"].Value[0], FillType = chartTableNode.SelectSingleNode("fillType").InnerText, SymbolSpacingType = chartTableNode.SelectSingleNode("spacingType").InnerText, MinDistance = Convert.ToInt32(chartTableNode.SelectSingleNode("minimumDistance").InnerText, CultureInfo.InvariantCulture), MaxDistance = Convert.ToInt32(chartTableNode.SelectSingleNode("maximumDistance").InnerText, CultureInfo.InvariantCulture) }; break; default: break; } styleModule.ModuleName = chartTableNode.SelectSingleNode("module").InnerText; styleModule.Rcid = Convert.ToInt32(chartTableNode.Attributes["rcid"].Value, CultureInfo.InvariantCulture); styleModule.Name = chartTableNode.Attributes["name"].Value; // Information related to geometry XmlNode geoNode = chartTableNode.SelectSingleNode("geometry"); styleModule.BoundingBox = new Size(Convert.ToInt32(geoNode.Attributes["width"].Value, CultureInfo.InvariantCulture), Convert.ToInt32(geoNode.Attributes["height"].Value, CultureInfo.InvariantCulture)); styleModule.Pivot = new Point(Convert.ToInt32(geoNode.SelectSingleNode("pivotX").InnerText, CultureInfo.InvariantCulture), Convert.ToInt32(geoNode.SelectSingleNode("pivotY").InnerText, CultureInfo.InvariantCulture)); styleModule.UpperLeft = new Point(Convert.ToInt32(geoNode.SelectSingleNode("upperLeftX").InnerText, CultureInfo.InvariantCulture), Convert.ToInt32(geoNode.SelectSingleNode("upperLeftY").InnerText, CultureInfo.InvariantCulture)); XmlNode colorRefsNode = chartTableNode.SelectSingleNode("colorRefs"); if (colorRefsNode != null) { foreach (XmlNode colorRefNode in colorRefsNode.ChildNodes) { styleModule.ColorReferences.Add(colorRefNode.Attributes["index"].Value[0], colorRefNode.Attributes["token"].Value); } } XmlNode commandsNode = chartTableNode.SelectSingleNode("commands"); if (commandsNode != null) { foreach (XmlNode commandNode in commandsNode.ChildNodes) { styleModule.Commands.Add(commandNode.InnerText); } } chartTable.ChartStyleModules.Add(styleModule.Name, styleModule); } chartTables.Add(chartTable.Name, chartTable); } return(chartTables); }