public string SaveDgml(string filePath, bool whatIf = false) { var writer = new DgmlWriter(); Console.WriteLine("Analyzing the async graphs..."); var visualContext = VisuaNodes.VisualContext.Create(Nodes, simplify: true); foreach (var node in visualContext.EnumerateVisualNodes()) { writer.AddNode(new DgmlWriter.Node(id: node.Id, label: node.DisplayText)); //foreach (var dependency in node.Dependencies.OrderBy(d => d.Id)) foreach (var dependency in node.AwaitsOn) { writer.AddLink(new DgmlWriter.Link( source: node.Id, target: dependency.Id, label: null)); } } if (whatIf) { return(writer.SerializeAsString()); } if (File.Exists(filePath)) { var existingFile = File.ReadAllText(filePath); var newFile = writer.SerializeAsString(); if (existingFile == newFile) { Console.WriteLine("No changes were detected!"); } else { Console.WriteLine("The diagram has changaed!"); writer.Serialize(filePath); } } else { writer.Serialize(filePath); } return(writer.SerializeAsString()); }
public void WriteToFile(string file) { using (var ms = new FileStream(file, FileMode.Create)) { XmlWriter io = new XmlTextWriter(ms, Encoding.Unicode); _dgmlWriter.Serialize(io); } }
/// <summary> /// Exports the contents of the given pip graph. It is expected to no longer change as of the start of this call. /// </summary> public override int Analyze() { DgmlWriter writer = new DgmlWriter(); Dictionary <PipId, PipReference> concretePipValues = new Dictionary <PipId, PipReference>(); HashSet <PipReference> allValuePips = new HashSet <PipReference>(PipGraph.RetrievePipReferencesOfType(PipType.Value)); foreach (var valuePip in allValuePips) { foreach (var incoming in DataflowGraph.GetIncomingEdges(valuePip.PipId.ToNodeId())) { if (!PipTable.GetPipType(incoming.OtherNode.ToPipId()).IsMetaPip()) { concretePipValues[valuePip.PipId] = valuePip; } } } foreach (var concretePipValue in concretePipValues.Values) { var value = ((ValuePip)concretePipValue.HydratePip()).Symbol.ToString(SymbolTable); writer.AddNode(new DgmlWriter.Node(concretePipValue.PipId.ToString(), value)); foreach (var incoming in DataflowGraph.GetIncomingEdges(concretePipValue.PipId.ToNodeId())) { var incomingId = incoming.OtherNode.ToPipId(); if (concretePipValues.ContainsKey(incomingId)) { writer.AddLink(new DgmlWriter.Link( incomingId.ToString(), concretePipValue.PipId.ToString(), label: null)); } } } writer.Serialize(m_dgmlFilePath); return(0); }
public void CreateDiagram(string path) { var parser = new BoardDgmlParser(); // Get all links var edges = new List <Edge <Component> >(); foreach (var cycle in _board.Cycle()) { edges.AddRange(parser.ParseCyclesToEdge(cycle)); } parser.Parse(new BoardDgmlStrategy(), edges); var dgmlWriter = new DgmlWriter(); dgmlWriter.Nodes = parser.Nodes; dgmlWriter.Links = parser.Links; dgmlWriter.Serialize(path); }