better process.start for mono
This commit is contained in:
parent
aee7019ed2
commit
435904bc0a
|
@ -55,9 +55,7 @@ namespace NzbDrone.Common.Test
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_be_able_to_start_process()
|
public void Should_be_able_to_start_process()
|
||||||
{
|
{
|
||||||
var startInfo = new ProcessStartInfo(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
|
var process = Subject.Start(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
|
||||||
|
|
||||||
var process = Subject.Start(startInfo);
|
|
||||||
|
|
||||||
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
||||||
.BeTrue("excepted one dummy process to be already running");
|
.BeTrue("excepted one dummy process to be already running");
|
||||||
|
@ -71,7 +69,7 @@ namespace NzbDrone.Common.Test
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_be_able_to_execute_process()
|
public void Should_be_able_to_execute_process()
|
||||||
{
|
{
|
||||||
var process = Subject.ShellExecute(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
|
var process = Subject.Start(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
|
||||||
|
|
||||||
|
|
||||||
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
||||||
|
@ -95,10 +93,9 @@ namespace NzbDrone.Common.Test
|
||||||
dummy2.HasExited.Should().BeTrue();
|
dummy2.HasExited.Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Process StartDummyProcess()
|
private Process StartDummyProcess()
|
||||||
{
|
{
|
||||||
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
return Subject.Start(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
||||||
return Subject.Start(startInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -14,22 +14,21 @@ namespace NzbDrone.Common
|
||||||
{
|
{
|
||||||
ProcessInfo GetCurrentProcess();
|
ProcessInfo GetCurrentProcess();
|
||||||
ProcessInfo GetProcessById(int id);
|
ProcessInfo GetProcessById(int id);
|
||||||
Process Start(string path);
|
void OpenDefaultBrowser(string url);
|
||||||
Process Start(ProcessStartInfo startInfo);
|
|
||||||
void WaitForExit(Process process);
|
void WaitForExit(Process process);
|
||||||
void SetPriority(int processId, ProcessPriorityClass priority);
|
void SetPriority(int processId, ProcessPriorityClass priority);
|
||||||
void KillAll(string processName);
|
void KillAll(string processName);
|
||||||
bool Exists(string processName);
|
bool Exists(string processName);
|
||||||
ProcessPriorityClass GetCurrentProcessPriority();
|
ProcessPriorityClass GetCurrentProcessPriority();
|
||||||
Process ShellExecute(string path, string args = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null);
|
Process Start(string path, string args = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProcessProvider : IProcessProvider
|
public class ProcessProvider : IProcessProvider
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public const string NzbDroneProcessName = "NzbDrone";
|
public const string NZB_DRONE_PROCESS_NAME = "NzbDrone";
|
||||||
public const string NzbDroneConsoleProcessName = "NzbDrone.Console";
|
public const string NZB_DRONE_CONSOLE_PROCESS_NAME = "NzbDrone.Console";
|
||||||
|
|
||||||
private static List<Process> GetProcessesByName(string name)
|
private static List<Process> GetProcessesByName(string name)
|
||||||
{
|
{
|
||||||
|
@ -73,12 +72,22 @@ namespace NzbDrone.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Process Start(string path)
|
public void OpenDefaultBrowser(string url)
|
||||||
{
|
{
|
||||||
return Start(new ProcessStartInfo(path));
|
Logger.Info("Opening URL [{0}]", url);
|
||||||
|
|
||||||
|
var process = new Process
|
||||||
|
{
|
||||||
|
StartInfo = new ProcessStartInfo(url)
|
||||||
|
{
|
||||||
|
UseShellExecute = true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Process ShellExecute(string path, string args = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null)
|
public Process Start(string path, string args = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (OsInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
if (OsInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
@ -139,19 +148,6 @@ namespace NzbDrone.Common
|
||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Process Start(ProcessStartInfo startInfo)
|
|
||||||
{
|
|
||||||
Logger.Info("Starting process. [{0}]", startInfo.FileName);
|
|
||||||
|
|
||||||
var process = new Process
|
|
||||||
{
|
|
||||||
StartInfo = startInfo
|
|
||||||
};
|
|
||||||
process.Start();
|
|
||||||
|
|
||||||
return process;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WaitForExit(Process process)
|
public void WaitForExit(Process process)
|
||||||
{
|
{
|
||||||
Logger.Trace("Waiting for process {0} to exit.", process.ProcessName);
|
Logger.Trace("Waiting for process {0} to exit.", process.ProcessName);
|
||||||
|
|
|
@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.UpdateTests
|
||||||
Subject.Execute(new ApplicationUpdateCommand());
|
Subject.Execute(new ApplicationUpdateCommand());
|
||||||
|
|
||||||
Mocker.GetMock<IProcessProvider>()
|
Mocker.GetMock<IProcessProvider>()
|
||||||
.Verify(c => c.ShellExecute(It.IsAny<string>(), "12", null, null), Times.Once());
|
.Verify(c => c.Start(It.IsAny<string>(), "12", null, null), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace NzbDrone.Core.Update
|
||||||
|
|
||||||
_logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath());
|
_logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath());
|
||||||
|
|
||||||
var process = _processProvider.ShellExecute(_appFolderInfo.GetUpdateClientExePath(), _processProvider.GetCurrentProcess().Id.ToString());
|
var process = _processProvider.Start(_appFolderInfo.GetUpdateClientExePath(), _processProvider.GetCurrentProcess().Id.ToString());
|
||||||
|
|
||||||
_processProvider.WaitForExit(process);
|
_processProvider.WaitForExit(process);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace NzbDrone.Host.AccessControl
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var process = _processProvider.ShellExecute("netsh.exe", arguments);
|
var process = _processProvider.Start("netsh.exe", arguments);
|
||||||
process.WaitForExit(5000);
|
process.WaitForExit(5000);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace NzbDrone.Host
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.Info("Starting default browser. {0}", _hostController.AppUrl);
|
_logger.Info("Starting default browser. {0}", _hostController.AppUrl);
|
||||||
_processProvider.Start(_hostController.AppUrl);
|
_processProvider.OpenDefaultBrowser(_hostController.AppUrl);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,14 +56,14 @@ namespace NzbDrone.Integration.Test
|
||||||
|
|
||||||
public void KillAll()
|
public void KillAll()
|
||||||
{
|
{
|
||||||
_processProvider.KillAll(ProcessProvider.NzbDroneConsoleProcessName);
|
_processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
|
||||||
_processProvider.KillAll(ProcessProvider.NzbDroneProcessName);
|
_processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start(string outputNzbdroneConsoleExe)
|
private void Start(string outputNzbdroneConsoleExe)
|
||||||
{
|
{
|
||||||
var args = "-nobrowser -data=\"" + AppDate + "\"";
|
var args = "-nobrowser -data=\"" + AppDate + "\"";
|
||||||
_nzbDroneProcess = _processProvider.ShellExecute(outputNzbdroneConsoleExe, args, OnOutputDataReceived, OnOutputDataReceived);
|
_nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, OnOutputDataReceived, OnOutputDataReceived);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
@ -33,10 +32,7 @@ namespace NzbDrone.Update.Test
|
||||||
|
|
||||||
Subject.Start(AppType.Service, targetFolder);
|
Subject.Start(AppType.Service, targetFolder);
|
||||||
|
|
||||||
Mocker.GetMock<IProcessProvider>().Verify(c => c.Start(It.Is<ProcessStartInfo>(s =>
|
Mocker.GetMock<IProcessProvider>().Verify(c => c.Start("c:\\NzbDrone\\NzbDrone.Console.exe", StartupArguments.NO_BROWSER, null, null), Times.Once());
|
||||||
s.FileName == "c:\\NzbDrone\\NzbDrone.Console.exe" &&
|
|
||||||
s.Arguments == StartupArguments.NO_BROWSER
|
|
||||||
)), Times.Once());
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Update.UpdateEngine
|
||||||
return AppType.Service;
|
return AppType.Service;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_processProvider.Exists(ProcessProvider.NzbDroneConsoleProcessName))
|
if (_processProvider.Exists(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME))
|
||||||
{
|
{
|
||||||
return AppType.Console;
|
return AppType.Console;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace NzbDrone.Update.UpdateEngine
|
||||||
_logger.Info("Starting {0}", fileName);
|
_logger.Info("Starting {0}", fileName);
|
||||||
var path = Path.Combine(installationFolder, fileName);
|
var path = Path.Combine(installationFolder, fileName);
|
||||||
|
|
||||||
_processProvider.Start(new ProcessStartInfo(path, StartupArguments.NO_BROWSER));
|
_processProvider.Start(path, StartupArguments.NO_BROWSER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,8 +44,8 @@ namespace NzbDrone.Update.UpdateEngine
|
||||||
|
|
||||||
_logger.Info("Killing all running processes");
|
_logger.Info("Killing all running processes");
|
||||||
|
|
||||||
_processProvider.KillAll(ProcessProvider.NzbDroneConsoleProcessName);
|
_processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
|
||||||
_processProvider.KillAll(ProcessProvider.NzbDroneProcessName);
|
_processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -84,7 +84,7 @@ namespace NzbDrone.SysTray
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_processProvider.Start(_hostController.AppUrl);
|
_processProvider.OpenDefaultBrowser(_hostController.AppUrl);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue