Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sm6srw committed Nov 23, 2020
1 parent 8a63d91 commit 824f785
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions src/DynamoUtilities/Md2Html.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,6 @@ internal class Md2Html : IDisposable
{
private readonly Process process = new Process();
private bool started;
/// <summary>
/// Constructor
/// Start the CLI tool and keep it around
/// </summary>
internal Md2Html()
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,

UseShellExecute = false,
Arguments = @"",
FileName = GetToolPath()
};

process.StartInfo = startInfo;
try
{
process.Start();
started = true;
}
catch(Win32Exception)
{
// Do nothing
}
}

/// <summary>
/// Kill the CLI tool, if still running
Expand Down Expand Up @@ -75,7 +47,7 @@ public void Dispose()
/// <returns>Returns converted markdown as html</returns>
internal string ParseMd2Html(string mdString, string mdPath)
{
if (!started)
if (!StartProcess())
{
return GetCantStartErrorMessage();
}
Expand Down Expand Up @@ -105,7 +77,7 @@ internal string ParseMd2Html(string mdString, string mdPath)
/// <returns>Returns Sanitized Html</returns>
internal string SanitizeHtml(string content)
{
if (!started)
if (!StartProcess())
{
return GetCantStartErrorMessage();
}
Expand Down Expand Up @@ -176,6 +148,40 @@ private static string GetToolPath ()
return toolPath;
}

/// <summary>
/// Start the CLI tool if not started and keep it around
/// <returns>Returns true if the process started or was running, false if the process failed to start.</returns>
/// </summary>
private bool StartProcess()
{
if (!started)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,

UseShellExecute = false,
Arguments = @"",
FileName = GetToolPath()
};

process.StartInfo = startInfo;
try
{
process.Start();
started = true;
}
catch (Win32Exception)
{
// Do nothing
}
}

return started;
}

/// <summary>
/// Kill the CLI tool - if running
/// </summary>
Expand Down

0 comments on commit 824f785

Please sign in to comment.