Example #1
0
        public static List <Question> GetGraphNodes()
        {
            var graph = new List <Question>();
            //var graphMl = MapFromXml();
            var xml = XElement.Load(@"C:\Users\Lucho\Documents\En ejecuciĆ³n\Proyectos\UAN\HAVIR\HumanoVirtual\Assets\HAVIR\Scripts\Game\Main\GraphModel\BasicDialog.graphml");

            var graphXml = xml.Elements("{http://graphml.graphdrawing.org/xmlns}graph");

            foreach (var node in graphXml.Elements("{http://graphml.graphdrawing.org/xmlns}node"))
            {
                var d5 = node.Elements("{http://graphml.graphdrawing.org/xmlns}data").FirstOrDefault(x => x.Attribute("key").Value.Equals("d5"));
                var d6 = node.Elements("{http://graphml.graphdrawing.org/xmlns}data").FirstOrDefault(x => x.Attribute("key").Value.Equals("d6"));
                string
                    id          = node.Attribute("id").Value,
                    description = "",
                    audio       = "",
                    animation   = "";
                if (d5 != null)
                {
                    var data = d5.Value.Split('|');
                    description = data[0];
                    audio       = data.Any(x => x.StartsWith("@audio")) ? string.Empty : data.FirstOrDefault(x => x.StartsWith("@audio"));
                    animation   = data.Any(x => x.StartsWith("@animation")) ? string.Empty : data.FirstOrDefault(x => x.StartsWith("@animation"));
                }

                var genericNode = (XElement)d6.FirstNode;
                var type        = genericNode.Attribute("configuration").Value;

                var targetEdges = graphXml.Elements("{http://graphml.graphdrawing.org/xmlns}edge").Where(x => x.Attribute("target").Value == id);
                var graphNode   = new Question(id, description, audio, animation, _getNodeType(type), targetEdges.Any());
                var sourceEdges = graphXml.Elements("{http://graphml.graphdrawing.org/xmlns}edge")
                                  .Where(x => x.Attribute("source").Value == id);

                foreach (var edge in sourceEdges)
                {
                    var edgeData = edge.Elements("{http://graphml.graphdrawing.org/xmlns}data").FirstOrDefault(x => x.Attribute("key").Value.Equals("d9"));
                    var arista   = new Answer()
                    {
                        TargetId = edge.Attribute("target").Value
                    };
                    arista.Choices = new List <string>();
                    List <string> tempChoices;
                    if (edgeData != null)
                    {
                        foreach (var option in edgeData.Value.Split(','))
                        {
                            if (PredefinedAnswers.dictionary.TryGetValue(edgeData.Value, out tempChoices))
                            {
                                arista.Choices.AddRange(tempChoices);
                            }
                            else
                            {
                                arista.Choices.Add(option);
                            }
                        }
                    }

                    graphNode.AddArista(arista);
                }
                graph.Add(graphNode);
            }


            return(graph);
        }