/// <summary> /// Method for deserilizing the cognitive intervention XML datastructure. /// </summary> /// <param name="str"> the xml-string to be desirilized. </param> /// <returns> The desirilized data structure. </returns> internal XMLCognitiveInterventionData getDatastructureFromXmlString(String str) { XmlSerializer serializer = new XmlSerializer(typeof(XMLCognitiveInterventionData)); //Console.WriteLine(str); using (TextReader reader = new StringReader(str)) { XMLCognitiveInterventionData result = (XMLCognitiveInterventionData)serializer.Deserialize(reader); return(result); } }
public CognitiveInterventionTree(XMLCognitiveInterventionData data) { //fill interventions List <string> instances; foreach (XMLCognitiveInterventionType interventionType in data.cognitiveInterventionTypeList.cognitiveInterventionType) { instances = new List <string>(); foreach (XMLCognitiveInterventionInstance instance in interventionType.cognitiveInterventionInstanceList.cognitiveInterventionInstanceList) { instances.Add(instance.instance); } this.interventions[interventionType.typeId] = instances; } //create and add all nodes foreach (XMLCognitiveInterventionNode xmlNode in data.cognitiveInterventionNodeList.cognitiveInterventionNodes) { CognitiveInterventionNode newNode = new CognitiveInterventionNode(xmlNode.nodeId); newNode.interventionType = xmlNode.interventionType; newNode.timeToDeactivationInMiliSec = xmlNode.activationDuration; this.nodes.Add(newNode); } //create and add all edges CognitiveInterventionNode node; CognitiveInterventionEdge newEdge; foreach (XMLCognitiveInterventionNode xmlNode in data.cognitiveInterventionNodeList.cognitiveInterventionNodes) { node = getCognitiveInterventionNodeById(xmlNode.nodeId); if (xmlNode.cognitiveInterventionEdgeList != null && xmlNode.cognitiveInterventionEdgeList.cognitiveInterventionEdges != null) { foreach (XMLCognitiveInterventionEdge xmlEdge in xmlNode.cognitiveInterventionEdgeList.cognitiveInterventionEdges) { newEdge = new CognitiveInterventionEdge(); newEdge.successor = getCognitiveInterventionNodeById(xmlEdge.successorId); newEdge.exclusive = xmlEdge.type.Equals("exclusive") ? true : false; node.edges[xmlEdge.trackingId] = newEdge; } } else { node.edges = new Dictionary <string, CognitiveInterventionEdge>(); } } this.startingNode = getCognitiveInterventionNodeById(data.cognitiveInterventionStartingNode); this.activeNodes.Add(this.startingNode); }