From 0884fa617a642fe07a9181b23eeee62072467161 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 11 Dec 2011 22:52:58 -0800 Subject: [PATCH] Added extra logging to update/ProcessProvider --- NzbDrone.Common.Test/ProcessProviderTests.cs | 13 +++++++++++++ NzbDrone.Common/Model/ProcessInfo.cs | 8 +++++++- NzbDrone.Common/ProcessProvider.cs | 18 ++++++++++++++++-- NzbDrone.Test.Common/TestBase.cs | 2 +- NzbDrone.Update.Test/ProgramFixture.cs | 3 --- NzbDrone.Update/Program.cs | 13 ++++++++----- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs index 2a9adfed7..bb8f44a29 100644 --- a/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -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()); + } + } } diff --git a/NzbDrone.Common/Model/ProcessInfo.cs b/NzbDrone.Common/Model/ProcessInfo.cs index 3bcd2b39b..79ea0b421 100644 --- a/NzbDrone.Common/Model/ProcessInfo.cs +++ b/NzbDrone.Common/Model/ProcessInfo.cs @@ -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); + } } } \ No newline at end of file diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 348bcdb4d..a6583654f 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -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 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 }; } diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 8c43ca9a5..6b2787dfc 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -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); } diff --git a/NzbDrone.Update.Test/ProgramFixture.cs b/NzbDrone.Update.Test/ProgramFixture.cs index fd715e0c7..5dd13ef2e 100644 --- a/NzbDrone.Update.Test/ProgramFixture.cs +++ b/NzbDrone.Update.Test/ProgramFixture.cs @@ -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; diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 60c54f64b..2c8409f12 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -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]); } } }