public void UpdateColorEntry(NauticalChartsDefaultColorSchema colorSchema, ColorEntry newColorEntry) { XDocument document = XDocument.Load(resourceFile); XElement element = document.Root.XPathSelectElements("ColorSchemas/" + colorSchema.ToString().ToUpperInvariant() + "/Color").Where(x => x.Attribute("token").Value.ToString() == newColorEntry.Token).First(); if (element != null) { element.Attribute("r").SetValue(newColorEntry.Color.RedComponent); element.Attribute("g").SetValue(newColorEntry.Color.GreenComponent); element.Attribute("b").SetValue(newColorEntry.Color.BlueComponent); document.Save(resourceFile); } }
internal static Dictionary <NauticalChartsDefaultColorSchema, ColorTable> Read(XmlDocument doc) { Dictionary <NauticalChartsDefaultColorSchema, ColorTable> colorTables = new Dictionary <NauticalChartsDefaultColorSchema, ColorTable>(); XmlNode colorsNode = doc.DocumentElement.SelectSingleNode(@"ColorSchemas"); foreach (XmlNode colorTableNode in colorsNode.ChildNodes) { ColorTable colorTable = new ColorTable(colorTableNode.Attributes["name"].Value); NauticalChartsDefaultColorSchema colorSchema = (NauticalChartsDefaultColorSchema)Enum.Parse(typeof(NauticalChartsDefaultColorSchema), colorTableNode.Attributes["name"].Value, true); Collection <ColorEntry> colorEntries = new Collection <ColorEntry>(); foreach (XmlNode colorEntryNode in colorTableNode.ChildNodes) { ColorEntry colorEntry = new ColorEntry(colorEntryNode.Attributes["token"].Value, short.Parse(colorEntryNode.Attributes["r"].Value), short.Parse(colorEntryNode.Attributes["g"].Value), short.Parse(colorEntryNode.Attributes["b"].Value)); colorEntries.Add(colorEntry); } colorTable.ColorEntries = colorEntries; colorTables.Add(colorSchema, colorTable); } return(colorTables); }