Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
Issue #36 - Yeoman generator output overrunning synchronous output bu…
Browse files Browse the repository at this point in the history
…gger; change output log to use async read methods for standard and error output.
  • Loading branch information
eshupps committed Jul 30, 2018
1 parent 2296022 commit be19d9a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
73 changes: 44 additions & 29 deletions Framework.VSIX/FrameworkProjectWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Resources;
using Framework.VSIX.Resources;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.DataContracts;
Expand Down Expand Up @@ -56,51 +57,65 @@ public void ProjectFinishedGenerating(Project project)
proc.StartInfo.WorkingDirectory = genDir;
proc.StartInfo.FileName = @"cmd.exe";

Task<string> outTask = null;
Task<string> errTask = null;

if (showWindow == false)
{
proc.StartInfo.Arguments = string.Format(@" /c {0}", commandString);
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();

proc.StandardInput.Flush();
proc.StandardInput.WriteLine("exit");
proc.StandardInput.Flush();

using (StreamReader reader = proc.StandardOutput)
{
string result = reader.ReadToEnd();
outputText.Append(result);
}

using (StreamReader reader = proc.StandardError)
{
string result = reader.ReadToEnd();
outputText.Append(result);
}
try
{
proc.StartInfo.Arguments = string.Format(@" /c {0}", commandString);
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();

proc.StandardInput.Flush();
proc.StandardInput.WriteLine("exit");
proc.StandardInput.Flush();

outTask = Task.Run(() => proc.StandardOutput.ReadToEndAsync());
errTask = Task.Run(() => proc.StandardError.ReadToEndAsync());
}
catch (System.Exception ex)
{
//TODO: Log Error
}
}
else
{
proc.StartInfo.Arguments = string.Format(@" /k {0}", commandString);
proc.Start();
}

proc.WaitForExit();

proc.WaitForExit();
if (showWindow == false)
{
outputText.Append(outTask.Result);
outputText.Append(errTask.Result);
}

using (StreamWriter sw = File.AppendText(logFile))
{
sw.Write(outputText);
}
}

telemetry.TrackEvent("project-wizard", telProps, null);
// Allow some time for flushing before shutdown.
telemetry.Flush();
System.Threading.Thread.Sleep(1000);
try
{
telemetry.TrackEvent("project-wizard", telProps, null);
// Allow some time for flushing before shutdown.
telemetry.Flush();
System.Threading.Thread.Sleep(1000);
}
catch (System.Exception ex)
{
//TODO: Log error
}

string[] files = Directory.GetFiles(projectDir, "*.*", SearchOption.AllDirectories);

Expand Down
2 changes: 1 addition & 1 deletion Framework.VSIX/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="SharePoint.Framework.VSIX.94e9564e-67da-422c-b02b-501e2f45147a" Version="1.5.1.1" Language="en-US" Publisher="SharePoint PnP" />
<Identity Id="SharePoint.Framework.VSIX.94e9564e-67da-422c-b02b-501e2f45147a" Version="1.5.1.2" Language="en-US" Publisher="SharePoint PnP" />
<DisplayName>SPFx Project Template</DisplayName>
<Description xml:space="preserve">New SharePoint Framework Project.</Description>
<MoreInfo>https://github.com/SharePoint/sp-dev-fx-vs-extension</MoreInfo>
Expand Down

0 comments on commit be19d9a

Please sign in to comment.