public Create ( string diagramText, string diagramName ) : Image | ||
diagramText | string | |
diagramName | string | |
return | Image |
public Image Create(string diagramText, string diagramName)
{
try
{
Process process = new Process
{
StartInfo =
{
FileName = _javaPath,
Arguments = _invocation.ToString(),
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
},
EnableRaisingEvents = true
};
Logger("Invoking plantuml - Diagram: {0}, FileName: {1}, Arguments: {2}".FormatWith(diagramName, process.StartInfo.FileName, process.StartInfo.Arguments));
bool started = process.Start();
if (started)
{
process.StandardInput.Write(diagramText);
process.StandardInput.Close();
if (process.StandardOutput.BaseStream == null)
throw new NPlantException("While invoking plant uml, the standard output was empty. Error out: {0}".FormatWith(process.StandardError.ReadToEnd()));
return Image.FromStream(process.StandardOutput.BaseStream);
}
Logger("Failed to start plantuml");
return null;
}
catch (Exception ex)
{
Logger("Unhandled exception occurred while invoking plantuml: " + ex);
if (ex.IsDontMessWithMeException())
throw;
string message = CreateException(ex);
throw new NPlantException(message, ex);
}
}
private void RunGenerateDiagramImagesStage(FileSystemInfo outputDirectory, IEnumerable <DiscoveredDiagram> diagrams, IRunnerRecorder recorder) { recorder.Log("Starting Stage: Diagram Rendering (output={0})...".FormatWith(outputDirectory.FullName)); foreach (var diagram in diagrams) { var text = BufferedClassDiagramGenerator.GetDiagramText(diagram.Diagram); var javaPath = _options.JavaPath ?? "java.exe"; var plantUml = _options.PlantUml ?? Assembly.GetExecutingAssembly().Location; var npImage = new NPlantImage(javaPath, new PlantUmlInvocation(plantUml)) { Logger = recorder.Log }; var image = npImage.Create(text, diagram.Diagram.Name); if (image != null) { string dir = outputDirectory.FullName; dir = Categorize(diagram, dir); var fileName = diagram.Diagram.Name.ReplaceIllegalPathCharacters('_'); image.SaveNPlantImage(dir, fileName); } } recorder.Log("Finished Stage: Diagram Rendering..."); }