Exemple #1
0
 public async Task RunAsync(Graph graph, Stream outputStream, RendererLayouts layout, RendererFormats format, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     var fileName = Path.Combine(graphvizBin, GetRendererLayoutExecutable(layout));
     var arguments = GetRendererFormatArgument(format);
     var startInfo = new ProcessStartInfo
     {
         FileName = fileName,
         Arguments = arguments,
         UseShellExecute = false,
         CreateNoWindow = true,
         RedirectStandardInput = true,
         RedirectStandardOutput = true,
         RedirectStandardError = true
     };
     var tcs = new TaskCompletionSource<object>();
     using (var process = Process.Start(startInfo))
     {
         cancellationToken.ThrowIfCancellationRequested();
         cancellationToken.Register(() =>
         {
             tcs.TrySetCanceled();
             process.CloseMainWindow();
         });
         using (var standardInput = process.StandardInput)
         {
             graph.WriteTo(standardInput);
         }
         using (var standardOutput = process.StandardOutput)
         {
             await Task.WhenAny(tcs.Task, standardOutput.BaseStream.CopyToAsync(outputStream, 4096, cancellationToken));
         }
     }
     cancellationToken.ThrowIfCancellationRequested();
 }
Exemple #2
0
 private static string GetRendererLayoutExecutable(RendererLayouts layout)
 {
     switch (layout)
     {
         case RendererLayouts.Dot:
             return "dot.exe";
         default:
             throw new ArgumentOutOfRangeException("layout");
     }
 }
Exemple #3
0
        private static string GetRendererLayoutExecutable(RendererLayouts layout)
        {
            switch (layout)
            {
            case RendererLayouts.Dot:
                return("dot.exe");

            default:
                throw new ArgumentOutOfRangeException("layout");
            }
        }
Exemple #4
0
        public async Task RunAsync(Graph graph, Stream outputStream, RendererLayouts layout, RendererFormats format, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var fileName  = Path.Combine(graphvizBin, GetRendererLayoutExecutable(layout));
            var arguments = GetRendererFormatArgument(format);
            var startInfo = new ProcessStartInfo
            {
                FileName               = fileName,
                Arguments              = arguments,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };
            var tcs = new TaskCompletionSource <object>();

            using (var process = Process.Start(startInfo))
            {
                cancellationToken.ThrowIfCancellationRequested();
                cancellationToken.Register(() =>
                {
                    tcs.TrySetCanceled();
                    process.CloseMainWindow();
                });

                using (var sw = new StreamWriter("rendererOutput.txt", false))
                {
                    using (var standardInput = process.StandardInput)
                    {
                        graph.WriteTo(standardInput);
                        graph.WriteTo(sw);
                    }
                }

                using (var standardOutput = process.StandardOutput)
                {
                    await Task.WhenAny(tcs.Task, standardOutput.BaseStream.CopyToAsync(outputStream, 4096, cancellationToken));
                }
            }
            cancellationToken.ThrowIfCancellationRequested();
        }