Resharper Code cleanup.

pull/4/head
kay.one 13 years ago
parent 57c296c62f
commit 6a9ee3f0b0

@ -11,15 +11,17 @@ namespace NzbDrone
private static readonly Logger Logger = LogManager.GetLogger("Host.App"); private static readonly Logger Logger = LogManager.GetLogger("Host.App");
private readonly ConfigProvider _configProvider; private readonly ConfigProvider _configProvider;
private readonly WebClient _webClient;
private readonly IISProvider _iisProvider;
private readonly ConsoleProvider _consoleProvider; private readonly ConsoleProvider _consoleProvider;
private readonly DebuggerProvider _debuggerProvider; private readonly DebuggerProvider _debuggerProvider;
private readonly EnviromentProvider _enviromentProvider; private readonly EnviromentProvider _enviromentProvider;
private readonly IISProvider _iisProvider;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly WebClient _webClient;
public Application(ConfigProvider configProvider, WebClient webClient, IISProvider iisProvider, ConsoleProvider consoleProvider, public Application(ConfigProvider configProvider, WebClient webClient, IISProvider iisProvider,
DebuggerProvider debuggerProvider, EnviromentProvider enviromentProvider, ProcessProvider processProvider) ConsoleProvider consoleProvider,
DebuggerProvider debuggerProvider, EnviromentProvider enviromentProvider,
ProcessProvider processProvider)
{ {
_configProvider = configProvider; _configProvider = configProvider;
_webClient = webClient; _webClient = webClient;
@ -33,7 +35,6 @@ namespace NzbDrone
_configProvider.CreateDefaultConfigFile(); _configProvider.CreateDefaultConfigFile();
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _configProvider.ApplicationRoot); Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _configProvider.ApplicationRoot);
Thread.CurrentThread.Name = "Host"; Thread.CurrentThread.Name = "Host";
} }
public void Start() public void Start()
@ -71,8 +72,6 @@ namespace NzbDrone
public void Stop() public void Stop()
{ {
} }
} }
} }

@ -1,14 +1,9 @@
using System; using System.ServiceProcess;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace NzbDrone namespace NzbDrone
{ {
class NzbDroneService : ServiceBase internal class NzbDroneService : ServiceBase
{ {
protected override void OnStart(string[] args) protected override void OnStart(string[] args)
{ {
base.OnStart(args); base.OnStart(args);
@ -18,6 +13,5 @@ namespace NzbDrone
{ {
base.OnStop(); base.OnStop();
} }
} }
} }

@ -19,7 +19,7 @@ namespace NzbDrone
public static void Attach() public static void Attach()
{ {
DTE2 dte2; DTE2 dte2;
dte2 = (DTE2)Marshal. dte2 = (DTE2) Marshal.
GetActiveObject("VisualStudio.DTE.10.0"); GetActiveObject("VisualStudio.DTE.10.0");
var pa = new ProcessAttacher(dte2, "iisexpress", 10); var pa = new ProcessAttacher(dte2, "iisexpress", 10);
@ -27,7 +27,6 @@ namespace NzbDrone
return; return;
// Get an instance of the currently running Visual Studio IDE. // Get an instance of the currently running Visual Studio IDE.
} }
#region private #region private
@ -88,9 +87,9 @@ namespace NzbDrone
private AttachResult PessimisticAttach(AttachType attachType) private AttachResult PessimisticAttach(AttachType attachType)
{ {
AttachResult res = Attach(attachType); var res = Attach(attachType);
DateTime timeout = DateTime.Now.AddSeconds(_waitTimeout); var timeout = DateTime.Now.AddSeconds(_waitTimeout);
while (res == AttachResult.NotRunning && timeout > DateTime.Now) while (res == AttachResult.NotRunning && timeout > DateTime.Now)
{ {
@ -102,8 +101,6 @@ namespace NzbDrone
private bool IsBeingDebugged() private bool IsBeingDebugged()
{ {
if (_dte.Debugger.DebuggedProcesses != null) if (_dte.Debugger.DebuggedProcesses != null)
{ {
foreach (Process process in _dte.Debugger.DebuggedProcesses) foreach (Process process in _dte.Debugger.DebuggedProcesses)

@ -1,8 +1,4 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace NzbDrone namespace NzbDrone
{ {
@ -13,6 +9,5 @@ namespace NzbDrone
public string StartPath { get; set; } public string StartPath { get; set; }
public bool HasExited { get; set; } public bool HasExited { get; set; }
} }
} }

@ -28,7 +28,6 @@ namespace NzbDrone
Console.WriteLine("Starting Console."); Console.WriteLine("Starting Console.");
Kernel.Get<MonitoringProvider>().Start(); Kernel.Get<MonitoringProvider>().Start();
Kernel.Get<Application>().Start(); Kernel.Get<Application>().Start();
} }
catch (Exception e) catch (Exception e)
{ {

@ -36,4 +36,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.0.*")] [assembly: AssemblyVersion("0.5.0.*")]

@ -88,10 +88,10 @@ namespace NzbDrone.Providers
)); ));
bindings.Add( bindings.Add(
new XElement("binding", new XElement("binding",
new XAttribute("protocol", "http"), new XAttribute("protocol", "http"),
new XAttribute("bindingInformation", String.Format("*:{0}:", Port)) new XAttribute("bindingInformation", String.Format("*:{0}:", Port))
)); ));
configXml.Save(configPath); configXml.Save(configPath);
} }
@ -112,10 +112,10 @@ namespace NzbDrone.Providers
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xDoc.Add(new XElement("Config", xDoc.Add(new XElement("Config",
new XElement("Port", 8989), new XElement("Port", 8989),
new XElement("LaunchBrowser", true) new XElement("LaunchBrowser", true)
) )
); );
xDoc.Save(ConfigFile); xDoc.Save(ConfigFile);
} }
@ -130,7 +130,7 @@ namespace NzbDrone.Providers
if (parent != null) if (parent != null)
parentContainer = config.Descendants(parent).Single(); parentContainer = config.Descendants(parent).Single();
var value = parentContainer.Descendants(key).Single().Value; string value = parentContainer.Descendants(key).Single().Value;
return value; return value;
} }

@ -12,4 +12,4 @@ namespace NzbDrone.Providers
} }
} }
} }
} }

@ -7,7 +7,6 @@ namespace NzbDrone.Providers
{ {
public class DebuggerProvider public class DebuggerProvider
{ {
private static readonly Logger Logger = LogManager.GetLogger("Host.DebuggerProvider"); private static readonly Logger Logger = LogManager.GetLogger("Host.DebuggerProvider");
@ -18,7 +17,7 @@ namespace NzbDrone.Providers
{ {
Logger.Info("Trying to attach to debugger"); Logger.Info("Trying to attach to debugger");
var count = 0; int count = 0;
while (true) while (true)
{ {
@ -38,14 +37,10 @@ namespace NzbDrone.Providers
} }
Thread.Sleep(100); Thread.Sleep(100);
} }
} }
} }
#endif #endif
} }
} }
} }

@ -14,4 +14,4 @@ namespace NzbDrone.Providers
get { return Environment.UserInteractive; } get { return Environment.UserInteractive; }
} }
} }
} }

@ -8,10 +8,10 @@ namespace NzbDrone.Providers
{ {
public class IISProvider public class IISProvider
{ {
private readonly ConfigProvider _configProvider;
private readonly ProcessProvider _processProvider;
private static readonly Logger IISLogger = LogManager.GetLogger("Host.IISExpress"); private static readonly Logger IISLogger = LogManager.GetLogger("Host.IISExpress");
private static readonly Logger Logger = LogManager.GetLogger("Host.IISProvider"); private static readonly Logger Logger = LogManager.GetLogger("Host.IISProvider");
private readonly ConfigProvider _configProvider;
private readonly ProcessProvider _processProvider;
[Inject] [Inject]
@ -19,12 +19,10 @@ namespace NzbDrone.Providers
{ {
_configProvider = configProvider; _configProvider = configProvider;
_processProvider = processProvider; _processProvider = processProvider;
} }
public IISProvider() public IISProvider()
{ {
} }
public string AppUrl public string AppUrl
@ -141,7 +139,5 @@ namespace NzbDrone.Providers
return info.FullName.Trim('/', '\\', ' ').ToLower(); return info.FullName.Trim('/', '\\', ' ').ToLower();
} }
} }
} }

@ -1,6 +1,5 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Net;
using System.Runtime.Remoting; using System.Runtime.Remoting;
using System.Timers; using System.Timers;
using NLog; using NLog;
@ -14,15 +13,22 @@ namespace NzbDrone.Providers
private readonly IISProvider _iisProvider; private readonly IISProvider _iisProvider;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly WebClientProvider _webClientProvider;
private int _pingFailCounter; private int _pingFailCounter;
private Timer _pingTimer; private Timer _pingTimer;
[Inject] [Inject]
public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider) public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider,
WebClientProvider webClientProvider)
{ {
_processProvider = processProvider; _processProvider = processProvider;
_iisProvider = iisProvider; _iisProvider = iisProvider;
_webClientProvider = webClientProvider;
}
public MonitoringProvider()
{
} }
public void Start() public void Start()
@ -36,15 +42,11 @@ namespace NzbDrone.Providers
prioCheckTimer.Elapsed += EnsurePriority; prioCheckTimer.Elapsed += EnsurePriority;
prioCheckTimer.Enabled = true; prioCheckTimer.Enabled = true;
_pingTimer = new Timer(60000) { AutoReset = true }; _pingTimer = new Timer(60000) {AutoReset = true};
_pingTimer.Elapsed += (PingServer); _pingTimer.Elapsed += (PingServer);
_pingTimer.Start(); _pingTimer.Start();
} }
public MonitoringProvider()
{
}
public virtual void EnsurePriority(object sender, ElapsedEventArgs e) public virtual void EnsurePriority(object sender, ElapsedEventArgs e)
{ {
@ -68,16 +70,18 @@ namespace NzbDrone.Providers
try try
{ {
string response = new WebClient().DownloadString(_iisProvider.AppUrl + "/health"); string response = _webClientProvider.DownloadString(_iisProvider.AppUrl + "/health");
if (!response.Contains("OK")) if (!response.Contains("OK"))
{ {
throw new ServerException("Health services responded with an invalid response."); throw new ServerException("Health services responded with an invalid response.");
} }
if (_pingFailCounter > 0) if (_pingFailCounter > 0)
{ {
Logger.Info("Application pool has been successfully recovered."); Logger.Info("Application pool has been successfully recovered.");
} }
_pingFailCounter = 0; _pingFailCounter = 0;
} }
catch (Exception ex) catch (Exception ex)

@ -76,11 +76,11 @@ namespace NzbDrone.Providers
if (process == null) return null; if (process == null) return null;
return new ProcessInfo return new ProcessInfo
{ {
Id = process.Id, Id = process.Id,
Priority = process.PriorityClass, Priority = process.PriorityClass,
StartPath = process.MainModule.FileName StartPath = process.MainModule.FileName
}; };
} }
} }
} }

@ -14,11 +14,11 @@ namespace NzbDrone.Providers
private static readonly Logger Logger = LogManager.GetLogger("Host.ServiceManager"); private static readonly Logger Logger = LogManager.GetLogger("Host.ServiceManager");
public bool ServiceExist(string name) public bool ServiceExist(string name)
{ {
return return
System.ServiceProcess.ServiceController.GetServices().Any( ServiceController.GetServices().Any(
s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase)); s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
} }
@ -36,7 +36,7 @@ namespace NzbDrone.Providers
var serviceInstaller = new ServiceInstaller(); var serviceInstaller = new ServiceInstaller();
String[] cmdline = { @"/assemblypath=" + Assembly.GetExecutingAssembly().Location }; String[] cmdline = {@"/assemblypath=" + Assembly.GetExecutingAssembly().Location};
var context = new InstallContext("service_install.log", cmdline); var context = new InstallContext("service_install.log", cmdline);
serviceInstaller.Context = context; serviceInstaller.Context = context;

@ -1,17 +1,12 @@
using System; using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace NzbDrone.Providers namespace NzbDrone.Providers
{ {
public class WebClientProvider public class WebClientProvider
{ {
public virtual string DownloadString(string url) public virtual string DownloadString(string url)
{ {
return new WebClient().DownloadString(url); return new WebClient().DownloadString(url);
} }
} }
} }
Loading…
Cancel
Save