private XElement ConvertPlaceToPnmlElement(Place place) { var placeElement = new XElement("place"); place.ID = place.ID ?? place.ID ?? Guid.NewGuid().ToString().Substring(0, 8); placeElement.SetAttributeValue("id", place.ID); var nameElement = new XElement("name"); var textElement = new XElement("text", place.Label); nameElement.Add(textElement); placeElement.Add(nameElement); if (place.Marking > 0) { var markingElement = new XElement("initialMarking"); markingElement.Add(new XElement("text", place.Marking)); placeElement.Add(markingElement); } AppendMetadataToPnmlElement(placeElement, place.GraphicsMetadata); return placeElement; }
private static Place GetPlaceObjectFromPnmlElement(XElement pnmlElement) { Place place = new Place(); place.ID = pnmlElement.Attribute("id").Value; place.Label = pnmlElement.Element("name").Element("text").Value; if (pnmlElement.Element("initialMarking") != null) { place.Marking = int.Parse(pnmlElement.Element("initialMarking").Element("text").Value); } if (pnmlElement.Element("graphics") != null) { if (pnmlElement.Element("graphics").Element("position") != null) { place.SetGraphicsMetadataItem("graphics.position.@x", int.Parse(pnmlElement.Element("graphics").Element("position").Attribute("x").Value)); place.SetGraphicsMetadataItem("graphics.position.@y", int.Parse(pnmlElement.Element("graphics").Element("position").Attribute("y").Value)); } if (pnmlElement.Element("graphics").Element("dimension") != null) { place.SetGraphicsMetadataItem("graphics.dimension.@x", int.Parse(pnmlElement.Element("graphics").Element("dimension").Attribute("x").Value)); place.SetGraphicsMetadataItem("graphics.dimension.@y", int.Parse(pnmlElement.Element("graphics").Element("dimension").Attribute("y").Value)); } } return place; }