/// <summary>
        /// Activates a given node.
        /// </summary>
        /// <param name="nodeToActivate"> Node which gets activated </param>
        internal void activateNode(CognitiveInterventionNode nodeToActivate)
        {
            CognitiveInterventionAsset.Handler.loggingCI("Activating Node '" + nodeToActivate.id + "'.");

            if (!this.activeNodes.Contains(nodeToActivate))
            {
                this.activeNodes.Add(nodeToActivate);
            }

            foreach (string trackIterator in nodeToActivate.edges.Keys)
            {
                nodeToActivate.edges[trackIterator].active = true;
            }

            nodeToActivate.setDeactivationTimestamp();

            //perform intervention ...
            if (nodeToActivate.edges.Count == 0)
            {
                //...if there is any to perform
                if (nodeToActivate.interventionType != null && nodeToActivate.interventionType != "")
                {
                    performIntervention(nodeToActivate.interventionType);
                }
                deactivateNode(nodeToActivate);
            }
        }
        /// <summary>
        /// uses new received track to update the cognitive intervention tree
        /// </summary>
        /// <param name="track"> track received from the game. </param>
        internal void addNewTrack(string track)
        {
            loggingCI("New track added: '" + track + "'.");
            CognitiveInterventionTree tree = getCognitiveInterventionTree();

            foreach (CognitiveInterventionNode node in this.cognitiveInterventionTree.nodes)
            {
                node.wasActivatedThisUpdate = false;
            }

            List <string> listOfActiveNodeIds = tree.getListOfActiveNodeIds();

            foreach (string nodeId in listOfActiveNodeIds)
            {
                CognitiveInterventionNode node = tree.getCognitiveInterventionNodeById(nodeId);

                if (node.isStillActive())
                {
                    if (node.edges.ContainsKey(track))
                    {
                        if (node.edges[track].active)
                        {
                            tree.setActive(node, track);
                        }
                    }
                }
            }
            tree.logActiveNodes();
        }
 /// <summary>
 /// Deactivates a given node.
 /// </summary>
 /// <param name="nodeTodeactivate"> Node which gets deactivated </param>
 internal void deactivateNode(CognitiveInterventionNode nodeToDeactivate)
 {
     if (nodeToDeactivate.id.Equals(this.startingNode.id))
     {
         return;
     }
     CognitiveInterventionAsset.Handler.loggingCI("Deactivating Node '" + nodeToDeactivate.id + "'.");
     this.activeNodes.Remove(nodeToDeactivate);
 }
        /// <summary>
        /// Method for intervention trigger check
        /// </summary>
        internal void refresh()
        {
            CognitiveInterventionTree tree = getCognitiveInterventionTree();

            List <string> listOfActiveNodeIds = tree.getListOfActiveNodeIds();

            foreach (string nodeId in listOfActiveNodeIds)
            {
                CognitiveInterventionNode node = tree.getCognitiveInterventionNodeById(nodeId);
                node.isStillActive();
            }
        }
        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;
        }