CheckElement() public method

Check that we're at the given element name.
public CheckElement ( string elementName ) : void
elementName string
return void
Beispiel #1
0
        // Read the state of this language from XML.
        public void ReadXml(XmlInput xmlinput)
        {
            xmlinput.CheckElement("language");

            this.LangId          = xmlinput.GetAttributeString("lang");
            this.PluralNouns     = xmlinput.GetAttributeBool("plural-nouns", false);
            this.PluralModifiers = xmlinput.GetAttributeBool("plural-modifiers", false);
            this.GenderModifiers = xmlinput.GetAttributeBool("gender-modifiers", false);
            this.CaseModifiers   = xmlinput.GetAttributeBool("case-modifiers", false);

            string genders = xmlinput.GetAttributeString("genders", "");

            if (genders != "")
            {
                this.Genders = genders.Split(new char[] { ',' });
            }

            string cases = xmlinput.GetAttributeString("cases", "");

            if (cases != "")
            {
                this.Cases = cases.Split(new char[] { ',' });
            }

            this.Name = xmlinput.GetContentString();
        }
Beispiel #2
0
        private void ReadSymbolFile(string filename)
        {
            int sortOrder = 1;

            using (XmlInput xmlinput = new XmlInput(filename)) {
                xmlinput.CheckElement("symbols");

                bool first = true;
                while (xmlinput.FindSubElement(first, new string[] { "symbol", "language" }))
                {
                    if (xmlinput.Name == "symbol")
                    {
                        Symbol symbol = new Symbol(this, sortOrder);
                        ++sortOrder;

                        symbol.ReadXml(xmlinput);

                        if (symbols.ContainsKey(symbol.Id))
                        {
                            symbols[symbol.Id].Add(symbol);
                        }
                        else
                        {
                            symbols[symbol.Id] = new List <Symbol>()
                            {
                                symbol
                            };
                        }
                    }
                    else if (xmlinput.Name == "language")
                    {
                        SymbolLanguage language = new SymbolLanguage();

                        language.ReadXml(xmlinput);
                        languages.Add(language.LangId, language);
                    }

                    first = false;
                }
            }
        }
Beispiel #3
0
        private void ReadSymbolFile(string filename)
        {
            using (XmlInput xmlinput = new XmlInput(filename)) {
                xmlinput.CheckElement("symbols");

                bool first = true;
                while (xmlinput.FindSubElement(first, new string[] { "symbol", "language" })) {
                    if (xmlinput.Name == "symbol") {
                        Symbol symbol = new Symbol(this);

                        symbol.ReadXml(xmlinput);

                        symbols.Add(symbol.Id, symbol);
                    }
                    else if (xmlinput.Name == "language") {
                        SymbolLanguage language = new SymbolLanguage();

                        language.ReadXml(xmlinput);
                        languages.Add(language.LangId, language);
                    }

                    first = false;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Read the state of this symbol from XML. The xmlinput must be on a 
        /// symbol node.
        /// </summary>
        public void ReadXml(XmlInput xmlinput)
        {
            xmlinput.CheckElement("symbol");

            this.kind = xmlinput.GetAttributeString("kind")[0];
            this.id = xmlinput.GetAttributeString("id");
            this.sizeIsDepth = xmlinput.GetAttributeBool("size-is-depth", false);

            bool first = true;
            List<SymbolStroke> strokes = new List<SymbolStroke>();

            while (xmlinput.FindSubElement(first, new string[] { "name", "text", "filled-circle", "circle", "polygon", "filled-polygon", "lines", "beziers", "filled-beziers" })) {
                SymbolStroke stroke = new SymbolStroke();
                bool isStroke = true;

                switch (xmlinput.Name) {
                    case "name":
                        xmlinput.CheckElement("name");
                        string language = xmlinput.GetAttributeString("lang");
                        name.Add(language, xmlinput.GetContentString());
                        isStroke = false;
                        break;

                    case "text":
                        xmlinput.CheckElement("text");
                        SymbolText symtext = new SymbolText();
                        symtext.ReadXml(xmlinput);
                        texts.Add(symtext);
                        isStroke = false;
                        break;

                    case "filled-circle":
                        xmlinput.CheckElement("filled-circle");
                        stroke.kind = SymbolStrokes.Disc;
                        stroke.radius = xmlinput.GetAttributeFloat("radius");
                        break;

                    case "circle":
                        xmlinput.CheckElement("circle");
                        stroke.kind = SymbolStrokes.Circle;
                        stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                        stroke.radius = xmlinput.GetAttributeFloat("radius");
                        break;

                    case "polygon":
                        xmlinput.CheckElement("polygon");
                        stroke.kind = SymbolStrokes.Polygon;
                        stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                        stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput);
                        break;

                    case "filled-polygon":
                        xmlinput.CheckElement("filled-polygon");
                        stroke.kind = SymbolStrokes.FilledPolygon;
                        break;

                    case "lines":
                        xmlinput.CheckElement("lines");
                        stroke.kind = SymbolStrokes.Polyline;
                        stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                        stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput);
                        stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput);
                        break;

                    case "beziers":
                        xmlinput.CheckElement("beziers");
                        stroke.kind = SymbolStrokes.PolyBezier;
                        stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                        stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput);
                        break;

                    case "filled-beziers":
                        xmlinput.CheckElement("filled-beziers");
                        stroke.kind = SymbolStrokes.FilledPolyBezier;
                        break;
                }

                if (isStroke) {
                    stroke.points = ReadPoints(xmlinput);
                    strokes.Add(stroke);
                }

                first = false;
            }

            if (this.name == null)
                xmlinput.BadXml("Missing name element");
            if (texts.Count == 0)
                xmlinput.BadXml("Missing text element");

            this.strokes = strokes.ToArray();
        }
Beispiel #5
0
        // Read the state of this language from XML.
        public void ReadXml(XmlInput xmlinput)
        {
            xmlinput.CheckElement("language");

            this.LangId = xmlinput.GetAttributeString("lang");
            this.PluralNouns = xmlinput.GetAttributeBool("plural-nouns", false);
            this.PluralModifiers = xmlinput.GetAttributeBool("plural-modifiers", false);
            this.GenderModifiers = xmlinput.GetAttributeBool("gender-modifiers", false);
            this.CaseModifiers = xmlinput.GetAttributeBool("case-modifiers", false);

            string genders = xmlinput.GetAttributeString("genders", "");
            if (genders != "") {
                this.Genders = genders.Split(new char[] {','});
            }

            string cases = xmlinput.GetAttributeString("cases", "");
            if (cases != "") {
                this.Cases = cases.Split(new char[] { ',' });
            }

            this.Name = xmlinput.GetContentString();
        }
Beispiel #6
0
        /// <summary>
        /// Read the state of this symbol from XML. The xmlinput must be on a
        /// symbol node.
        /// </summary>
        public void ReadXml(XmlInput xmlinput)
        {
            xmlinput.CheckElement("symbol");

            this.kind          = xmlinput.GetAttributeString("kind")[0];
            this.id            = xmlinput.GetAttributeString("id");
            this.replacementId = xmlinput.GetAttributeString("replacement-id", null);
            this.sizeIsDepth   = xmlinput.GetAttributeBool("size-is-depth", false);

            string standardStrings = xmlinput.GetAttributeString("standard", "");

            if (standardStrings != "")
            {
                this.standards = standardStrings.Split(',');
            }

            bool first = true;
            List <SymbolStroke> strokes = new List <SymbolStroke>();

            while (xmlinput.FindSubElement(first, new string[] { "name", "text", "filled-circle", "circle", "polygon", "filled-polygon", "lines", "beziers", "filled-beziers" }))
            {
                SymbolStroke stroke   = new SymbolStroke();
                bool         isStroke = true;

                switch (xmlinput.Name)
                {
                case "name":
                    xmlinput.CheckElement("name");
                    string language = xmlinput.GetAttributeString("lang");
                    name.Add(language, xmlinput.GetContentString());
                    isStroke = false;
                    break;

                case "text":
                    xmlinput.CheckElement("text");
                    SymbolText symtext = new SymbolText();
                    symtext.ReadXml(xmlinput);
                    texts.Add(symtext);
                    isStroke = false;
                    break;

                case "filled-circle":
                    xmlinput.CheckElement("filled-circle");
                    stroke.kind   = SymbolStrokes.Disc;
                    stroke.radius = xmlinput.GetAttributeFloat("radius");
                    break;

                case "circle":
                    xmlinput.CheckElement("circle");
                    stroke.kind      = SymbolStrokes.Circle;
                    stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                    stroke.radius    = xmlinput.GetAttributeFloat("radius");
                    break;

                case "polygon":
                    xmlinput.CheckElement("polygon");
                    stroke.kind      = SymbolStrokes.Polygon;
                    stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                    stroke.corners   = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput);
                    break;

                case "filled-polygon":
                    xmlinput.CheckElement("filled-polygon");
                    stroke.kind = SymbolStrokes.FilledPolygon;
                    break;

                case "lines":
                    xmlinput.CheckElement("lines");
                    stroke.kind      = SymbolStrokes.Polyline;
                    stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                    stroke.ends      = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput);
                    stroke.corners   = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput);
                    break;

                case "beziers":
                    xmlinput.CheckElement("beziers");
                    stroke.kind      = SymbolStrokes.PolyBezier;
                    stroke.thickness = xmlinput.GetAttributeFloat("thickness");
                    stroke.ends      = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput);
                    break;

                case "filled-beziers":
                    xmlinput.CheckElement("filled-beziers");
                    stroke.kind = SymbolStrokes.FilledPolyBezier;
                    break;
                }

                if (isStroke)
                {
                    stroke.points = ReadPoints(xmlinput);
                    strokes.Add(stroke);
                }

                first = false;
            }

            if (this.name == null)
            {
                xmlinput.BadXml("Missing name element");
            }
            if (texts.Count == 0)
            {
                xmlinput.BadXml("Missing text element");
            }

            this.strokes = strokes.ToArray();
        }
Beispiel #7
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();
            }
        }
Beispiel #8
0
        public override void ReadAttributesAndContent(XmlInput xmlinput)
        {
            string kindText = xmlinput.GetAttributeString("kind");
            switch (kindText) {
                case "normal":              kind = ControlPointKind.Normal; break;
                case "start":               kind = ControlPointKind.Start; break;
                case "finish":              kind = ControlPointKind.Finish; break;
                case "crossing-point":      kind = ControlPointKind.CrossingPoint; break;
                case "map-exchange": kind = ControlPointKind.MapExchange; break;
                default:                    xmlinput.BadXml("Invalid control point kind '{0}'", kindText); break;
            }

            if (kind == ControlPointKind.Normal || kind == ControlPointKind.Start || kind == ControlPointKind.MapExchange)
                symbolIds = new string[6];
            else if (kind == ControlPointKind.Finish || kind == ControlPointKind.CrossingPoint)
                symbolIds = new string[1];

            code = null;
            descriptionText = null;
            columnFText = null;

            // Old file format had a single gaps attribute for all scales. Put this in the dictionary with scale of 0, then update after load is finished.
            string gapText = xmlinput.GetAttributeString("gaps", "");
            if (gapText != "") {
                uint gapValue = Convert.ToUInt32(gapText, 2);
                if (gaps == null)
                    gaps = new Dictionary<int, CircleGap[]>();
                gaps[0] = CircleGap.ComputeCircleGaps(gapValue);
            }

            string codeAngle = xmlinput.GetAttributeString("all-controls-code-angle", "");
            if (codeAngle != "") {
                customCodeLocation = true;
                codeLocationAngle = XmlConvert.ToSingle(codeAngle);
            }

            if (kind == ControlPointKind.CrossingPoint)
                orientation = xmlinput.GetAttributeFloat("orientation");

            bool first = true;
            while (xmlinput.FindSubElement(first, "code", "location", "description", "description-text", "gaps", "circle-gaps", "punch-pattern", "description-text-line")) {
                switch (xmlinput.Name) {
                    case "code":
                        if (kind != ControlPointKind.Normal)
                            xmlinput.BadXml("Only normal control points can have a code");
                        code = xmlinput.GetContentString();
                        break;

                    case "location":
                        float x = xmlinput.GetAttributeFloat("x");
                        float y = xmlinput.GetAttributeFloat("y");
                        location = new PointF(x, y);
                        xmlinput.Skip();
                        break;

                    case "punch-pattern":
                        punches = new PunchPattern();
                        punches.size = xmlinput.GetAttributeInt("size");
                        punches.dots = new bool[punches.size, punches.size];

                        string punchPattern = xmlinput.GetContentString();

                        int index = 0;
                        for (int i = 0; i < punches.size; ++i)
                            for (int j = 0; j < punches.size; ++j) {
                                char c;
                                do {
                                    if (index >= punchPattern.Length) {
                                        xmlinput.BadXml("invalid punch pattern");
                                        goto QUITPUNCHPATTERN;
                                    }
                                    c = punchPattern[index++];
                                } while (c != '0' && c != '1');
                                punches.dots[i, j] = (c == '1');
                            }

                    QUITPUNCHPATTERN:
                        break;

                    case "gaps": {
                        int scale = xmlinput.GetAttributeInt("scale", 0);
                        gapText = xmlinput.GetContentString().Trim();

                        if (gapText != "") {
                            if (gaps == null)
                                gaps = new Dictionary<int, CircleGap[]>();
                            if (gapText.Contains(":")) {
                                // For 2.0 beta 1 compatibility only.
                                gaps[scale] = CircleGap.DecodeGaps(gapText);
                            }
                            else if (!gaps.ContainsKey(scale)) {
                                // Only use the old-style if the new-style wasn't found.
                                uint gapValue = Convert.ToUInt32(gapText, 2);
                                gaps[scale] = CircleGap.ComputeCircleGaps(gapValue);
                            }
                        }

                        break;
                    }

                    case "circle-gaps": {
                        int scale = xmlinput.GetAttributeInt("scale", 0);
                        gapText = xmlinput.GetContentString().Trim();

                        if (gapText != "") {
                            if (gaps == null)
                                gaps = new Dictionary<int, CircleGap[]>();
                            if (gapText.Contains(":")) {
                                // This is the new-style; overrides old style if both present.
                                gaps[scale] = CircleGap.DecodeGaps(gapText);
                            }
                        }

                        break;
                    }

                    case "description-text":
                        descriptionText = xmlinput.GetContentString();
                        break;

                    case "description-text-line":
                        xmlinput.CheckElement("description-text-line");
                        string locationText = xmlinput.GetAttributeString("location");
                        if (locationText == "before")
                            descTextBefore = xmlinput.GetContentString();
                        else if (locationText == "after")
                            descTextAfter = xmlinput.GetContentString();
                        else {
                            xmlinput.BadXml("location attribute on description-text-line must be \"before\" or \"after\"");
                            xmlinput.Skip();
                        }
                        break;

                    case "description":
                        string box = xmlinput.GetAttributeString("box");
                        string symbolId = xmlinput.GetAttributeString("iof-2004-ref", null);
                        string text = xmlinput.GetContentString();

                        switch (box) {
                            case "all": symbolIds[0] = symbolId; break;
                            case "C": symbolIds[0] = symbolId; break;
                            case "D": symbolIds[1] = symbolId; break;
                            case "E": symbolIds[2] = symbolId; break;
                            case "F": symbolIds[3] = symbolId; break;
                            case "G": symbolIds[4] = symbolId; break;
                            case "H": symbolIds[5] = symbolId; break;
                            default: xmlinput.BadXml("Invalid box type '{0}'", box); break;
                        }

                        if (box == "F" && !string.IsNullOrEmpty(text))
                            columnFText = text;
                        break;
                }

                first = false;
            }
        }
Beispiel #9
0
        public override void ReadAttributesAndContent(XmlInput xmlinput)
        {
            int myId = xmlinput.GetAttributeInt("id");

            nextCourseControl = Id<CourseControl>.None;
            splitCourseControls = null;
            control = new Id<ControlPoint>(xmlinput.GetAttributeInt("control"));

            string variationType = xmlinput.GetAttributeString("variation", "");
            if (variationType == "fork") {
                split = true; loop = false;
            }
            else if (variationType == "loop") {
                split = true; loop = true;
            }
            else {
                split = false;
            }
            if (split)
                splitEnd = new Id<CourseControl>(xmlinput.GetAttributeInt("variation-end"));
            exchange = xmlinput.GetAttributeBool("map-exchange", false);
            points = xmlinput.GetAttributeInt("points", 0);

            List<Id<CourseControl>> variationCourseControls = null;

            bool first = true;
            while (xmlinput.FindSubElement(first, "next", "variation", "number-location", "description-text-line")) {
                switch (xmlinput.Name) {
                    case "next":
                        xmlinput.CheckElement("next");
                        nextCourseControl = new Id<CourseControl>(xmlinput.GetAttributeInt("course-control"));
                        xmlinput.Skip();
                        break;

                    case "variation":
                        xmlinput.CheckElement("variation");
                        if (variationCourseControls == null)
                            variationCourseControls = new List<Id<CourseControl>>();
                        variationCourseControls.Add(new Id<CourseControl>(xmlinput.GetAttributeInt("course-control")));
                        xmlinput.Skip();
                        break;

                    case "number-location":
                        xmlinput.CheckElement("number-location");
                        customNumberPlacement = true;
                        numberDeltaX = xmlinput.GetAttributeFloat("x");
                        numberDeltaY = xmlinput.GetAttributeFloat("y");
                        xmlinput.Skip();
                        break;

                    case "description-text-line":
                        xmlinput.CheckElement("description-text-line");
                        string location = xmlinput.GetAttributeString("location");
                        if (location == "before")
                            descTextBefore = xmlinput.GetContentString();
                        else if (location == "after")
                            descTextAfter = xmlinput.GetContentString();
                        else {
                            xmlinput.BadXml("location attribute on description-text-line must be \"before\" or \"after\"");
                            xmlinput.Skip();
                        }
                        break;
                }
                first = false;
            }

            if (!split && variationCourseControls != null)
                xmlinput.BadXml("Non-variation course control shouldn't have variation sub-element.");

            if (variationCourseControls != null)
                splitCourseControls = variationCourseControls.ToArray();
        }