Added extra logging to update/ProcessProvider
This commit is contained in:
parent
50c4aa7557
commit
0884fa617a
|
@ -1,8 +1,11 @@
|
|||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Dummy;
|
||||
|
||||
|
@ -39,6 +42,8 @@ namespace NzbDrone.Common.Test
|
|||
public void GetById_should_return_null_if_process_doesnt_exist()
|
||||
{
|
||||
_processProvider.GetProcessById(1234567).Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
|
@ -47,6 +52,8 @@ namespace NzbDrone.Common.Test
|
|||
public void GetProcessById_should_return_null_for_invalid_process(int processId)
|
||||
{
|
||||
_processProvider.GetProcessById(processId).Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -77,5 +84,11 @@ namespace NzbDrone.Common.Test
|
|||
return _processProvider.Start(startInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToString_on_new_processInfo()
|
||||
{
|
||||
Console.WriteLine(new ProcessInfo().ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,13 @@ namespace NzbDrone.Common.Model
|
|||
public class ProcessInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public ProcessPriorityClass Priority { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string StartPath { get; set; }
|
||||
public ProcessPriorityClass Priority { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}:{1} [{2}] [{3}]", Id, Name ?? "Unknown", StartPath ?? "Unknown", Priority);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,7 +19,20 @@ namespace NzbDrone.Common
|
|||
|
||||
public virtual ProcessInfo GetProcessById(int id)
|
||||
{
|
||||
return ConvertToProcessInfo(Process.GetProcesses().Where(p => p.Id == id).FirstOrDefault());
|
||||
Logger.Trace("Finding process with Id:{0}", id);
|
||||
|
||||
var processInfo = ConvertToProcessInfo(Process.GetProcesses().Where(p => p.Id == id).FirstOrDefault());
|
||||
|
||||
if (processInfo == null)
|
||||
{
|
||||
Logger.Warn("Unable to find process with ID {0}", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Trace("Found process {0}", processInfo.ToString());
|
||||
}
|
||||
|
||||
return processInfo;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<ProcessInfo> GetProcessByName(string name)
|
||||
|
@ -84,7 +97,8 @@ namespace NzbDrone.Common
|
|||
{
|
||||
Id = process.Id,
|
||||
Priority = process.PriorityClass,
|
||||
StartPath = process.MainModule.FileName
|
||||
StartPath = process.MainModule.FileName,
|
||||
Name = process.ProcessName
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace NzbDrone.Test.Common
|
|||
[SetUp]
|
||||
public void TestBaseSetup()
|
||||
{
|
||||
if (Directory.Exists(TempFolder))
|
||||
if (Directory.Exists(TempFolder) && Directory.GetFiles(TempFolder, "*.*", SearchOption.AllDirectories).Any())
|
||||
{
|
||||
Directory.Delete(TempFolder, true);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
|
|
|
@ -84,21 +84,22 @@ namespace NzbDrone.Update
|
|||
VerfityArguments(args);
|
||||
int processId = ParseProcessId(args);
|
||||
|
||||
FileInfo exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath);
|
||||
string appPath = exeFileInfo.Directory.FullName;
|
||||
var exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath);
|
||||
string targetFolder = exeFileInfo.Directory.FullName;
|
||||
|
||||
logger.Info("Starting update process");
|
||||
_updateProvider.Start(appPath);
|
||||
logger.Info("Starting update process. Target Path:{0}", targetFolder);
|
||||
_updateProvider.Start(targetFolder);
|
||||
}
|
||||
|
||||
private int ParseProcessId(string[] args)
|
||||
{
|
||||
int id = 0;
|
||||
int id;
|
||||
if (!Int32.TryParse(args[0], out id) || id <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Invalid process id: " + args[0]);
|
||||
}
|
||||
|
||||
logger.Debug("NzbDrone processId:{0}", id);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -106,6 +107,8 @@ namespace NzbDrone.Update
|
|||
{
|
||||
if (args == null || args.Length != 2)
|
||||
throw new ArgumentException("Wrong number of parameters were passed in.");
|
||||
|
||||
logger.Debug("Arguments verified. [{0}] , [{1}]", args[0], args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue