Skip to content

Commit 0ca4b43

Browse files
authored
Merge pull request #1924 from paulvanbrenk/preClean
Clean up to prepare for unit test changes
2 parents cb33da5 + d6e36c8 commit 0ca4b43

File tree

15 files changed

+94
-168
lines changed

15 files changed

+94
-168
lines changed

Common/Product/SharedProject/ProcessOutput.cs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public virtual bool CloseStandardInput()
6565
/// </summary>
6666
internal sealed class ProcessOutput : IDisposable
6767
{
68-
private readonly Process process;
6968
private readonly string arguments;
7069
private readonly List<string> output, error;
7170
private ManualResetEvent waitHandleEvent;
@@ -409,30 +408,30 @@ private ProcessOutput(Process process, Redirector redirector)
409408
this.error = new List<string>();
410409
}
411410

412-
this.process = process;
413-
if (this.process.StartInfo.RedirectStandardOutput)
411+
this.Process = process;
412+
if (this.Process.StartInfo.RedirectStandardOutput)
414413
{
415-
this.process.OutputDataReceived += this.OnOutputDataReceived;
414+
this.Process.OutputDataReceived += this.OnOutputDataReceived;
416415
}
417-
if (this.process.StartInfo.RedirectStandardError)
416+
if (this.Process.StartInfo.RedirectStandardError)
418417
{
419-
this.process.ErrorDataReceived += this.OnErrorDataReceived;
418+
this.Process.ErrorDataReceived += this.OnErrorDataReceived;
420419
}
421420

422-
if (!this.process.StartInfo.RedirectStandardOutput && !this.process.StartInfo.RedirectStandardError)
421+
if (!this.Process.StartInfo.RedirectStandardOutput && !this.Process.StartInfo.RedirectStandardError)
423422
{
424423
// If we are receiving output events, we signal that the process
425424
// has exited when one of them receives null. Otherwise, we have
426425
// to listen for the Exited event.
427426
// If we just listen for the Exited event, we may receive it
428427
// before all the output has arrived.
429-
this.process.Exited += this.OnExited;
428+
this.Process.Exited += this.OnExited;
430429
}
431-
this.process.EnableRaisingEvents = true;
430+
this.Process.EnableRaisingEvents = true;
432431

433432
try
434433
{
435-
this.process.Start();
434+
this.Process.Start();
436435
}
437436
catch (Exception ex)
438437
{
@@ -451,28 +450,28 @@ private ProcessOutput(Process process, Redirector redirector)
451450
{
452451
this.error.AddRange(SplitLines(ex.ToString()));
453452
}
454-
this.process = null;
453+
this.Process = null;
455454
}
456455

457-
if (this.process != null)
456+
if (this.Process != null)
458457
{
459-
if (this.process.StartInfo.RedirectStandardOutput)
458+
if (this.Process.StartInfo.RedirectStandardOutput)
460459
{
461-
this.process.BeginOutputReadLine();
460+
this.Process.BeginOutputReadLine();
462461
}
463-
if (this.process.StartInfo.RedirectStandardError)
462+
if (this.Process.StartInfo.RedirectStandardError)
464463
{
465-
this.process.BeginErrorReadLine();
464+
this.Process.BeginErrorReadLine();
466465
}
467466

468-
if (this.process.StartInfo.RedirectStandardInput)
467+
if (this.Process.StartInfo.RedirectStandardInput)
469468
{
470469
// Close standard input so that we don't get stuck trying to read input from the user.
471470
if (this.redirector == null || (this.redirector != null && this.redirector.CloseStandardInput()))
472471
{
473472
try
474473
{
475-
this.process.StandardInput.Close();
474+
this.Process.StandardInput.Close();
476475
}
477476
catch (InvalidOperationException)
478477
{
@@ -496,11 +495,11 @@ private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
496495
lock (this.seenNullLock)
497496
{
498497
this.seenNullInOutput = true;
499-
shouldExit = this.seenNullInError || !this.process.StartInfo.RedirectStandardError;
498+
shouldExit = this.seenNullInError || !this.Process.StartInfo.RedirectStandardError;
500499
}
501500
if (shouldExit)
502501
{
503-
OnExited(this.process, EventArgs.Empty);
502+
OnExited(this.Process, EventArgs.Empty);
504503
}
505504
}
506505
else if (!string.IsNullOrEmpty(e.Data))
@@ -532,11 +531,11 @@ private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
532531
lock (this.seenNullLock)
533532
{
534533
this.seenNullInError = true;
535-
shouldExit = this.seenNullInOutput || !this.process.StartInfo.RedirectStandardOutput;
534+
shouldExit = this.seenNullInOutput || !this.Process.StartInfo.RedirectStandardOutput;
536535
}
537536
if (shouldExit)
538537
{
539-
OnExited(this.process, EventArgs.Empty);
538+
OnExited(this.Process, EventArgs.Empty);
540539
}
541540
}
542541
else if (!string.IsNullOrEmpty(e.Data))
@@ -555,7 +554,9 @@ private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
555554
}
556555
}
557556

558-
public int? ProcessId => this.IsStarted ? this.process.Id : (int?)null;
557+
public int? ProcessId => this.IsStarted ? this.Process.Id : (int?)null;
558+
559+
public Process Process { get; }
559560

560561
/// <summary>
561562
/// The arguments that were originally passed, including the filename.
@@ -565,7 +566,7 @@ private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
565566
/// <summary>
566567
/// True if the process started. False if an error occurred.
567568
/// </summary>
568-
public bool IsStarted => this.process != null;
569+
public bool IsStarted => this.Process != null;
569570

570571
/// <summary>
571572
/// The exit code or null if the process never started or has not
@@ -575,11 +576,11 @@ public int? ExitCode
575576
{
576577
get
577578
{
578-
if (this.process == null || !this.process.HasExited)
579+
if (this.Process == null || !this.Process.HasExited)
579580
{
580581
return null;
581582
}
582-
return this.process.ExitCode;
583+
return this.Process.ExitCode;
583584
}
584585
}
585586

@@ -590,11 +591,11 @@ public ProcessPriorityClass PriorityClass
590591
{
591592
get
592593
{
593-
if (this.process != null && !this.process.HasExited)
594+
if (this.Process != null && !this.Process.HasExited)
594595
{
595596
try
596597
{
597-
return this.process.PriorityClass;
598+
return this.Process.PriorityClass;
598599
}
599600
catch (Win32Exception)
600601
{
@@ -609,11 +610,11 @@ public ProcessPriorityClass PriorityClass
609610
}
610611
set
611612
{
612-
if (this.process != null && !this.process.HasExited)
613+
if (this.Process != null && !this.Process.HasExited)
613614
{
614615
try
615616
{
616-
this.process.PriorityClass = value;
617+
this.Process.PriorityClass = value;
617618
}
618619
catch (Win32Exception)
619620
{
@@ -640,34 +641,34 @@ public void WriteInputLine(string line)
640641
{
641642
if (IsStarted && redirector != null && !redirector.CloseStandardInput())
642643
{
643-
process.StandardInput.WriteLine(line);
644-
process.StandardInput.Flush();
644+
Process.StandardInput.WriteLine(line);
645+
Process.StandardInput.Flush();
645646
}
646647
}
647648

648649
private void FlushAndCloseOutput()
649650
{
650-
if (this.process == null)
651+
if (this.Process == null)
651652
{
652653
return;
653654
}
654655

655-
if (this.process.StartInfo.RedirectStandardOutput)
656+
if (this.Process.StartInfo.RedirectStandardOutput)
656657
{
657658
try
658659
{
659-
this.process.CancelOutputRead();
660+
this.Process.CancelOutputRead();
660661
}
661662
catch (InvalidOperationException)
662663
{
663664
// Reader has already been cancelled
664665
}
665666
}
666-
if (this.process.StartInfo.RedirectStandardError)
667+
if (this.Process.StartInfo.RedirectStandardError)
667668
{
668669
try
669670
{
670-
this.process.CancelErrorRead();
671+
this.Process.CancelErrorRead();
671672
}
672673
catch (InvalidOperationException)
673674
{
@@ -706,7 +707,7 @@ public WaitHandle WaitHandle
706707
{
707708
get
708709
{
709-
if (this.process == null)
710+
if (this.Process == null)
710711
{
711712
return null;
712713
}
@@ -725,9 +726,9 @@ public WaitHandle WaitHandle
725726
/// </summary>
726727
public void Wait()
727728
{
728-
if (this.process != null)
729+
if (this.Process != null)
729730
{
730-
this.process.WaitForExit();
731+
this.Process.WaitForExit();
731732
// Should have already been called, in which case this is a no-op
732733
OnExited(this, EventArgs.Empty);
733734
}
@@ -742,9 +743,9 @@ public void Wait()
742743
/// </returns>
743744
public bool Wait(TimeSpan timeout)
744745
{
745-
if (this.process != null)
746+
if (this.Process != null)
746747
{
747-
var exited = this.process.WaitForExit((int)timeout.TotalMilliseconds);
748+
var exited = this.Process.WaitForExit((int)timeout.TotalMilliseconds);
748749
if (exited)
749750
{
750751
// Should have already been called, in which case this is a no-op
@@ -762,18 +763,18 @@ public TaskAwaiter<int> GetAwaiter()
762763
{
763764
if (this.awaiter == null)
764765
{
765-
if (this.process == null)
766+
if (this.Process == null)
766767
{
767768
var tcs = new TaskCompletionSource<int>();
768769
tcs.SetCanceled();
769770
this.awaiter = tcs.Task;
770771
}
771-
else if (this.process.HasExited)
772+
else if (this.Process.HasExited)
772773
{
773774
// Should have already been called, in which case this is a no-op
774775
OnExited(this, EventArgs.Empty);
775776
var tcs = new TaskCompletionSource<int>();
776-
tcs.SetResult(this.process.ExitCode);
777+
tcs.SetResult(this.Process.ExitCode);
777778
this.awaiter = tcs.Task;
778779
}
779780
else
@@ -788,7 +789,7 @@ public TaskAwaiter<int> GetAwaiter()
788789
{
789790
throw new OperationCanceledException();
790791
}
791-
return this.process.ExitCode;
792+
return this.Process.ExitCode;
792793
});
793794
}
794795
}
@@ -801,9 +802,9 @@ public TaskAwaiter<int> GetAwaiter()
801802
/// </summary>
802803
public void Kill()
803804
{
804-
if (this.process != null && !this.process.HasExited)
805+
if (this.Process != null && !this.Process.HasExited)
805806
{
806-
this.process.Kill();
807+
this.Process.Kill();
807808
// Should have already been called, in which case this is a no-op
808809
OnExited(this, EventArgs.Empty);
809810
}
@@ -837,17 +838,17 @@ public void Dispose()
837838
if (!this.isDisposed)
838839
{
839840
this.isDisposed = true;
840-
if (this.process != null)
841+
if (this.Process != null)
841842
{
842-
if (this.process.StartInfo.RedirectStandardOutput)
843+
if (this.Process.StartInfo.RedirectStandardOutput)
843844
{
844-
this.process.OutputDataReceived -= this.OnOutputDataReceived;
845+
this.Process.OutputDataReceived -= this.OnOutputDataReceived;
845846
}
846-
if (this.process.StartInfo.RedirectStandardError)
847+
if (this.Process.StartInfo.RedirectStandardError)
847848
{
848-
this.process.ErrorDataReceived -= this.OnErrorDataReceived;
849+
this.Process.ErrorDataReceived -= this.OnErrorDataReceived;
849850
}
850-
this.process.Dispose();
851+
this.Process.Dispose();
851852
}
852853
if (this.redirector is IDisposable disp)
853854
{

Nodejs/Product/Nodejs/Jade/Outlining/IndentBasedRegionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private static int GetLineIndent(ITextSnapshotLine line)
160160
for (int i = line.Start; i < line.End; i++)
161161
{
162162
var ch = line.Snapshot.GetText(i, 1)[0];
163-
if (!Char.IsWhiteSpace(ch))
163+
if (!char.IsWhiteSpace(ch))
164164
{
165165
return i - line.Start;
166166
}

Nodejs/Product/Nodejs/Jade/TextProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public int IndexOf(string text, ITextRange range, bool ignoreCase)
9191

9292
if (ignoreCase)
9393
{
94-
ch1 = Char.ToLowerInvariant(ch1);
95-
ch2 = Char.ToLowerInvariant(ch2);
94+
ch1 = char.ToLowerInvariant(ch1);
95+
ch2 = char.ToLowerInvariant(ch2);
9696
}
9797

9898
if (ch1 != ch2)

Nodejs/Product/Nodejs/Jade/Tokenizer/JadeTokenizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected override ITextRange HandleString(bool addToken = true)
146146
break;
147147
}
148148

149-
if (this._cs.CurrentChar == '<' && (this._cs.NextChar == '/' || Char.IsLetter(this._cs.NextChar)))
149+
if (this._cs.CurrentChar == '<' && (this._cs.NextChar == '/' || char.IsLetter(this._cs.NextChar)))
150150
{
151151
if (this._cs.Position > start)
152152
{

Nodejs/Product/Nodejs/Jade/Tokenizer/States/HtmlState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal partial class JadeTokenizer : Tokenizer<JadeToken>
1010
// plain text with possible #{foo} variable references
1111
private void OnHtml()
1212
{
13-
Debug.Assert(this._cs.CurrentChar == '<' && (this._cs.NextChar == '/' || Char.IsLetter(this._cs.NextChar)));
13+
Debug.Assert(this._cs.CurrentChar == '<' && (this._cs.NextChar == '/' || char.IsLetter(this._cs.NextChar)));
1414

1515
var length = this._cs.NextChar == '/' ? 2 : 1;
1616
AddToken(JadeTokenType.AngleBracket, this._cs.Position, length);

Nodejs/Product/Nodejs/Jade/Tokenizer/States/TagState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void OnTag()
7171

7272
while (!this._cs.IsWhiteSpace() && !this._cs.IsEndOfStream())
7373
{
74-
if (this._cs.CurrentChar == '.' && Char.IsWhiteSpace(this._cs.NextChar))
74+
if (this._cs.CurrentChar == '.' && char.IsWhiteSpace(this._cs.NextChar))
7575
{
7676
// If this is last ., then what follows is a text literal
7777
if (StringComparer.OrdinalIgnoreCase.Equals(ident, "script"))
@@ -115,7 +115,7 @@ private void OnTag()
115115
selectorRange.Length
116116
);
117117

118-
if (Char.IsWhiteSpace(this._cs.CurrentChar) && this._cs.LookAhead(-1) == '.')
118+
if (char.IsWhiteSpace(this._cs.CurrentChar) && this._cs.LookAhead(-1) == '.')
119119
{
120120
this._cs.Position--;
121121
}

Nodejs/Product/Nodejs/Jade/Tokenizer/States/TextState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private void OnText(bool strings, bool html, bool entities)
2828
{
2929
HandleString();
3030
}
31-
else if (this._cs.CurrentChar == '<' && (this._cs.NextChar == '/' || Char.IsLetter(this._cs.NextChar)) && html)
31+
else if (this._cs.CurrentChar == '<' && (this._cs.NextChar == '/' || char.IsLetter(this._cs.NextChar)) && html)
3232
{
3333
OnHtml();
3434
}

0 commit comments

Comments
 (0)