예제 #1
0
        private void RunGraphViz(string dotFile, string imageFile, LayoutEngine layoutEngine, string outputFomat)
        {
            if (!Directory.Exists(_graphVizFolder))
            {
                throw new DirectoryNotFoundException("Please install GraphViz and asign the installation folder!");
            }

            var prop = new ProcessStartInfo
            {
                FileName               = Path.Combine(_graphVizFolder, layoutEngine.ToString() + ".exe"),
                Arguments              = "-" + outputFomat + " \"" + dotFile + "\" -o \"" + imageFile + "\"",
                WindowStyle            = ProcessWindowStyle.Hidden,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            Process process = Process.Start(prop);

            string errorText = process.StandardError.ReadToEnd();

            if (errorText != null && errorText.Contains("syntax error"))
            {
                throw new FormatException(errorText);
            }
            else if (errorText != null && errorText.Contains("Error:"))
            {
                throw new InvalidOperationException(errorText);
            }

            process.WaitForExit(120000);
        }
예제 #2
0
        public void AddLayout(Graph graphObject, LayoutEngine layoutEngine)
        {
            Arguments.NotNull(graphObject, nameof(graphObject));

            this.ThrowIfDisposed();

            var funcRet = NativeMethods.gvLayout(this.graphvizContextPtr, graphObject.SafeHandle, layoutEngine.ToString().ToLowerInvariant().ToCharArray());

            var errorCode = Marshal.GetLastWin32Error();

            this.Logger.Debug("gvLayout({0},{1},{2}):{3}", this.graphvizContextPtr, graphObject.SafeHandle, layoutEngine.ToString().ToLowerInvariant(), funcRet);

            if (funcRet != NativeMethods.SUCCESS)
            {
                this.Logger.Error("gvLayout:{0}  Win32ErrorCode:{1}", funcRet, errorCode);
                throw new GraphvizApiException("error");
            }

            this.graph = graphObject;
        }