private void WriteXml(StateMachine stateMachine) { Check.Require(stateMachine != null, string.Format(CommonStrings.XMustNotBeNull, "stateMachine")); Check.Require(stateMachine.States!= null && !stateMachine.States.IsEmpty(), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "stateMachine.States")); foreach (State state in stateMachine.States) { string stateType = AmType.GetName(state); writer.WriteStartElement(UseOpenEhrPrefix(writer), "states", OpenEhrNamespace); writer.WriteAttributeString(UseXsiPrefix(writer), "type", XsiNamespace, stateType); this.WriteXml(state); writer.WriteEndElement(); } }
protected void Validate(StateMachine stateMachine) { Invariant(stateMachine.States != null && !stateMachine.States.IsEmpty(), "stateMachine.States must not be null or empty."); foreach (State state in stateMachine.States) this.Validate(state); }
private void ReadXml(StateMachine stateMachine) { Check.Require(stateMachine != null, "StateMachine must not be null."); reader.ReadStartElement(); reader.MoveToContent(); if (reader.LocalName != "states") throw new InvalidXmlException("states", reader.LocalName); System.Collections.Generic.List<State> statesList = new System.Collections.Generic.List<State>(); do{ string stateType = reader.GetAttribute("type", XsiNamespace); Check.Assert(!string.IsNullOrEmpty(stateType), "stateType must not be null or empty."); State state = AmFactory.State(stateType); this.ReadXml(state); statesList.Add(state); }while (reader.LocalName != "states"); Check.Assert(statesList.Count>0, "statesList must not be empty."); stateMachine.States = new Set<State>(statesList); reader.ReadEndElement(); reader.MoveToContent(); }