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);
}
}