Esempio n. 1
0
        /// <summary>
        /// Reads the Sketch XML attributes and cycles through the XML elements
        /// </summary>
        /// <param name="reader">XML text reader for the file</param>
        private void ReadSketchData(XmlTextReader reader)
        {
            reader.MoveToContent();

            if (reader.Name != "sketch")
            {
                throw new XmlException("MIT XML must have a sketch as its root element");
            }

            // Modify the Sketch's attributes
            Sketch.XmlStructs.XmlSketchAttrs sketchAttrs = new Sketch.XmlStructs.XmlSketchAttrs();
            sketchAttrs.Id = new Guid(reader.GetAttribute("id"));

            if (reader.MoveToAttribute("units"))
            {
                sketchAttrs.Units = reader.Value;
            }
            else
            {
                sketchAttrs.Units = "himetric";
            }

            sketch.XmlAttrs = sketchAttrs;

            // Go past the sketch tag and start reading subelements
            reader.Read();

            // Now read the subelements
            while (reader.NodeType != XmlNodeType.EndElement &&
                   reader.NodeType != XmlNodeType.None)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "sketcher":
                        ReadSketcher(reader);
                        break;

                    case "study":
                        ReadStudy(reader);
                        break;

                    case "domain":
                        ReadDomain(reader);
                        break;

                    case "point":
                        ReadPoint(reader);
                        break;

                    case "shape":
                        ReadShape(reader);
                        break;

                    case "edit":
                        ReadEdit(reader);
                        break;

                    case "speech":
                        ReadSpeech(reader);
                        break;

                    case "mediaInfo":
                        ReadMediaInfo(reader);
                        break;
                    }
                }
                else
                {
                    string message = "Invalid file format: " + reader.NodeType + " not expected";
                    throw new XmlException(message);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the Sketch XML attributes and cycles through the XML elements
        /// </summary>
        /// <param name="reader">XML text reader for the file</param>
        private void ReadSketchData(XmlTextReader reader)
        {
            reader.MoveToContent();

            if (reader.Name != "sketch")
            {
                throw new XmlException("MIT XML must have a sketch as its root element");
            }

            // Modify the Sketch's attributes
            string id = reader.GetAttribute("id");

            Sketch.XmlStructs.XmlSketchAttrs sketchAttrs = XmlStructs.XmlSketchAttrs.CreateNew(id);

            if (reader.MoveToAttribute("units"))
            {
                sketchAttrs._units = reader.Value;
            }
            else
            {
                sketchAttrs._units = "pixels";
            }

            if (reader.MoveToAttribute("name"))
            {
                sketchAttrs.Name = reader.Value;
            }

            sketch.XmlAttrs = sketchAttrs;

            // Go past the sketch tag and start reading subelements
            reader.Read();

            // Now read the subelements
            while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "point":
                        ReadPoint(reader);
                        break;

                    case "shape":
                        ReadShape(reader);
                        break;

                    case "edit":
                        ReadEdit(reader);
                        break;

                    case "speech":
                        ReadSpeech(reader);
                        break;

                    case "mediaInfo":
                        ReadMediaInfo(reader);
                        break;

                    case "Text":
                        reader.Read();
                        break;

                    case "circuit":
                        ReadCircuitInfo(reader);
                        break;

                    case "SubCircuitLookup":
                        ReadSubCircuits(reader);
                        break;

                    default:
                        Console.WriteLine("ReadXML: Warning: skipping tag '" + reader.Name + "'");
                        reader.Read();
                        break;
                    }
                }
                else
                {
                    //Hack to let it pass while I'm working on saving and loading sub circuits
                    if (reader.NodeType == XmlNodeType.Text)
                    {
                        reader.Read();
                    }
                    else
                    {
                        string message = "Invalid file format: " + reader.NodeType + " not expected";
                        throw new XmlException(message);
                    }
                }
            }
            if (sketch.Units == "himetric")
            {
                sketch.Units = "pixel";
                throw new Exception("trying to load old format. use new format in data/converthimetricdata");
            }
        }