Read() public method

Read to next content node.
public Read ( ) : bool
return bool
Esempio n. 1
0
        /// <summary>
        /// Load the entire state of the event DB from a file.
        /// </summary>
        public void Load(string filename)
        {
            using (XmlInput xmlinput = new XmlInput(filename)) {
                xmlinput.CheckElement(rootElement);
                xmlinput.Read();

                eventStore.Load(xmlinput);
                controlPointStore.Load(xmlinput);
                courseStore.Load(xmlinput);
                courseControlStore.Load(xmlinput);
                legStore.Load(xmlinput);
                specialStore.Load(xmlinput);

                // Fix backward compatibility issues.
                FixCourseSortOrders();
                FixControlPointGaps();
                FixPrintAreas();
            }
        }
Esempio n. 2
0
        public override void ReadAttributesAndContent(XmlInput xmlinput)
        {
            firstControlCode = 31;
            disallowInvertibleCodes = true;
            courseAppearance.purpleColorBlend = false; // default for existing events is false, true for new events.
            printArea = null;  // Will be set at end if not loaded.

            bool first = true;
            while (xmlinput.FindSubElement(first, "title", "notes", "map", "all-controls", "numbering", "punch-card", "course-appearance", "print-area", "descriptions", "ocad", "custom-symbol-text")) {
                switch (xmlinput.Name) {
                    case "title":
                        title = xmlinput.GetContentString();
                        break;

                    case "notes":
                        notes = xmlinput.GetContentString();
                        break;

                    case "map":
                        mapScale = xmlinput.GetAttributeFloat("scale");

                        string kindString = xmlinput.GetAttributeString("kind");
                        switch (kindString) {
                            case "none": mapType = MapType.None; break;
                            case "OCAD": mapType = MapType.OCAD; break;
                            case "bitmap": mapType = MapType.Bitmap; break;
                            case "PDF": mapType = MapType.PDF; break;
                            default: xmlinput.BadXml("Invalid map kind '{0}'", kindString); break;
                        }

                        if (mapType == MapType.Bitmap)
                            mapDpi = xmlinput.GetAttributeFloat("dpi");
                        else
                            mapDpi = 0;

                        if (mapType == MapType.OCAD)
                            ignoreMissingFonts = xmlinput.GetAttributeBool("ignore-missing-fonts", false);

                        if (mapType != MapType.None) {
                            mapFileName = xmlinput.GetContentString();
                            mapFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(xmlinput.FileName), mapFileName)); // file name is relative to the XML file
                        }
                        else {
                            mapFileName = null;
                            xmlinput.Skip();
                        }

                        break;

                    case "all-controls":
                        allControlsPrintScale = xmlinput.GetAttributeFloat("print-scale", 0);
                        allControlsDescKind = EventDBUtil.ReadDescriptionKindAttribute(xmlinput);
                        xmlinput.Skip();
                        break;

                    case "numbering":
                        firstControlCode = xmlinput.GetAttributeInt("start", 31);
                        disallowInvertibleCodes = xmlinput.GetAttributeBool("disallow-invertible", true);
                        xmlinput.Skip();
                        break;

                    case "punch-card":
                        punchcardFormat.boxesDown = xmlinput.GetAttributeInt("rows", PunchcardAppearance.defaultBoxesDown);
                        punchcardFormat.boxesAcross = xmlinput.GetAttributeInt("columns", PunchcardAppearance.defaultBoxesAcross);
                        punchcardFormat.leftToRight = xmlinput.GetAttributeBool("left-to-right", PunchcardAppearance.defaultLeftToRight);
                        punchcardFormat.topToBottom = xmlinput.GetAttributeBool("top-to-bottom", PunchcardAppearance.defaultTopToBottom);
                        xmlinput.Skip();
                        break;

                    case "course-appearance":
                        courseAppearance.controlCircleSize = xmlinput.GetAttributeFloat("control-circle-size-ratio", 1.0F);
                        courseAppearance.lineWidth = xmlinput.GetAttributeFloat("line-width-ratio", 1.0F);
                        courseAppearance.centerDotDiameter = xmlinput.GetAttributeFloat("center-dot-diameter", 0.0F);
                        courseAppearance.numberHeight = xmlinput.GetAttributeFloat("number-size-ratio", 1.0F);
                        courseAppearance.numberBold = xmlinput.GetAttributeBool("number-bold", false);
                        courseAppearance.numberOutlineWidth = xmlinput.GetAttributeFloat("number-outline-width", 0.0F);
                        courseAppearance.autoLegGapSize = xmlinput.GetAttributeFloat("auto-leg-gap-size", 3.5F);  // default value
                        courseAppearance.purpleColorBlend = xmlinput.GetAttributeBool("blend-purple", false);
                        courseAppearance.purpleC = xmlinput.GetAttributeFloat("purple-cyan", -1F);
                        courseAppearance.purpleM = xmlinput.GetAttributeFloat("purple-magenta", -1F);
                        courseAppearance.purpleY = xmlinput.GetAttributeFloat("purple-yellow", -1F);
                        courseAppearance.purpleK = xmlinput.GetAttributeFloat("purple-black", -1F);
                        if (courseAppearance.purpleC < 0 || courseAppearance.purpleM < 0 || courseAppearance.purpleY < 0 || courseAppearance.purpleK < 0) {
                            courseAppearance.useDefaultPurple = true;
                            courseAppearance.purpleC = courseAppearance.purpleM = courseAppearance.purpleY = courseAppearance.purpleK = 1;
                        }
                        else {
                            courseAppearance.useDefaultPurple = false;
                        }

                        xmlinput.Skip();
                        break;

                    case "print-area":
                        printArea = new PrintArea();
                        printArea.ReadAttributesAndContent(xmlinput);
                        break;

                    case "descriptions":
                        descriptionLangId = xmlinput.GetAttributeString("lang");

                        string descriptionColor = xmlinput.GetAttributeString("color", "black");
                        if (descriptionColor.Equals("purple", StringComparison.InvariantCultureIgnoreCase))
                            courseAppearance.descriptionsPurple = true;
                        else
                            courseAppearance.descriptionsPurple = false;

                        xmlinput.Skip();
                        break;

                    case "ocad":
                        courseAppearance.useOcadOverprint = xmlinput.GetAttributeBool("overprint-colors", false);
                        xmlinput.Skip();
                        break;

                    case "custom-symbol-text":
                        string iof2004id = xmlinput.GetAttributeString("iof-2004-ref");
                        bool key = xmlinput.GetAttributeBool("show-key", false);
                        customSymbolKey[iof2004id] = key;
                        xmlinput.Read();
                        xmlinput.MoveToContent();

                        List<SymbolText> texts = new List<SymbolText>();
                        if (xmlinput.Reader.NodeType == XmlNodeType.Text) {
                            // Reading the old-style custom symbol text.
                            string customText = xmlinput.Reader.ReadString();
                            if (iof2004id.StartsWith("8.", StringComparison.InvariantCulture))
                                customText += " {0}";     // old style for modifiers didn't have the fill-in placeholder.
                            SymbolText text = new SymbolText();
                            text.Lang = "en";
                            text.Plural = false;
                            text.Gender = "";
                            text.Text = customText;
                            texts.Add(text);
                        }
                        else {
                            // Read the new-style custom symbol text.
                            while (xmlinput.Reader.NodeType == XmlNodeType.Element && xmlinput.Name == "text") {
                                SymbolText text = new SymbolText();
                                text.ReadXml(xmlinput);
                                texts.Add(text);
                                xmlinput.Skip();
                            }
                        }
                        
                        customSymbolText[iof2004id] = texts;
                        xmlinput.Skip();
                        break;
                        
                }

                first = false;
            }

            if (allControlsPrintScale == 0)
                allControlsPrintScale = mapScale;

            float scaleRatio;
            if (mapScale > 0 && allControlsPrintScale > 0)
                scaleRatio = allControlsPrintScale / mapScale;
            else
                scaleRatio = 1.0F;

            if (printArea == null) {
                printArea = MapUtil.GetDefaultPrintArea(mapFileName, scaleRatio);
            }
        }