Exemplo n.º 1
0
        private static void AddNodesToDiagram(string parentNodeGuid, XmlNode currentNode, Dgm.PointList pointList, Dgm.ConnectionList connectionList, UInt32 connectionSourcePosition, bool clearExisting)
        {
            //recursive function to add nodes to an existing diagram
            if (clearExisting)
            {
                //remove all connections
                connectionList.RemoveAllChildren();
                //remove all nodes except where type = 'doc' ... NOTE: Didn't test what happens if you also remove the doc type node, but it seemed important.
                List <Dgm.Point> pts = pointList.OfType <Dgm.Point>().Where(x => x.Type != "doc").ToList();
                for (int i = pts.Count - 1; i >= 0; i--)
                {
                    pts[i].Remove();
                }                                                            //remove in reverse order.
            }

            string currentNodeGuid = "{" + Guid.NewGuid().ToString() + "}";//generate new guid, not sure if curly brackets are required (probably not).

            //create the new point
            Dgm.Point newPoint = new Dgm.Point(new Dgm.PropertySet())
            {
                ModelId = currentNodeGuid
            };
            Dgm.ShapeProperties newPointShapeProperties = new Dgm.ShapeProperties();

            if (currentNode.Attributes["highlight"] != null && currentNode.Attributes["highlight"].Value == "true")
            {
                //if we need to highlight this particular point, then add a solidfill to it
                newPointShapeProperties.Append(new A.SolidFill(new A.SchemeColor()
                {
                    Val = A.SchemeColorValues.Accent5
                }));
            }

            Dgm.TextBody newPointTextBody = new Dgm.TextBody(new A.BodyProperties(), new A.ListStyle());

            A.Paragraph     paragraph1                 = new A.Paragraph();
            A.Run           ComponentNameRun           = new A.Run();
            A.RunProperties ComponentNameRunProperties = new A.RunProperties()
            {
                Language = "en-AU"
            };
            A.Text ComponentNameText = new A.Text(currentNode.Attributes["componentName"].Value);
            ComponentNameRun.Append(ComponentNameRunProperties);
            ComponentNameRun.Append(ComponentNameText);
            paragraph1.Append(ComponentNameRun);

            A.Paragraph     paragraph2                = new A.Paragraph();
            A.Run           PositionNameRun           = new A.Run();
            A.RunProperties PositionNameRunProperties = new A.RunProperties()
            {
                Language = "en-AU"
            };
            A.Text PositionNameText = new A.Text(currentNode.Attributes["memberName"].Value);
            PositionNameRun.Append(PositionNameRunProperties);
            PositionNameRun.Append(PositionNameText);
            paragraph2.Append(PositionNameRun);

            newPointTextBody.Append(paragraph1);
            newPointTextBody.Append(paragraph2);

            newPoint.Append(newPointShapeProperties, newPointTextBody);//append to point

            //append the point to the point list

            pointList.Append(newPoint);

            if (!string.IsNullOrEmpty(parentNodeGuid))
            {
                //if parent specified, then create the connection where the parent is the source and the current node is the destination
                connectionList.Append(new Dgm.Connection()
                {
                    ModelId = "{" + Guid.NewGuid().ToString() + "}", SourceId = parentNodeGuid, DestinationId = currentNodeGuid, SourcePosition = (UInt32Value)connectionSourcePosition, DestinationPosition = (UInt32Value)0U
                });
            }

            foreach (XmlNode childNode in currentNode.ChildNodes)
            {
                //call this method for every child
                AddNodesToDiagram(currentNodeGuid, childNode, pointList, connectionList, connectionSourcePosition++, false);
            }
        }