public static string Serialize(IModule module)
        {
            var types = module.GetAllTypes();

            return(DGMLSerializer.Serialize(types));
        }
        public static string Serialize(INamedTypeReference type)
        {
            var types = new INamedTypeReference[] { type };

            return(DGMLSerializer.Serialize(type));
        }
        public static string Serialize(PointsToGraph ptg)
        {
            using (var stringWriter = new StringWriter())
                using (var xmlWriter = new XmlTextWriter(stringWriter))
                {
                    xmlWriter.Formatting = Formatting.Indented;
                    xmlWriter.WriteStartElement("DirectedGraph");
                    xmlWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/vs/2009/dgml");
                    xmlWriter.WriteStartElement("Nodes");

                    foreach (var variable in ptg.Variables)
                    {
                        var label = variable.Name;

                        xmlWriter.WriteStartElement("Node");
                        xmlWriter.WriteAttributeString("Id", label);
                        xmlWriter.WriteAttributeString("Label", label);
                        xmlWriter.WriteAttributeString("Shape", "None");
                        xmlWriter.WriteEndElement();
                    }

                    foreach (var node in ptg.Nodes)
                    {
                        var nodeId = Convert.ToString(node.Id);
                        var label  = DGMLSerializer.Serialize(node);

                        xmlWriter.WriteStartElement("Node");
                        xmlWriter.WriteAttributeString("Id", nodeId);
                        xmlWriter.WriteAttributeString("Label", label);

                        if (node.Kind == PTGNodeKind.Null)
                        {
                            xmlWriter.WriteAttributeString("Background", "Yellow");
                        }
                        else if (node.Kind == PTGNodeKind.Unknown)
                        {
                            xmlWriter.WriteAttributeString("Background", "#FFB445");
                            xmlWriter.WriteAttributeString("StrokeDashArray", "6,6");
                        }

                        xmlWriter.WriteEndElement();
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("Links");

                    foreach (var node in ptg.Nodes)
                    {
                        var targetId = Convert.ToString(node.Id);

                        foreach (var variable in node.Variables)
                        {
                            var sourceId = variable.Name;

                            xmlWriter.WriteStartElement("Link");
                            xmlWriter.WriteAttributeString("Source", sourceId);
                            xmlWriter.WriteAttributeString("Target", targetId);
                            xmlWriter.WriteEndElement();
                        }

                        var fieldsBySource = from e in node.Sources
                                             from s in e.Value
                                             group e.Key by s into g
                                             select g;

                        foreach (var g in fieldsBySource)
                        {
                            var sourceId = Convert.ToString(g.Key.Id);
                            var label    = DGMLSerializer.GetLabel(g);

                            xmlWriter.WriteStartElement("Link");
                            xmlWriter.WriteAttributeString("Source", sourceId);
                            xmlWriter.WriteAttributeString("Target", targetId);
                            xmlWriter.WriteAttributeString("Label", label);
                            xmlWriter.WriteEndElement();
                        }
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("Styles");
                    xmlWriter.WriteStartElement("Style");
                    xmlWriter.WriteAttributeString("TargetType", "Node");

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "FontFamily");
                    xmlWriter.WriteAttributeString("Value", "Consolas");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "NodeRadius");
                    xmlWriter.WriteAttributeString("Value", "5");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "MinWidth");
                    xmlWriter.WriteAttributeString("Value", "0");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.Flush();
                    return(stringWriter.ToString());
                }
        }
        public static string Serialize(ControlFlowGraph cfg)
        {
            using (var stringWriter = new StringWriter())
                using (var xmlWriter = new XmlTextWriter(stringWriter))
                {
                    xmlWriter.Formatting = Formatting.Indented;
                    xmlWriter.WriteStartElement("DirectedGraph");
                    xmlWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/vs/2009/dgml");
                    xmlWriter.WriteStartElement("Nodes");

                    foreach (var node in cfg.Nodes)
                    {
                        var nodeId = Convert.ToString(node.Id);
                        var label  = DGMLSerializer.Serialize(node);

                        xmlWriter.WriteStartElement("Node");
                        xmlWriter.WriteAttributeString("Id", nodeId);
                        xmlWriter.WriteAttributeString("Label", label);

                        if (node.Kind == CFGNodeKind.Entry ||
                            node.Kind == CFGNodeKind.Exit)
                        {
                            xmlWriter.WriteAttributeString("Background", "Yellow");
                        }

                        xmlWriter.WriteEndElement();
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("Links");

                    foreach (var node in cfg.Nodes)
                    {
                        var sourceId = Convert.ToString(node.Id);

                        foreach (var successor in node.Successors)
                        {
                            var targetId = Convert.ToString(successor.Id);

                            xmlWriter.WriteStartElement("Link");
                            xmlWriter.WriteAttributeString("Source", sourceId);
                            xmlWriter.WriteAttributeString("Target", targetId);
                            xmlWriter.WriteEndElement();
                        }
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("Styles");
                    xmlWriter.WriteStartElement("Style");
                    xmlWriter.WriteAttributeString("TargetType", "Node");

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "FontFamily");
                    xmlWriter.WriteAttributeString("Value", "Consolas");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "NodeRadius");
                    xmlWriter.WriteAttributeString("Value", "5");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "MinWidth");
                    xmlWriter.WriteAttributeString("Value", "0");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.Flush();
                    return(stringWriter.ToString());
                }
        }
Beispiel #5
0
        public static string Serialize(SimplePointsToGraph ptg)
        {
            using (var stringWriter = new StringWriter())
                using (var xmlWriter = new XmlTextWriter(stringWriter))
                {
                    xmlWriter.Formatting = Formatting.Indented;
                    xmlWriter.WriteStartElement("DirectedGraph");
                    xmlWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/vs/2009/dgml");
                    xmlWriter.WriteStartElement("Nodes");

                    foreach (var variable in ptg.Roots)
                    {
                        var label = variable.Name;

                        xmlWriter.WriteStartElement("Node");
                        xmlWriter.WriteAttributeString("Id", label);
                        xmlWriter.WriteAttributeString("Label", label);
                        xmlWriter.WriteAttributeString("Shape", "None");
                        xmlWriter.WriteEndElement();
                    }

                    foreach (var node in ptg.Nodes)
                    {
                        var nodeId = Convert.ToString(node.Id);
                        var label  = DGMLSerializer.Serialize(node);

                        xmlWriter.WriteStartElement("Node");
                        xmlWriter.WriteAttributeString("Id", nodeId);
                        xmlWriter.WriteAttributeString("Label", label);

                        if (node.Kind == PTGNodeKind.Null)
                        {
                            xmlWriter.WriteAttributeString("Background", "Yellow");
                        }
                        else if (node.Kind == PTGNodeKind.Delegate)
                        {
                            xmlWriter.WriteAttributeString("Background", "Cyan");
                        }
                        else if (node.Kind == PTGNodeKind.Parameter)
                        {
                            xmlWriter.WriteAttributeString("Background", "Red");
                            xmlWriter.WriteAttributeString("StrokeDashArray", "6,6");
                        }
                        else if (node.Kind == PTGNodeKind.Unknown)
                        {
                            xmlWriter.WriteAttributeString("Background", "#FFB445");
                            xmlWriter.WriteAttributeString("StrokeDashArray", "6,6");
                        }

                        xmlWriter.WriteEndElement();
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("Links");

                    foreach (var variable in ptg.Roots)
                    {
                        var sourceId = variable.Name;
                        foreach (var target in ptg.GetTargets(variable))
                        {
                            var targetId = Convert.ToString(target.Id);

                            xmlWriter.WriteStartElement("Link");
                            xmlWriter.WriteAttributeString("Source", sourceId);
                            xmlWriter.WriteAttributeString("Target", targetId);
                            xmlWriter.WriteEndElement();
                        }
                    }

                    foreach (var node in ptg.Nodes)
                    {
                        var sourceId = Convert.ToString(node.Id);

                        foreach (var targetMap in ptg.GetTargets(node))
                        {
                            foreach (var target in targetMap.Value)
                            {
                                var targetId = Convert.ToString(target.Id);
                                var label    = targetMap.Key.Name;

                                xmlWriter.WriteStartElement("Link");
                                xmlWriter.WriteAttributeString("Source", sourceId);
                                xmlWriter.WriteAttributeString("Target", targetId);
                                xmlWriter.WriteAttributeString("Label", label);
                                xmlWriter.WriteEndElement();
                            }
                        }
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("Styles");
                    xmlWriter.WriteStartElement("Style");
                    xmlWriter.WriteAttributeString("TargetType", "Node");

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "FontFamily");
                    xmlWriter.WriteAttributeString("Value", "Consolas");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "NodeRadius");
                    xmlWriter.WriteAttributeString("Value", "5");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Setter");
                    xmlWriter.WriteAttributeString("Property", "MinWidth");
                    xmlWriter.WriteAttributeString("Value", "0");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.Flush();
                    return(stringWriter.ToString());
                }
        }