@ -1,5 +1,4 @@
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Linq ;
using NLog ;
@ -12,10 +11,9 @@ namespace NzbDrone.Common
ProcessInfo GetCurrentProcess ( ) ;
ProcessInfo GetProcessById ( int id ) ;
IEnumerable < ProcessInfo > GetProcessByName ( string name ) ;
void Start ( string path ) ;
Process Start ( string path ) ;
Process Start ( ProcessStartInfo startInfo ) ;
void WaitForExit ( Process process ) ;
void Kill ( int processId ) ;
void SetPriority ( int processId , ProcessPriorityClass priority ) ;
void KillAll ( string processName ) ;
}
@ -55,9 +53,9 @@ namespace NzbDrone.Common
return Process . GetProcessesByName ( name ) . Select ( ConvertToProcessInfo ) . Where ( p = > p ! = null ) ;
}
public void Start ( string path )
public Process Start ( string path )
{
Process . Start( path ) ;
return Start ( new Process StartInfo ( path ) ) ;
}
public Process Start ( ProcessStartInfo startInfo )
@ -69,6 +67,7 @@ namespace NzbDrone.Common
StartInfo = startInfo
} ;
process . Start ( ) ;
return process ;
}
@ -78,27 +77,7 @@ namespace NzbDrone.Common
process . WaitForExit ( ) ;
}
public void Kill ( int processId )
{
if ( processId = = 0 | | Process . GetProcesses ( ) . All ( p = > p . Id ! = processId ) )
{
Logger . Warn ( "Cannot find process with id: {0}" , processId ) ;
return ;
}
var process = Process . GetProcessById ( processId ) ;
if ( process . HasExited )
{
return ;
}
Logger . Info ( "[{0}]: Killing process" , process . Id ) ;
process . Kill ( ) ;
Logger . Info ( "[{0}]: Waiting for exit" , process . Id ) ;
process . WaitForExit ( ) ;
Logger . Info ( "[{0}]: Process terminated successfully" , process . Id ) ;
}
public void SetPriority ( int processId , ProcessPriorityClass priority )
{
@ -134,5 +113,27 @@ namespace NzbDrone.Common
Kill ( processInfo . Id ) ;
}
}
private void Kill ( int processId )
{
if ( processId = = 0 | | Process . GetProcesses ( ) . All ( p = > p . Id ! = processId ) )
{
Logger . Warn ( "Cannot find process with id: {0}" , processId ) ;
return ;
}
var process = Process . GetProcessById ( processId ) ;
if ( process . HasExited )
{
return ;
}
Logger . Info ( "[{0}]: Killing process" , process . Id ) ;
process . Kill ( ) ;
Logger . Info ( "[{0}]: Waiting for exit" , process . Id ) ;
process . WaitForExit ( ) ;
Logger . Info ( "[{0}]: Process terminated successfully" , process . Id ) ;
}
}
}