mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
better process.start for mono
This commit is contained in:
parent
aee7019ed2
commit
435904bc0a
@ -55,9 +55,7 @@ public void GetProcessById_should_return_null_for_invalid_process(int processId)
|
|||||||
[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 @@ public void Should_be_able_to_start_process()
|
|||||||
[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 @@ public void kill_all_should_kill_all_process_with_name()
|
|||||||
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 @@ public interface IProcessProvider
|
|||||||
{
|
{
|
||||||
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 @@ public ProcessInfo GetProcessById(int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 @@ public Process ShellExecute(string path, string args = null, Action<string> onOu
|
|||||||
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 @@ public void should_start_update_client()
|
|||||||
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 @@ private void InstallUpdate(UpdatePackage updatePackage)
|
|||||||
|
|
||||||
_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 @@ private void RunNetsh(string arguments)
|
|||||||
{
|
{
|
||||||
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 @@ public void Start()
|
|||||||
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 @@ public void Start()
|
|||||||
|
|
||||||
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 @@ public void should_start_console_if_app_type_was_serivce_but_start_failed_becaus
|
|||||||
|
|
||||||
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 @@ public AppType GetAppType()
|
|||||||
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 @@ private void Start(string installationFolder, string fileName)
|
|||||||
_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 @@ public void Terminate()
|
|||||||
|
|
||||||
_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 @@ private void LaunchBrowser(object sender, EventArgs e)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_processProvider.Start(_hostController.AppUrl);
|
_processProvider.OpenDefaultBrowser(_hostController.AppUrl);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user