public virtual string ToSvg(IGraphDescriptor graphDescriptor, IUndirectedGraph<IContent, IUndirectedEdge<IContent>> graph, Action<GraphvizAlgorithm<IContent, IUndirectedEdge<IContent>>> initialization) { //var stringBuilder = new StringBuilder(); //using (var xmlWriter = XmlWriter.Create(stringBuilder)) //{ // // This may also need attributes on models, see: http://quickgraph.codeplex.com/wikipage?title=GraphML%20Serialization&referringTitle=Documentation // graph.SerializeToGraphML<TNode, IUndirectedEdge<TNode>, IUndirectedGraph<TNode, IUndirectedEdge<TNode>>>( // xmlWriter, // node => node.Label, // edge => edge.Source.ContentItem.Id.ToString() + edge.Target.ContentItem.Id.ToString()); //} //var graphML = stringBuilder.ToString(); // Sadly graph.GetHashCode() gives different results on different requests, therefore only the dot hash // is reliable. Fortunately it's quite fast. var dotData = graph.ToGraphviz(algorithm => { initialization(algorithm); }); var filePath = "_AssociativyModules/Frontends/GraphImages/" + graphDescriptor.Name + "/" + dotData.GetHashCode() + ".svg"; var cacheKey = "Associativy.Frontends.Graphviz.GraphImages." + filePath; return _cacheService.GetMonitored(graphDescriptor, cacheKey, () => { using (var lockFile = _lockManager.TryAcquireLock(cacheKey)) { return RetrieveImage(dotData, filePath); } }); }