/// <summary> /// Render the given GraphViz code into an image /// </summary> /// <param name="dotSourceText"></param> /// <param name="returnType"></param> /// <returns></returns> private byte[] RenderGraph(string dotSourceText, GvOutputFormat returnType) { _errorsList.Clear(); byte[] output = null; var processStartInfo = GetProcessStartInfo(returnType.Name); using (var process = Process.Start(processStartInfo)) if (ReferenceEquals(process, null) == false) { process.ErrorDataReceived += ErrorDataHandler; process.BeginErrorReadLine(); using (var stdIn = process.StandardInput) { stdIn.WriteLine(dotSourceText); } using (var stdOut = process.StandardOutput) { output = ReadFullStream(stdOut.BaseStream); } } return(output); }
/// <summary> /// Render the given GraphViz code and save it to file. /// </summary> /// <param name="dotSourceText"></param> /// <param name="returnType"></param> /// <param name="filePath"></param> /// <returns></returns> public bool RenderToFile(string dotSourceText, GvOutputFormat returnType, string filePath) { var byteArray = RenderGraph(dotSourceText, returnType); if (byteArray.Length == 0) { return(false); } try { File.WriteAllBytes(filePath, byteArray); } catch (Exception e) { _errorsList.Add(e.Message); return(false); } return(true); }