PageRenderTime 40ms CodeModel.GetById 37ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Examples/012 - Graphviz example.linq

#
Unknown | 45 lines | 37 code | 8 blank | 0 comment | 0 complexity | 21dadff9090673c344eafd449b20f8c9 MD5 | raw file
 1<Query Kind="Program">
 2  <Reference Relative="..\Mercurial.Net\bin\Debug\Mercurial.NET.dll">C:\Dev\VS.NET\Mercurial.Net\Mercurial.Net\bin\Debug\Mercurial.NET.dll</Reference>
 3  <Namespace>Mercurial</Namespace>
 4</Query>
 5
 6// *****************************************************
 7// *
 8// * Visualize a random bitbucket-project through Graphviz
 9// * The project was chosen because it had relatively few
10// * changesets, and a couple of parallel branches.
11// *
12// ***********************
13
14const string repoPath = @"C:\Temp\repo";
15const string repoSource = @"http://bitbucket.org/ventor3000/iup.net";
16const string tempFile = @"C:\Temp\test.dot";
17
18void Main()
19{
20    if (Directory.Exists(repoPath))
21        Directory.Delete(repoPath, true);
22    Directory.CreateDirectory(repoPath);
23    
24    var repo = new Repository(repoPath);
25    repo.Init();
26    var log = repo.Incoming(repoSource, new IncomingCommand().WithTimeout(240));
27
28    List<string> lines = new List<string>();
29    lines.Add("digraph G {");
30    lines.Add("   rankdir = LR;");
31    
32    foreach (var changeset in log)
33    {
34        if (changeset.LeftParentRevision >= 0)
35            lines.Add("    \"" + changeset.LeftParentRevision + "\" -> \"" + changeset.RevisionNumber + "\"");
36        if (changeset.RightParentRevision >= 0)
37            lines.Add("    \"" + changeset.RightParentRevision + "\" -> \"" + changeset.RevisionNumber + "\"");
38    }
39    
40    lines.Add("}");
41    File.WriteAllLines(tempFile, lines.ToArray());
42    
43    Util.Cmd("dot " + tempFile + " -Tpng -O");
44    Util.Cmd("\"" + tempFile + ".png\"");
45}