public TextReader Run(Action <TextWriter> writeGraph, string format, Graphs.LayoutEngine engine = Graphs.LayoutEngine.Dot)
        {
            using (var writer = new StringWriter())
            {
                writeGraph(writer);
                string graph     = writer.GetStringBuilder().ToString();
                var    graphFile = Path.Combine(Path.GetTempPath(), this.filename + ".dot");
                File.WriteAllText(graphFile, graph);

                // now we read the file and write it to the real process input.
                using (var reader = this.runner.Run(w => w.Write(graph), format, engine))
                {
                    // we read all output, save it into another file, and return it as a memory stream
                    var text       = reader.ReadToEnd();
                    var layoutFile = Path.Combine(Path.GetTempPath(), this.filename + ".layout.dot");
                    File.WriteAllBytes(layoutFile, Encoding.UTF8.GetBytes(text));
                    return(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(text))));
                }
            }
        }
Exemple #2
0
        public TextReader Run(Action <TextWriter> writeGraph, string format, Graphs.LayoutEngine engine = Graphs.LayoutEngine.Dot)
        {
            var process = new Process();

            try
            {
                process.StartInfo = new ProcessStartInfo
                {
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    Arguments              = $"-T{format} -K{engine.ToString().ToLowerInvariant()}",
                    FileName               = Path.Combine(DotExecutablePath, DotExecutable),
                    RedirectStandardOutput = true,
                    RedirectStandardInput  = true
                };
                process.Start();
                process.StandardInput.AutoFlush = true;
                writeGraph(process.StandardInput);
                process.StandardInput.Close();
                return(process.StandardOutput);
            }
            catch (Exception ex)
            {
                var msg = string.Format(
                    "An exception occurred in DotExeRunner.RunDot(Action<StreamWriter>)." +
                    "Check if you have GrahpViz installed on your machine. " +
                    "Check that the folder where file 'dot.exe' is (part of GraphViz installation) is " +
                    "either in the system PATH variable or you must set it as value of the DotExecutablePath property." +
                    "Original exception type {0} and message: {1}",
                    ex.GetType().Name,
                    ex.Message);
                throw new Exception(msg, ex);
            }
            finally
            {
                process.Dispose();
            }
        }
Exemple #3
0
 public TextReader RunDot(Action <TextWriter> writeGraph, Graphs.LayoutEngine engine = Graphs.LayoutEngine.Dot)
 {
     return(Run(writeGraph, "dot", engine));
 }