public void UpdateLookupTableEntry(LookupTableType lookupTableType, LookupTableModule newLookupTableModule)
        {
            switch (lookupTableType)
            {
            case LookupTableType.LINES:
                UpdateLookupTableEntry("Lines", newLookupTableModule);
                break;

            case LookupTableType.PAPER_CHART:
                UpdateLookupTableEntry("PaperChart", newLookupTableModule);
                break;

            case LookupTableType.PLAIN_BOUNDARIES:
                UpdateLookupTableEntry("PlainBoundaries", newLookupTableModule);
                break;

            case LookupTableType.SIMPLIFIED:
                UpdateLookupTableEntry("Simplified", newLookupTableModule);
                break;

            case LookupTableType.SYMBOLIZED_BOUNDARIES:
                UpdateLookupTableEntry("SymbolizedBoundaries", newLookupTableModule);
                break;
            }
        }
Пример #2
0
        internal static Dictionary <LookupTableType, LookupTable> Read(XmlDocument doc)
        {
            // select "lookups" node
            Dictionary <LookupTableType, LookupTable> lookupTables = new Dictionary <LookupTableType, LookupTable>();

            XmlNode lookupsNode = doc.DocumentElement.SelectSingleNode("lookups");

            foreach (XmlNode lookupTableNode in lookupsNode.ChildNodes)
            {
                LookupTable lookupTable = new LookupTable()
                {
                    DrawnType = GetLookTableType(lookupTableNode.Attributes["name"].InnerText)
                };
                string shapeType = lookupTableNode.Attributes["shapeType"].InnerText;

                XmlNodeList lookups = lookupTableNode.SelectNodes("lookup");
                foreach (XmlNode lookup in lookups)
                {
                    LookupTableModule lookupModule = new LookupTableModule()
                    {
                        Rcid            = Convert.ToInt32(lookup.Attributes["rcid"].InnerText, CultureInfo.InvariantCulture),
                        ModuleName      = lookup.SelectSingleNode("module").InnerText,
                        ObjectClass     = lookup.SelectSingleNode("objectClass").InnerText,
                        DisplayType     = shapeType,
                        DisplayPriority = Convert.ToInt32(lookup.SelectSingleNode("displayPriority").InnerText, CultureInfo.InvariantCulture),
                        RadarPriority   = lookup.SelectSingleNode("radarPriority").InnerText[0],
                        DisplayCategory = lookup.Attributes["category"].InnerText
                    };

                    XmlNode attributesNode = lookup.SelectSingleNode("attributes");
                    if (attributesNode != null)
                    {
                        foreach (XmlNode attrNode in attributesNode.ChildNodes)
                        {
                            lookupModule.Attributes.Add(attrNode.Name, attrNode.InnerText);
                        }
                    }

                    XmlNode instructionsNode = lookup.SelectSingleNode("instructions");
                    if (instructionsNode != null)
                    {
                        foreach (XmlNode instrNode in instructionsNode.ChildNodes)
                        {
                            lookupModule.Instructions.Add(instrNode.InnerText);
                        }
                    }
                    lookupTable.LookupModules.Add(lookupModule);
                }

                lookupTables.Add(GetLookTableType(lookupTableNode.Attributes["name"].InnerText), lookupTable);
            }

            return(lookupTables);
        }
        private void UpdateLookupTableEntry(string type, LookupTableModule newLookupTableModule)
        {
            XDocument document = XDocument.Load(resourceFile);
            XElement  element  = document.Root.XPathSelectElements("lookups/" + type + "/lookup").Where(x => x.Attribute("rcid").Value.ToString() == newLookupTableModule.Rcid.ToString()).First();

            if (element != null)
            {
                element.Attribute("category").SetValue(newLookupTableModule.DisplayCategory);
                element.Element("objectClass").SetValue(newLookupTableModule.ObjectClass);
                element.Element("displayPriority").SetValue(newLookupTableModule.DisplayPriority.ToString());
                element.Element("radarPriority").SetValue(newLookupTableModule.RadarPriority.ToString());
                element.Element("module").SetValue(newLookupTableModule.ModuleName);
                element.XPathSelectElements("instructions/instr").Remove();
                XElement instructionsElement = element.Element("instructions");
                foreach (var item in newLookupTableModule.Instructions)
                {
                    XElement xElement = new XElement("instr");
                    xElement.SetValue(item);
                    instructionsElement.Add(xElement);
                }

                XElement attributesElement = element.Element("attributes");
                if (newLookupTableModule.Attributes.Count > 0)
                {
                    if (attributesElement == null)
                    {
                        element.Add(new XElement("attributes"));
                    }
                    else
                    {
                        attributesElement.Elements().Remove();
                    }

                    attributesElement = element.Element("attributes");

                    foreach (var item in newLookupTableModule.Attributes)
                    {
                        attributesElement.Add(new XElement(item.Key, item.Value));
                    }
                }
                document.Save(resourceFile);
            }
        }