From 6f5774f03175b881c2a887c6ea884f53aa9956a6 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 00:48:08 -0400
Subject: [PATCH 01/11] :recycle: Rename parameter set constants
---
.../management/TestConnectionCommand.cs | 104 +++++++++---------
1 file changed, 52 insertions(+), 52 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 19974c8891b..8d55985661e 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -16,57 +16,57 @@ namespace Microsoft.PowerShell.Commands
///
/// The implementation of the "Test-Connection" cmdlet.
///
- [Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = ParameterSetPingCount, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
- [OutputType(typeof(PingReport), ParameterSetName = new string[] { ParameterSetPingCount })]
- [OutputType(typeof(PingReply), ParameterSetName = new string[] { ParameterSetPingContinues, ParameterSetDetectionOfMTUSize })]
- [OutputType(typeof(bool), ParameterSetName = new string[] { ParameterSetPingCount, ParameterSetPingContinues, ParameterSetConnectionByTCPPort })]
- [OutputType(typeof(Int32), ParameterSetName = new string[] { ParameterSetDetectionOfMTUSize })]
- [OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { ParameterSetTraceRoute })]
+ [Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
+ [OutputType(typeof(PingReport), ParameterSetName = new string[] { DefaultPingSet })]
+ [OutputType(typeof(PingReply), ParameterSetName = new string[] { RepeatPingSet, MtuSizeDetectSet })]
+ [OutputType(typeof(bool), ParameterSetName = new string[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
+ [OutputType(typeof(Int32), ParameterSetName = new string[] { MtuSizeDetectSet })]
+ [OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { TraceRouteSet })]
public class TestConnectionCommand : PSCmdlet
{
- private const string ParameterSetPingCount = "PingCount";
- private const string ParameterSetPingContinues = "PingContinues";
- private const string ParameterSetTraceRoute = "TraceRoute";
- private const string ParameterSetConnectionByTCPPort = "ConnectionByTCPPort";
- private const string ParameterSetDetectionOfMTUSize = "DetectionOfMTUSize";
+ private const string DefaultPingSet = "PingCount";
+ private const string RepeatPingSet = "PingContinues";
+ private const string TraceRouteSet = "TraceRoute";
+ private const string TcpPortSet = "ConnectionByTCPPort";
+ private const string MtuSizeDetectSet = "DetectionOfMTUSize";
#region Parameters
///
/// Do ping test.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
public SwitchParameter Ping { get; set; } = true;
///
/// Force using IPv4 protocol.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
- [Parameter(ParameterSetName = ParameterSetTraceRoute)]
- [Parameter(ParameterSetName = ParameterSetDetectionOfMTUSize)]
- [Parameter(ParameterSetName = ParameterSetConnectionByTCPPort)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = TraceRouteSet)]
+ [Parameter(ParameterSetName = MtuSizeDetectSet)]
+ [Parameter(ParameterSetName = TcpPortSet)]
public SwitchParameter IPv4 { get; set; }
///
/// Force using IPv6 protocol.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
- [Parameter(ParameterSetName = ParameterSetTraceRoute)]
- [Parameter(ParameterSetName = ParameterSetDetectionOfMTUSize)]
- [Parameter(ParameterSetName = ParameterSetConnectionByTCPPort)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = TraceRouteSet)]
+ [Parameter(ParameterSetName = MtuSizeDetectSet)]
+ [Parameter(ParameterSetName = TcpPortSet)]
public SwitchParameter IPv6 { get; set; }
///
/// Do reverse DNS lookup to get names for IP addresses.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
- [Parameter(ParameterSetName = ParameterSetTraceRoute)]
- [Parameter(ParameterSetName = ParameterSetDetectionOfMTUSize)]
- [Parameter(ParameterSetName = ParameterSetConnectionByTCPPort)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = TraceRouteSet)]
+ [Parameter(ParameterSetName = MtuSizeDetectSet)]
+ [Parameter(ParameterSetName = TcpPortSet)]
public SwitchParameter ResolveDestination { get; set; }
///
@@ -74,10 +74,10 @@ public class TestConnectionCommand : PSCmdlet
/// The default is Local Host.
/// Remoting is not yet implemented internally in the cmdlet.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
- [Parameter(ParameterSetName = ParameterSetTraceRoute)]
- [Parameter(ParameterSetName = ParameterSetConnectionByTCPPort)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = TraceRouteSet)]
+ [Parameter(ParameterSetName = TcpPortSet)]
public string Source { get; } = Dns.GetHostName();
///
@@ -86,9 +86,9 @@ public class TestConnectionCommand : PSCmdlet
/// they decrement the Time-to-Live (TTL) value found in the packet header.
/// The default (from Windows) is 128 hops.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
- [Parameter(ParameterSetName = ParameterSetTraceRoute)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = TraceRouteSet)]
[ValidateRange(0, sMaxHops)]
[Alias("Ttl", "TimeToLive", "Hops")]
public int MaxHops { get; set; } = sMaxHops;
@@ -99,7 +99,7 @@ public class TestConnectionCommand : PSCmdlet
/// Count of attempts.
/// The default (from Windows) is 4 times.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
[ValidateRange(ValidateRangeKind.Positive)]
public int Count { get; set; } = 4;
@@ -107,8 +107,8 @@ public class TestConnectionCommand : PSCmdlet
/// Delay between attempts.
/// The default (from Windows) is 1 second.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
[ValidateRange(ValidateRangeKind.Positive)]
public int Delay { get; set; } = 1;
@@ -117,8 +117,8 @@ public class TestConnectionCommand : PSCmdlet
/// The default (from Windows) is 32 bites.
/// Max value is 65500 (limit from Windows API).
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
[Alias("Size", "Bytes", "BS")]
[ValidateRange(0, 65500)]
public int BufferSize { get; set; } = DefaultSendBufferSize;
@@ -127,15 +127,15 @@ public class TestConnectionCommand : PSCmdlet
/// Don't fragment ICMP packages.
/// Currently CoreFX not supports this on Unix.
///
- [Parameter(ParameterSetName = ParameterSetPingCount)]
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
+ [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
public SwitchParameter DontFragment { get; set; }
///
/// Continue ping until user press Ctrl-C
/// or Int.MaxValue threshold reached.
///
- [Parameter(ParameterSetName = ParameterSetPingContinues)]
+ [Parameter(ParameterSetName = RepeatPingSet)]
public SwitchParameter Continues { get; set; }
///
@@ -169,20 +169,20 @@ public class TestConnectionCommand : PSCmdlet
///
/// Detect MTU size.
///
- [Parameter(Mandatory = true, ParameterSetName = ParameterSetDetectionOfMTUSize)]
+ [Parameter(Mandatory = true, ParameterSetName = MtuSizeDetectSet)]
public SwitchParameter MTUSizeDetect { get; set; }
///
/// Do traceroute test.
///
- [Parameter(Mandatory = true, ParameterSetName = ParameterSetTraceRoute)]
+ [Parameter(Mandatory = true, ParameterSetName = TraceRouteSet)]
public SwitchParameter Traceroute { get; set; }
///
/// Do tcp connection test.
///
[ValidateRange(0, 65535)]
- [Parameter(Mandatory = true, ParameterSetName = ParameterSetConnectionByTCPPort)]
+ [Parameter(Mandatory = true, ParameterSetName = TcpPortSet)]
public int TCPPort { get; set; }
#endregion Parameters
@@ -196,7 +196,7 @@ protected override void BeginProcessing()
switch (ParameterSetName)
{
- case ParameterSetPingContinues:
+ case RepeatPingSet:
Count = int.MaxValue;
break;
}
@@ -211,17 +211,17 @@ protected override void ProcessRecord()
{
switch (ParameterSetName)
{
- case ParameterSetPingCount:
- case ParameterSetPingContinues:
+ case DefaultPingSet:
+ case RepeatPingSet:
ProcessPing(targetName);
break;
- case ParameterSetDetectionOfMTUSize:
+ case MtuSizeDetectSet:
ProcessMTUSize(targetName);
break;
- case ParameterSetTraceRoute:
+ case TraceRouteSet:
ProcessTraceroute(targetName);
break;
- case ParameterSetConnectionByTCPPort:
+ case TcpPortSet:
ProcessConnectionByTCPPort(targetName);
break;
}
From 897ec6eea5822b568895d45730d696f46282f202 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 00:49:35 -0400
Subject: [PATCH 02/11] :memo: Rename parameter sets
---
.../commands/management/TestConnectionCommand.cs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 8d55985661e..a0169ca9280 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -24,11 +24,11 @@ namespace Microsoft.PowerShell.Commands
[OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { TraceRouteSet })]
public class TestConnectionCommand : PSCmdlet
{
- private const string DefaultPingSet = "PingCount";
- private const string RepeatPingSet = "PingContinues";
+ private const string DefaultPingSet = "DefaultPing";
+ private const string RepeatPingSet = "RepeatPing";
private const string TraceRouteSet = "TraceRoute";
- private const string TcpPortSet = "ConnectionByTCPPort";
- private const string MtuSizeDetectSet = "DetectionOfMTUSize";
+ private const string TcpPortSet = "TcpPort";
+ private const string MtuSizeDetectSet = "MtuSizeDetect";
#region Parameters
From f02c95aedf6e9fa7493dc1d3eff13c2cd58032a5 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 00:59:39 -0400
Subject: [PATCH 03/11] :art: Whitespace style fixes
---
.../management/TestConnectionCommand.cs | 174 +++++++++++-------
1 file changed, 105 insertions(+), 69 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index a0169ca9280..400ae502e82 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -158,10 +158,11 @@ public class TestConnectionCommand : PSCmdlet
///
/// Destination - computer name or IP address.
///
- [Parameter(Mandatory = true,
- Position = 0,
- ValueFromPipeline = true,
- ValueFromPipelineByPropertyName = true)]
+ [Parameter(
+ Mandatory = true,
+ Position = 0,
+ ValueFromPipeline = true,
+ ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
[Alias("ComputerName")]
public string[] TargetName { get; set; }
@@ -292,10 +293,11 @@ private void WriteConnectionTestHeader(string resolvedTargetName, string targetA
private void WriteConnectionTestProgress(string targetNameOrAddress, string targetAddress, int timeout)
{
- var msg = StringUtil.Format(TestConnectionResources.ConnectionTestDescription,
- targetNameOrAddress,
- targetAddress,
- timeout);
+ var msg = StringUtil.Format(
+ TestConnectionResources.ConnectionTestDescription,
+ targetNameOrAddress,
+ targetAddress,
+ timeout);
ProgressRecord record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, msg);
WriteProgress(record);
}
@@ -350,14 +352,16 @@ private void ProcessTraceroute(String targetNameOrAddress)
}
catch (PingException ex)
{
- string message = StringUtil.Format(TestConnectionResources.NoPingResult,
- resolvedTargetName,
- ex.Message);
+ string message = StringUtil.Format(
+ TestConnectionResources.NoPingResult,
+ resolvedTargetName,
+ ex.Message);
Exception pingException = new System.Net.NetworkInformation.PingException(message, ex.InnerException);
- ErrorRecord errorRecord = new ErrorRecord(pingException,
- TestConnectionExceptionId,
- ErrorCategory.ResourceUnavailable,
- resolvedTargetName);
+ ErrorRecord errorRecord = new ErrorRecord(
+ pingException,
+ TestConnectionExceptionId,
+ ErrorCategory.ResourceUnavailable,
+ resolvedTargetName);
WriteError(errorRecord);
continue;
@@ -381,7 +385,9 @@ private void ProcessTraceroute(String targetNameOrAddress)
WriteTraceRouteProgress(traceRouteReply);
traceRouteResult.Replies.Add(traceRouteReply);
- } while (reply != null && currentHop <= sMaxHops && (reply.Status == IPStatus.TtlExpired || reply.Status == IPStatus.TimedOut));
+ } while (reply != null
+ && currentHop <= sMaxHops
+ && (reply.Status == IPStatus.TtlExpired || reply.Status == IPStatus.TimedOut));
WriteTraceRouteFooter();
@@ -397,7 +403,11 @@ private void ProcessTraceroute(String targetNameOrAddress)
private void WriteConsoleTraceRouteHeader(string resolvedTargetName, string targetAddress)
{
- _testConnectionProgressBarActivity = StringUtil.Format(TestConnectionResources.TraceRouteStart, resolvedTargetName, targetAddress, MaxHops);
+ _testConnectionProgressBarActivity = StringUtil.Format(
+ TestConnectionResources.TraceRouteStart,
+ resolvedTargetName,
+ targetAddress,
+ MaxHops);
WriteInformation(_testConnectionProgressBarActivity, s_PSHostTag);
@@ -412,15 +422,25 @@ private void WriteTraceRouteProgress(TraceRouteReply traceRouteReply)
{
string msg = string.Empty;
- if (traceRouteReply.PingReplies[2].Status == IPStatus.TtlExpired || traceRouteReply.PingReplies[2].Status == IPStatus.Success)
+ if (traceRouteReply.PingReplies[2].Status == IPStatus.TtlExpired
+ || traceRouteReply.PingReplies[2].Status == IPStatus.Success)
{
var routerAddress = traceRouteReply.ReplyRouterAddress.ToString();
var routerName = traceRouteReply.ReplyRouterName ?? routerAddress;
- var roundtripTime0 = traceRouteReply.PingReplies[0].Status == IPStatus.TimedOut ? "*" : traceRouteReply.PingReplies[0].RoundtripTime.ToString();
- var roundtripTime1 = traceRouteReply.PingReplies[1].Status == IPStatus.TimedOut ? "*" : traceRouteReply.PingReplies[1].RoundtripTime.ToString();
- msg = StringUtil.Format(TestConnectionResources.TraceRouteReply,
- traceRouteReply.Hop, roundtripTime0, roundtripTime1, traceRouteReply.PingReplies[2].RoundtripTime.ToString(),
- routerName, routerAddress);
+ var roundtripTime0 = traceRouteReply.PingReplies[0].Status == IPStatus.TimedOut
+ ? "*"
+ : traceRouteReply.PingReplies[0].RoundtripTime.ToString();
+ var roundtripTime1 = traceRouteReply.PingReplies[1].Status == IPStatus.TimedOut
+ ? "*"
+ : traceRouteReply.PingReplies[1].RoundtripTime.ToString();
+ msg = StringUtil.Format(
+ TestConnectionResources.TraceRouteReply,
+ traceRouteReply.Hop,
+ roundtripTime0,
+ roundtripTime1,
+ traceRouteReply.PingReplies[2].RoundtripTime.ToString(),
+ routerName,
+ routerAddress);
}
else
{
@@ -541,7 +561,11 @@ private void ProcessMTUSize(String targetNameOrAddress)
WriteMTUSizeProgress(CurrentMTUSize, retry);
- WriteDebug(StringUtil.Format("LowMTUSize: {0}, CurrentMTUSize: {1}, HighMTUSize: {2}", LowMTUSize, CurrentMTUSize, HighMTUSize));
+ WriteDebug(StringUtil.Format(
+ "LowMTUSize: {0}, CurrentMTUSize: {1}, HighMTUSize: {2}",
+ LowMTUSize,
+ CurrentMTUSize,
+ HighMTUSize));
reply = sender.Send(targetAddress, timeout, buffer, pingOptions);
@@ -562,14 +586,16 @@ private void ProcessMTUSize(String targetNameOrAddress)
// Target host don't reply - try again up to 'Count'.
if (retry >= Count)
{
- string message = StringUtil.Format(TestConnectionResources.NoPingResult,
- targetAddress,
- reply.Status.ToString());
+ string message = StringUtil.Format(
+ TestConnectionResources.NoPingResult,
+ targetAddress,
+ reply.Status.ToString());
Exception pingException = new System.Net.NetworkInformation.PingException(message);
- ErrorRecord errorRecord = new ErrorRecord(pingException,
- TestConnectionExceptionId,
- ErrorCategory.ResourceUnavailable,
- targetAddress);
+ ErrorRecord errorRecord = new ErrorRecord(
+ pingException,
+ TestConnectionExceptionId,
+ ErrorCategory.ResourceUnavailable,
+ targetAddress);
WriteError(errorRecord);
return;
}
@@ -590,10 +616,11 @@ private void ProcessMTUSize(String targetNameOrAddress)
{
string message = StringUtil.Format(TestConnectionResources.NoPingResult, targetAddress, ex.Message);
Exception pingException = new System.Net.NetworkInformation.PingException(message, ex.InnerException);
- ErrorRecord errorRecord = new ErrorRecord(pingException,
- TestConnectionExceptionId,
- ErrorCategory.ResourceUnavailable,
- targetAddress);
+ ErrorRecord errorRecord = new ErrorRecord(
+ pingException,
+ TestConnectionExceptionId,
+ ErrorCategory.ResourceUnavailable,
+ targetAddress);
WriteError(errorRecord);
return;
}
@@ -622,10 +649,11 @@ private void ProcessMTUSize(String targetNameOrAddress)
private void WriteMTUSizeHeader(string resolvedTargetName, string targetAddress)
{
- _testConnectionProgressBarActivity = StringUtil.Format(TestConnectionResources.MTUSizeDetectStart,
- resolvedTargetName,
- targetAddress,
- BufferSize);
+ _testConnectionProgressBarActivity = StringUtil.Format(
+ TestConnectionResources.MTUSizeDetectStart,
+ resolvedTargetName,
+ targetAddress,
+ BufferSize);
ProgressRecord record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace);
WriteProgress(record);
@@ -685,10 +713,11 @@ private void ProcessPing(String targetNameOrAddress)
{
string message = StringUtil.Format(TestConnectionResources.NoPingResult, resolvedTargetName, ex.Message);
Exception pingException = new System.Net.NetworkInformation.PingException(message, ex.InnerException);
- ErrorRecord errorRecord = new ErrorRecord(pingException,
- TestConnectionExceptionId,
- ErrorCategory.ResourceUnavailable,
- resolvedTargetName);
+ ErrorRecord errorRecord = new ErrorRecord(
+ pingException,
+ TestConnectionExceptionId,
+ ErrorCategory.ResourceUnavailable,
+ resolvedTargetName);
WriteError(errorRecord);
quietResult = false;
@@ -738,16 +767,18 @@ private void ProcessPing(String targetNameOrAddress)
private void WritePingHeader(string resolvedTargetName, string targetAddress)
{
- _testConnectionProgressBarActivity = StringUtil.Format(TestConnectionResources.MTUSizeDetectStart,
- resolvedTargetName,
- targetAddress,
- BufferSize);
+ _testConnectionProgressBarActivity = StringUtil.Format(
+ TestConnectionResources.MTUSizeDetectStart,
+ resolvedTargetName,
+ targetAddress,
+ BufferSize);
WriteInformation(_testConnectionProgressBarActivity, s_PSHostTag);
- ProgressRecord record = new ProgressRecord(s_ProgressId,
- _testConnectionProgressBarActivity,
- ProgressRecordSpace);
+ ProgressRecord record = new ProgressRecord(
+ s_ProgressId,
+ _testConnectionProgressBarActivity,
+ ProgressRecordSpace);
WriteProgress(record);
}
@@ -760,11 +791,12 @@ private void WritePingProgress(PingReply reply)
}
else
{
- msg = StringUtil.Format(TestConnectionResources.PingReply,
- reply.Address.ToString(),
- reply.Buffer.Length,
- reply.RoundtripTime,
- reply.Options?.Ttl);
+ msg = StringUtil.Format(
+ TestConnectionResources.PingReply,
+ reply.Address.ToString(),
+ reply.Buffer.Length,
+ reply.RoundtripTime,
+ reply.Options?.Ttl);
}
WriteInformation(msg, s_PSHostTag);
@@ -840,14 +872,16 @@ private bool InitProcessPing(String targetNameOrAddress, out string resolvedTarg
}
catch (Exception ex)
{
- string message = StringUtil.Format(TestConnectionResources.NoPingResult,
- resolvedTargetName,
- TestConnectionResources.CannotResolveTargetName);
+ string message = StringUtil.Format(
+ TestConnectionResources.NoPingResult,
+ resolvedTargetName,
+ TestConnectionResources.CannotResolveTargetName);
Exception pingException = new System.Net.NetworkInformation.PingException(message, ex);
- ErrorRecord errorRecord = new ErrorRecord(pingException,
- TestConnectionExceptionId,
- ErrorCategory.ResourceUnavailable,
- resolvedTargetName);
+ ErrorRecord errorRecord = new ErrorRecord(
+ pingException,
+ TestConnectionExceptionId,
+ ErrorCategory.ResourceUnavailable,
+ resolvedTargetName);
WriteError(errorRecord);
return false;
}
@@ -867,14 +901,16 @@ private bool InitProcessPing(String targetNameOrAddress, out string resolvedTarg
if (targetAddress == null)
{
- string message = StringUtil.Format(TestConnectionResources.NoPingResult,
- resolvedTargetName,
- TestConnectionResources.TargetAddressAbsent);
+ string message = StringUtil.Format(
+ TestConnectionResources.NoPingResult,
+ resolvedTargetName,
+ TestConnectionResources.TargetAddressAbsent);
Exception pingException = new System.Net.NetworkInformation.PingException(message, null);
- ErrorRecord errorRecord = new ErrorRecord(pingException,
- TestConnectionExceptionId,
- ErrorCategory.ResourceUnavailable,
- resolvedTargetName);
+ ErrorRecord errorRecord = new ErrorRecord(
+ pingException,
+ TestConnectionExceptionId,
+ ErrorCategory.ResourceUnavailable,
+ resolvedTargetName);
WriteError(errorRecord);
return false;
}
From a9db3c9e74d099e38e79238755ea45c6adf8f947 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 01:04:59 -0400
Subject: [PATCH 04/11] :art: Code analysis style pass
---
.../management/TestConnectionCommand.cs | 54 ++++++++++---------
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 400ae502e82..385661a0e85 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -233,9 +233,8 @@ protected override void ProcessRecord()
private void ProcessConnectionByTCPPort(String targetNameOrAddress)
{
- string resolvedTargetName = null;
- IPAddress targetAddress = null;
-
+ string resolvedTargetName;
+ IPAddress targetAddress;
if (!InitProcessPing(targetNameOrAddress, out resolvedTargetName, out targetAddress))
{
return;
@@ -304,8 +303,10 @@ private void WriteConnectionTestProgress(string targetNameOrAddress, string targ
private void WriteConnectionTestFooter()
{
- ProgressRecord record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace);
- record.RecordType = ProgressRecordType.Completed;
+ var record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace)
+ {
+ RecordType = ProgressRecordType.Completed
+ };
WriteProgress(record);
}
@@ -314,10 +315,10 @@ private void WriteConnectionTestFooter()
#region TracerouteTest
private void ProcessTraceroute(String targetNameOrAddress)
{
- string resolvedTargetName = null;
- IPAddress targetAddress = null;
byte[] buffer = GetSendBuffer(BufferSize);
+ string resolvedTargetName;
+ IPAddress targetAddress;
if (!InitProcessPing(targetNameOrAddress, out resolvedTargetName, out targetAddress))
{
return;
@@ -420,8 +421,7 @@ private void WriteConsoleTraceRouteHeader(string resolvedTargetName, string targ
private void WriteTraceRouteProgress(TraceRouteReply traceRouteReply)
{
- string msg = string.Empty;
-
+ string msg;
if (traceRouteReply.PingReplies[2].Status == IPStatus.TtlExpired
|| traceRouteReply.PingReplies[2].Status == IPStatus.Success)
{
@@ -457,8 +457,10 @@ private void WriteTraceRouteFooter()
{
WriteInformation(TestConnectionResources.TraceRouteComplete, s_PSHostTag);
- ProgressRecord record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace);
- record.RecordType = ProgressRecordType.Completed;
+ var record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace)
+ {
+ RecordType = ProgressRecordType.Completed
+ };
WriteProgress(record);
}
@@ -532,10 +534,8 @@ internal TraceRouteResult(string source, IPAddress destinationAddress, string de
private void ProcessMTUSize(String targetNameOrAddress)
{
PingReply reply, replyResult = null;
-
- string resolvedTargetName = null;
- IPAddress targetAddress = null;
-
+ string resolvedTargetName;
+ IPAddress targetAddress;
if (!InitProcessPing(targetNameOrAddress, out resolvedTargetName, out targetAddress))
{
return;
@@ -669,8 +669,10 @@ private void WriteMTUSizeProgress(int currentMTUSize, int retry)
private void WriteMTUSizeFooter()
{
- ProgressRecord record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace);
- record.RecordType = ProgressRecordType.Completed;
+ var record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace)
+ {
+ RecordType = ProgressRecordType.Completed
+ };
WriteProgress(record);
}
@@ -680,9 +682,8 @@ private void WriteMTUSizeFooter()
private void ProcessPing(String targetNameOrAddress)
{
- string resolvedTargetName = null;
- IPAddress targetAddress = null;
-
+ string resolvedTargetName;
+ IPAddress targetAddress;
if (!InitProcessPing(targetNameOrAddress, out resolvedTargetName, out targetAddress))
{
return;
@@ -697,8 +698,8 @@ private void ProcessPing(String targetNameOrAddress)
byte[] buffer = GetSendBuffer(BufferSize);
Ping sender = new Ping();
+ PingReply reply;
PingOptions pingOptions = new PingOptions(MaxHops, DontFragment.IsPresent);
- PingReply reply = null;
PingReport pingReport = new PingReport(Source, resolvedTargetName);
Int32 timeout = TimeoutSeconds * 1000;
Int32 delay = Delay * 1000;
@@ -784,7 +785,7 @@ private void WritePingHeader(string resolvedTargetName, string targetAddress)
private void WritePingProgress(PingReply reply)
{
- string msg = string.Empty;
+ string msg;
if (reply.Status != IPStatus.Success)
{
msg = TestConnectionResources.PingTimeOut;
@@ -809,8 +810,10 @@ private void WritePingFooter()
{
WriteInformation(TestConnectionResources.PingComplete, s_PSHostTag);
- ProgressRecord record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace);
- record.RecordType = ProgressRecordType.Completed;
+ var record = new ProgressRecord(s_ProgressId, _testConnectionProgressBarActivity, ProgressRecordSpace)
+ {
+ RecordType = ProgressRecordType.Completed
+ };
WriteProgress(record);
}
@@ -846,10 +849,9 @@ internal PingReport(string source, string destination)
private bool InitProcessPing(String targetNameOrAddress, out string resolvedTargetName, out IPAddress targetAddress)
{
- IPHostEntry hostEntry = null;
-
resolvedTargetName = targetNameOrAddress;
+ IPHostEntry hostEntry;
if (IPAddress.TryParse(targetNameOrAddress, out targetAddress))
{
if (ResolveDestination)
From 8954c9e17be4e76a7ee24e950e9a711f3c6fbda1 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 01:07:28 -0400
Subject: [PATCH 05/11] :recycle: Simplify parameter sets
---
.../management/TestConnectionCommand.cs | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 385661a0e85..7d6d1db7b1b 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -42,31 +42,19 @@ public class TestConnectionCommand : PSCmdlet
///
/// Force using IPv4 protocol.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
- [Parameter(ParameterSetName = TraceRouteSet)]
- [Parameter(ParameterSetName = MtuSizeDetectSet)]
- [Parameter(ParameterSetName = TcpPortSet)]
+ [Parameter()]
public SwitchParameter IPv4 { get; set; }
///
/// Force using IPv6 protocol.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
- [Parameter(ParameterSetName = TraceRouteSet)]
- [Parameter(ParameterSetName = MtuSizeDetectSet)]
- [Parameter(ParameterSetName = TcpPortSet)]
+ [Parameter()]
public SwitchParameter IPv6 { get; set; }
///
/// Do reverse DNS lookup to get names for IP addresses.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
- [Parameter(ParameterSetName = TraceRouteSet)]
- [Parameter(ParameterSetName = MtuSizeDetectSet)]
- [Parameter(ParameterSetName = TcpPortSet)]
+ [Parameter()]
public SwitchParameter ResolveDestination { get; set; }
///
From 1ec1d037ad21de4c8ada77eab25afecc1765a375 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 01:40:47 -0400
Subject: [PATCH 06/11] :recycle: Address CodeFactor nits
---
.../commands/management/TestConnectionCommand.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 7d6d1db7b1b..8264a154d56 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -42,19 +42,19 @@ public class TestConnectionCommand : PSCmdlet
///
/// Force using IPv4 protocol.
///
- [Parameter()]
+ [Parameter]
public SwitchParameter IPv4 { get; set; }
///
/// Force using IPv6 protocol.
///
- [Parameter()]
+ [Parameter]
public SwitchParameter IPv6 { get; set; }
///
/// Do reverse DNS lookup to get names for IP addresses.
///
- [Parameter()]
+ [Parameter]
public SwitchParameter ResolveDestination { get; set; }
///
@@ -130,7 +130,7 @@ public class TestConnectionCommand : PSCmdlet
/// Set short output kind ('bool' for Ping, 'int' for MTU size ...).
/// Default is to return typed result object(s).
///
- [Parameter()]
+ [Parameter]
public SwitchParameter Quiet;
///
@@ -139,7 +139,7 @@ public class TestConnectionCommand : PSCmdlet
/// It is not the cmdlet timeout! It is a timeout for waiting one ping response.
/// The default (from Windows) is 5 second.
///
- [Parameter()]
+ [Parameter]
[ValidateRange(ValidateRangeKind.Positive)]
public int TimeoutSeconds { get; set; } = 5;
From 6c32cac0858f76e21a357617b7f939f291232266 Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 01:44:16 -0400
Subject: [PATCH 07/11] :recycle: Address Codacy nits
---
.../commands/management/TestConnectionCommand.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 8264a154d56..a16acb0aae4 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -17,11 +17,11 @@ namespace Microsoft.PowerShell.Commands
/// The implementation of the "Test-Connection" cmdlet.
///
[Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
- [OutputType(typeof(PingReport), ParameterSetName = new string[] { DefaultPingSet })]
- [OutputType(typeof(PingReply), ParameterSetName = new string[] { RepeatPingSet, MtuSizeDetectSet })]
- [OutputType(typeof(bool), ParameterSetName = new string[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
- [OutputType(typeof(Int32), ParameterSetName = new string[] { MtuSizeDetectSet })]
- [OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { TraceRouteSet })]
+ [OutputType(typeof(PingReport), ParameterSetName = new[] { DefaultPingSet })]
+ [OutputType(typeof(PingReply), ParameterSetName = new[] { RepeatPingSet, MtuSizeDetectSet })]
+ [OutputType(typeof(bool), ParameterSetName = new[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
+ [OutputType(typeof(int), ParameterSetName = new[] { MtuSizeDetectSet })]
+ [OutputType(typeof(TraceRouteReply), ParameterSetName = new[] { TraceRouteSet })]
public class TestConnectionCommand : PSCmdlet
{
private const string DefaultPingSet = "DefaultPing";
From 140efb2d8c9344450ae8d2b8df79e437069e2f1d Mon Sep 17 00:00:00 2001
From: vexx32 <32407840+vexx32@users.noreply.github.com>
Date: Sat, 24 Aug 2019 08:30:11 -0400
Subject: [PATCH 08/11] :recycle: Simplify type names
---
.../management/TestConnectionCommand.cs | 35 ++++++++++---------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index a16acb0aae4..daa6a22f581 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -16,7 +16,8 @@ namespace Microsoft.PowerShell.Commands
///
/// The implementation of the "Test-Connection" cmdlet.
///
- [Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
+ [Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet,
+ HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
[OutputType(typeof(PingReport), ParameterSetName = new[] { DefaultPingSet })]
[OutputType(typeof(PingReply), ParameterSetName = new[] { RepeatPingSet, MtuSizeDetectSet })]
[OutputType(typeof(bool), ParameterSetName = new[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
@@ -219,7 +220,7 @@ protected override void ProcessRecord()
#region ConnectionTest
- private void ProcessConnectionByTCPPort(String targetNameOrAddress)
+ private void ProcessConnectionByTCPPort(string targetNameOrAddress)
{
string resolvedTargetName;
IPAddress targetAddress;
@@ -301,7 +302,7 @@ private void WriteConnectionTestFooter()
#endregion ConnectionTest
#region TracerouteTest
- private void ProcessTraceroute(String targetNameOrAddress)
+ private void ProcessTraceroute(string targetNameOrAddress)
{
byte[] buffer = GetSendBuffer(BufferSize);
@@ -316,11 +317,11 @@ private void ProcessTraceroute(String targetNameOrAddress)
TraceRouteResult traceRouteResult = new TraceRouteResult(Source, targetAddress, resolvedTargetName);
- Int32 currentHop = 1;
+ int currentHop = 1;
Ping sender = new Ping();
PingOptions pingOptions = new PingOptions(currentHop, DontFragment.IsPresent);
PingReply reply = null;
- Int32 timeout = TimeoutSeconds * 1000;
+ int timeout = TimeoutSeconds * 1000;
do
{
@@ -345,7 +346,7 @@ private void ProcessTraceroute(String targetNameOrAddress)
TestConnectionResources.NoPingResult,
resolvedTargetName,
ex.Message);
- Exception pingException = new System.Net.NetworkInformation.PingException(message, ex.InnerException);
+ Exception pingException = new PingException(message, ex.InnerException);
ErrorRecord errorRecord = new ErrorRecord(
pingException,
TestConnectionExceptionId,
@@ -519,7 +520,7 @@ internal TraceRouteResult(string source, IPAddress destinationAddress, string de
#endregion TracerouteTest
#region MTUSizeTest
- private void ProcessMTUSize(String targetNameOrAddress)
+ private void ProcessMTUSize(string targetNameOrAddress)
{
PingReply reply, replyResult = null;
string resolvedTargetName;
@@ -535,7 +536,7 @@ private void ProcessMTUSize(String targetNameOrAddress)
int HighMTUSize = 10000;
int CurrentMTUSize = 1473;
int LowMTUSize = targetAddress.AddressFamily == AddressFamily.InterNetworkV6 ? 1280 : 68;
- Int32 timeout = TimeoutSeconds * 1000;
+ int timeout = TimeoutSeconds * 1000;
try
{
@@ -578,7 +579,7 @@ private void ProcessMTUSize(String targetNameOrAddress)
TestConnectionResources.NoPingResult,
targetAddress,
reply.Status.ToString());
- Exception pingException = new System.Net.NetworkInformation.PingException(message);
+ Exception pingException = new PingException(message);
ErrorRecord errorRecord = new ErrorRecord(
pingException,
TestConnectionExceptionId,
@@ -603,7 +604,7 @@ private void ProcessMTUSize(String targetNameOrAddress)
catch (PingException ex)
{
string message = StringUtil.Format(TestConnectionResources.NoPingResult, targetAddress, ex.Message);
- Exception pingException = new System.Net.NetworkInformation.PingException(message, ex.InnerException);
+ Exception pingException = new PingException(message, ex.InnerException);
ErrorRecord errorRecord = new ErrorRecord(
pingException,
TestConnectionExceptionId,
@@ -668,7 +669,7 @@ private void WriteMTUSizeFooter()
#region PingTest
- private void ProcessPing(String targetNameOrAddress)
+ private void ProcessPing(string targetNameOrAddress)
{
string resolvedTargetName;
IPAddress targetAddress;
@@ -689,8 +690,8 @@ private void ProcessPing(String targetNameOrAddress)
PingReply reply;
PingOptions pingOptions = new PingOptions(MaxHops, DontFragment.IsPresent);
PingReport pingReport = new PingReport(Source, resolvedTargetName);
- Int32 timeout = TimeoutSeconds * 1000;
- Int32 delay = Delay * 1000;
+ int timeout = TimeoutSeconds * 1000;
+ int delay = Delay * 1000;
for (int i = 1; i <= Count; i++)
{
@@ -701,7 +702,7 @@ private void ProcessPing(String targetNameOrAddress)
catch (PingException ex)
{
string message = StringUtil.Format(TestConnectionResources.NoPingResult, resolvedTargetName, ex.Message);
- Exception pingException = new System.Net.NetworkInformation.PingException(message, ex.InnerException);
+ Exception pingException = new PingException(message, ex.InnerException);
ErrorRecord errorRecord = new ErrorRecord(
pingException,
TestConnectionExceptionId,
@@ -835,7 +836,7 @@ internal PingReport(string source, string destination)
#endregion PingTest
- private bool InitProcessPing(String targetNameOrAddress, out string resolvedTargetName, out IPAddress targetAddress)
+ private bool InitProcessPing(string targetNameOrAddress, out string resolvedTargetName, out IPAddress targetAddress)
{
resolvedTargetName = targetNameOrAddress;
@@ -866,7 +867,7 @@ private bool InitProcessPing(String targetNameOrAddress, out string resolvedTarg
TestConnectionResources.NoPingResult,
resolvedTargetName,
TestConnectionResources.CannotResolveTargetName);
- Exception pingException = new System.Net.NetworkInformation.PingException(message, ex);
+ Exception pingException = new PingException(message, ex);
ErrorRecord errorRecord = new ErrorRecord(
pingException,
TestConnectionExceptionId,
@@ -895,7 +896,7 @@ private bool InitProcessPing(String targetNameOrAddress, out string resolvedTarg
TestConnectionResources.NoPingResult,
resolvedTargetName,
TestConnectionResources.TargetAddressAbsent);
- Exception pingException = new System.Net.NetworkInformation.PingException(message, null);
+ Exception pingException = new PingException(message, null);
ErrorRecord errorRecord = new ErrorRecord(
pingException,
TestConnectionExceptionId,
From be41e3ac6d9ffed5f61d8c5d27b5e4df3284e856 Mon Sep 17 00:00:00 2001
From: Joel <32407840+vexx32@users.noreply.github.com>
Date: Mon, 26 Aug 2019 12:14:18 -0400
Subject: [PATCH 09/11] Revert ":recycle: Address Codacy nits"
This reverts commit 6c32cac0858f76e21a357617b7f939f291232266.
---
.../commands/management/TestConnectionCommand.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index daa6a22f581..766e5fbaeb1 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -18,11 +18,11 @@ namespace Microsoft.PowerShell.Commands
///
[Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet,
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
- [OutputType(typeof(PingReport), ParameterSetName = new[] { DefaultPingSet })]
- [OutputType(typeof(PingReply), ParameterSetName = new[] { RepeatPingSet, MtuSizeDetectSet })]
- [OutputType(typeof(bool), ParameterSetName = new[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
- [OutputType(typeof(int), ParameterSetName = new[] { MtuSizeDetectSet })]
- [OutputType(typeof(TraceRouteReply), ParameterSetName = new[] { TraceRouteSet })]
+ [OutputType(typeof(PingReport), ParameterSetName = new string[] { DefaultPingSet })]
+ [OutputType(typeof(PingReply), ParameterSetName = new string[] { RepeatPingSet, MtuSizeDetectSet })]
+ [OutputType(typeof(bool), ParameterSetName = new string[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
+ [OutputType(typeof(int), ParameterSetName = new string[] { MtuSizeDetectSet })]
+ [OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { TraceRouteSet })]
public class TestConnectionCommand : PSCmdlet
{
private const string DefaultPingSet = "DefaultPing";
From e5f21611c69a8e6d99f324185a0ef2be318e0080 Mon Sep 17 00:00:00 2001
From: Joel <32407840+vexx32@users.noreply.github.com>
Date: Mon, 26 Aug 2019 14:31:19 -0400
Subject: [PATCH 10/11] :art: Use more verbose names for param sets
---
.../management/TestConnectionCommand.cs | 74 +++++++++----------
1 file changed, 37 insertions(+), 37 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 766e5fbaeb1..444bbea757d 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -16,28 +16,28 @@ namespace Microsoft.PowerShell.Commands
///
/// The implementation of the "Test-Connection" cmdlet.
///
- [Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet,
+ [Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingParameterSet,
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
- [OutputType(typeof(PingReport), ParameterSetName = new string[] { DefaultPingSet })]
- [OutputType(typeof(PingReply), ParameterSetName = new string[] { RepeatPingSet, MtuSizeDetectSet })]
- [OutputType(typeof(bool), ParameterSetName = new string[] { DefaultPingSet, RepeatPingSet, TcpPortSet })]
- [OutputType(typeof(int), ParameterSetName = new string[] { MtuSizeDetectSet })]
- [OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { TraceRouteSet })]
+ [OutputType(typeof(PingReport), ParameterSetName = new string[] { DefaultPingParameterSet })]
+ [OutputType(typeof(PingReply), ParameterSetName = new string[] { RepeatPingParameterSet, MtuSizeDetectParameterSet })]
+ [OutputType(typeof(bool), ParameterSetName = new string[] { DefaultPingParameterSet, RepeatPingParameterSet, TcpPortParameterSet })]
+ [OutputType(typeof(int), ParameterSetName = new string[] { MtuSizeDetectParameterSet })]
+ [OutputType(typeof(TraceRouteReply), ParameterSetName = new string[] { TraceRouteParameterSet })]
public class TestConnectionCommand : PSCmdlet
{
- private const string DefaultPingSet = "DefaultPing";
- private const string RepeatPingSet = "RepeatPing";
- private const string TraceRouteSet = "TraceRoute";
- private const string TcpPortSet = "TcpPort";
- private const string MtuSizeDetectSet = "MtuSizeDetect";
+ private const string DefaultPingParameterSet = "DefaultPing";
+ private const string RepeatPingParameterSet = "RepeatPing";
+ private const string TraceRouteParameterSet = "TraceRoute";
+ private const string TcpPortParameterSet = "TcpPort";
+ private const string MtuSizeDetectParameterSet = "MtuSizeDetect";
#region Parameters
///
/// Do ping test.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
public SwitchParameter Ping { get; set; } = true;
///
@@ -63,10 +63,10 @@ public class TestConnectionCommand : PSCmdlet
/// The default is Local Host.
/// Remoting is not yet implemented internally in the cmdlet.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
- [Parameter(ParameterSetName = TraceRouteSet)]
- [Parameter(ParameterSetName = TcpPortSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
+ [Parameter(ParameterSetName = TraceRouteParameterSet)]
+ [Parameter(ParameterSetName = TcpPortParameterSet)]
public string Source { get; } = Dns.GetHostName();
///
@@ -75,9 +75,9 @@ public class TestConnectionCommand : PSCmdlet
/// they decrement the Time-to-Live (TTL) value found in the packet header.
/// The default (from Windows) is 128 hops.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
- [Parameter(ParameterSetName = TraceRouteSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
+ [Parameter(ParameterSetName = TraceRouteParameterSet)]
[ValidateRange(0, sMaxHops)]
[Alias("Ttl", "TimeToLive", "Hops")]
public int MaxHops { get; set; } = sMaxHops;
@@ -88,7 +88,7 @@ public class TestConnectionCommand : PSCmdlet
/// Count of attempts.
/// The default (from Windows) is 4 times.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
[ValidateRange(ValidateRangeKind.Positive)]
public int Count { get; set; } = 4;
@@ -96,8 +96,8 @@ public class TestConnectionCommand : PSCmdlet
/// Delay between attempts.
/// The default (from Windows) is 1 second.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
[ValidateRange(ValidateRangeKind.Positive)]
public int Delay { get; set; } = 1;
@@ -106,8 +106,8 @@ public class TestConnectionCommand : PSCmdlet
/// The default (from Windows) is 32 bites.
/// Max value is 65500 (limit from Windows API).
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
[Alias("Size", "Bytes", "BS")]
[ValidateRange(0, 65500)]
public int BufferSize { get; set; } = DefaultSendBufferSize;
@@ -116,15 +116,15 @@ public class TestConnectionCommand : PSCmdlet
/// Don't fragment ICMP packages.
/// Currently CoreFX not supports this on Unix.
///
- [Parameter(ParameterSetName = DefaultPingSet)]
- [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
public SwitchParameter DontFragment { get; set; }
///
/// Continue ping until user press Ctrl-C
/// or Int.MaxValue threshold reached.
///
- [Parameter(ParameterSetName = RepeatPingSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
public SwitchParameter Continues { get; set; }
///
@@ -159,20 +159,20 @@ public class TestConnectionCommand : PSCmdlet
///
/// Detect MTU size.
///
- [Parameter(Mandatory = true, ParameterSetName = MtuSizeDetectSet)]
+ [Parameter(Mandatory = true, ParameterSetName = MtuSizeDetectParameterSet)]
public SwitchParameter MTUSizeDetect { get; set; }
///
/// Do traceroute test.
///
- [Parameter(Mandatory = true, ParameterSetName = TraceRouteSet)]
+ [Parameter(Mandatory = true, ParameterSetName = TraceRouteParameterSet)]
public SwitchParameter Traceroute { get; set; }
///
/// Do tcp connection test.
///
[ValidateRange(0, 65535)]
- [Parameter(Mandatory = true, ParameterSetName = TcpPortSet)]
+ [Parameter(Mandatory = true, ParameterSetName = TcpPortParameterSet)]
public int TCPPort { get; set; }
#endregion Parameters
@@ -186,7 +186,7 @@ protected override void BeginProcessing()
switch (ParameterSetName)
{
- case RepeatPingSet:
+ case RepeatPingParameterSet:
Count = int.MaxValue;
break;
}
@@ -201,17 +201,17 @@ protected override void ProcessRecord()
{
switch (ParameterSetName)
{
- case DefaultPingSet:
- case RepeatPingSet:
+ case DefaultPingParameterSet:
+ case RepeatPingParameterSet:
ProcessPing(targetName);
break;
- case MtuSizeDetectSet:
+ case MtuSizeDetectParameterSet:
ProcessMTUSize(targetName);
break;
- case TraceRouteSet:
+ case TraceRouteParameterSet:
ProcessTraceroute(targetName);
break;
- case TcpPortSet:
+ case TcpPortParameterSet:
ProcessConnectionByTCPPort(targetName);
break;
}
From 6ba701c44fcd39886c46857431bd7b7303060b30 Mon Sep 17 00:00:00 2001
From: Joel <32407840+vexx32@users.noreply.github.com>
Date: Mon, 26 Aug 2019 14:54:11 -0400
Subject: [PATCH 11/11] Revert ":recycle: Simplify parameter sets"
This reverts commit 8954c9e17be4e76a7ee24e950e9a711f3c6fbda1.
---
.../management/TestConnectionCommand.cs | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index 444bbea757d..c8c5ccfa153 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -43,19 +43,31 @@ public class TestConnectionCommand : PSCmdlet
///
/// Force using IPv4 protocol.
///
- [Parameter]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
+ [Parameter(ParameterSetName = TraceRouteParameterSet)]
+ [Parameter(ParameterSetName = MtuSizeDetectParameterSet)]
+ [Parameter(ParameterSetName = TcpPortParameterSet)]
public SwitchParameter IPv4 { get; set; }
///
/// Force using IPv6 protocol.
///
- [Parameter]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
+ [Parameter(ParameterSetName = TraceRouteParameterSet)]
+ [Parameter(ParameterSetName = MtuSizeDetectParameterSet)]
+ [Parameter(ParameterSetName = TcpPortParameterSet)]
public SwitchParameter IPv6 { get; set; }
///
/// Do reverse DNS lookup to get names for IP addresses.
///
- [Parameter]
+ [Parameter(ParameterSetName = DefaultPingParameterSet)]
+ [Parameter(ParameterSetName = RepeatPingParameterSet)]
+ [Parameter(ParameterSetName = TraceRouteParameterSet)]
+ [Parameter(ParameterSetName = MtuSizeDetectParameterSet)]
+ [Parameter(ParameterSetName = TcpPortParameterSet)]
public SwitchParameter ResolveDestination { get; set; }
///