@@ -40,10 +40,9 @@ internal class PortHelper
4040
4141 private static string ClassName => nameof ( PortHelper ) ;
4242
43- public static Tuple < bool , PortDetail > GetPortDetails ( int port , PluginInitContext context )
43+ public static ( bool Result , PortDetail Detail ) GetPortDetails ( int port , PluginInitContext context )
4444 {
45- PortDetail PortDetail = new PortDetail ( ) ;
46- Tuple < bool , PortDetail > result = Tuple . Create ( false , PortDetail ) ;
45+ var portDetail = new PortDetail ( ) ;
4746
4847 // execute netstat command for the given port
4948 string commandArgument = string . Format ( "/c netstat -an -o -p tcp|findstr \" :{0}.*LISTENING\" " , port ) ;
@@ -52,49 +51,49 @@ public static Tuple<bool, PortDetail> GetPortDetails(int port, PluginInitContext
5251 if ( string . IsNullOrEmpty ( commandOut ) )
5352 {
5453 // port is not in use
55- return result ;
54+ return ( false , portDetail ) ;
5655 }
5756
5857 var stringTokens = commandOut . Split ( default ( char [ ] ) , StringSplitOptions . RemoveEmptyEntries ) ;
5958 if ( stringTokens . Length < MINIMUM_TOKEN_IN_A_LINE )
6059 {
61- return result ;
60+ return ( false , portDetail ) ;
6261 }
6362
6463 // split host:port
6564 var hostPortTokens = stringTokens [ 1 ] . Split ( new char [ ] { ':' } ) ;
6665 if ( hostPortTokens . Length < 2 )
6766 {
68- return result ;
67+ return ( false , portDetail ) ;
6968 }
7069
7170 if ( ! int . TryParse ( hostPortTokens [ 1 ] , out var portFromHostPortToken ) )
7271 {
73- return result ;
72+ return ( false , portDetail ) ;
7473 }
7574
7675 if ( portFromHostPortToken != port )
7776 {
78- return result ;
77+ return ( false , portDetail ) ;
7978 }
8079
81- PortDetail . Port = port ;
82- PortDetail . ProcessID = int . Parse ( stringTokens [ 4 ] . Trim ( ) ) ;
80+ portDetail . Port = port ;
81+ portDetail . ProcessID = int . Parse ( stringTokens [ 4 ] . Trim ( ) ) ;
8382 ( string Name , string Path ) processNameAndPath ;
8483 try
8584 {
86- processNameAndPath = GetProcessNameAndCommandLineArgs ( PortDetail . ProcessID , context ) ;
87- PortDetail . ProcessName = processNameAndPath . Name ;
88- PortDetail . Path = processNameAndPath . Path ;
89- PortDetail . Process = Process . GetProcessById ( PortDetail . ProcessID ) ;
90- result = Tuple . Create ( true , PortDetail ) ;
85+ processNameAndPath = GetProcessNameAndCommandLineArgs ( portDetail . ProcessID , context ) ;
86+ portDetail . ProcessName = processNameAndPath . Name ;
87+ portDetail . Path = processNameAndPath . Path ;
88+ portDetail . Process = Process . GetProcessById ( portDetail . ProcessID ) ;
89+ return ( true , portDetail ) ;
9190 }
9291 catch ( Exception e )
9392 {
9493 context . API . LogException ( ClassName , "Failed to get process name and path" , e ) ;
9594 }
9695
97- return result ;
96+ return ( false , portDetail ) ;
9897 }
9998
10099 /// <summary>
0 commit comments