Esempio n. 1
0
        protected internal override void Save(XmlWriter writer)
        {
            writer.WriteStartElement("unit");
            writer.WriteAttributeString("id", GetXmlId());
            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteAttributeString("name", Name);
            }
            writer.WriteAttributeString("position", ManeuveringBoard.FormatXmlVector(Position));
            writer.WriteAttribute("course", Direction);
            writer.WriteAttribute("speed", Speed);

            string typeString = Type.ToString();

            writer.WriteAttributeString("type", typeString.Substring(0, 1).ToLowerInvariant() + typeString.Substring(1));

            if (TMASolution != null)
            {
                TMASolution.Save(writer);
            }

            if (Children.Count != 0)
            {
                writer.WriteStartElement("children");
                foreach (Shape shape in Children)
                {
                    shape.Save(writer);
                }
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Esempio n. 2
0
        public static new UnitShape Load(XmlReader reader, Dictionary <Observation, string> observers, Dictionary <string, UnitShape> unitsById)
        {
            UnitShape shape = new UnitShape();

            shape.Name      = reader.GetAttribute("name");
            shape.Position  = ManeuveringBoard.ParseXmlPoint(reader.GetStringAttribute("position"));
            shape.Direction = reader.GetDoubleAttribute("course");
            shape.Speed     = reader.GetDoubleAttribute("speed");
            shape.Type      = Utility.ParseEnum <UnitShapeType>(reader.GetStringAttribute("type", "unknown"), true);

            string id = reader.GetAttribute("id");

            if (!string.IsNullOrEmpty(id))
            {
                unitsById.Add(id, shape);
            }

            if (!reader.IsEmptyElement)
            {
                reader.Read();
                while (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.LocalName == "tmaSolution")
                    {
                        shape.TMASolution = TMASolution.Load(reader);
                    }
                    else if (reader.LocalName == "children" && !reader.IsEmptyElement)
                    {
                        reader.Read(); // move to either the first child or the end element
                        while (reader.NodeType == XmlNodeType.Element)
                        {
                            shape.Children.Add(Shape.Load(reader, observers, unitsById));
                        }
                        reader.ReadEndElement();
                    }
                    else
                    {
                        throw new InvalidDataException("Expected element " + reader.LocalName);
                    }
                }
            }

            return(shape);
        }