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); }
/// <summary> /// Method for setting a node active. /// </summary> /// <param name="startingNode"> Node from which the new active node is reached. </param> /// <param name="track"> Tracking id for setting the node active. </param> internal void setActive(CognitiveInterventionNode startingNode, string track) { CognitiveInterventionAsset.Handler.loggingCI("New update: starting from Node '" + startingNode.id + "' because of track '" + track + "'."); CognitiveInterventionEdge edge = startingNode.edges[track]; //set edge inactive, if not started from starting node if (!this.startingNode.id.Equals(startingNode.id)) { edge.active = false; } //deactivate node if it is an exclusive edge if (edge.exclusive && !this.startingNode.id.Equals(startingNode.id)) { if (!startingNode.wasActivatedThisUpdate) { deactivateNode(startingNode); } } else { //deactivate node if all edges are deactivated bool anActiveEdgeExists = false; foreach (string trackIterator in startingNode.edges.Keys) { if (startingNode.edges[trackIterator].active) { anActiveEdgeExists = true; } } if (!anActiveEdgeExists && !this.startingNode.id.Equals(startingNode.id)) { deactivateNode(startingNode); } } //activate new edge activateNode(edge.successor); edge.successor.wasActivatedThisUpdate = true; }