public SymbolStyleModule GetSymbolModuleByName(SymbolType symbolType, string name)
        {
            string type = "symbols";

            switch (symbolType)
            {
            case SymbolType.Symbols:
                break;

            case SymbolType.Lines:
                type = "lines";
                break;

            case SymbolType.Patterns:
                type = "patterns";
                break;

            default:
                break;
            }

            IEnumerable <SymbolStyleModule> chartTablesList = chartTables.Where(x => x.Key == type && x.Value.Name == name).Select(x => x.Value.ChartStyleModules.Values).Cast <SymbolStyleModule>();
            SymbolStyleModule chartTable = chartTablesList.First();

            return(chartTable); // Todo: please implement it
        }
        private void UpdateSymbolTableEntry(ChartStyleModule chartStyleModule)
        {
            SymbolStyleModule module   = chartStyleModule as SymbolStyleModule;
            XDocument         document = XDocument.Load(resourceFile);
            XElement          element  = document.Root.XPathSelectElements("charts/symbols/symbol").Where(x => x.Attribute("rcid").Value == module.Rcid.ToString()).First();

            if (element != null)
            {
                element.SetElementValue("module", module.ModuleName);
                element.SetElementValue("pivotX", module.Pivot.X.ToString());
                element.SetElementValue("pivotY", module.Pivot.Y.ToString());
                element.SetElementValue("upperLeftX", module.UpperLeft.X.ToString());
                element.SetElementValue("upperLeftY", 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);
                }

                document.Save(resourceFile);
            }
        }
Esempio n. 3
0
        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);
        }