From d8263c70574c6cb27329e270aebe3ba231f5e9ce Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 Apr 2013 11:45:15 -0400 Subject: [PATCH] resharper suggestions in common implementations --- .../BaseApplicationHost.cs | 2 +- .../BaseApplicationPaths.cs | 11 +++++-- .../HttpClientManager/HttpClientManager.cs | 12 +++---- .../Logging/NlogManager.cs | 9 +++--- .../NetworkManagement/NetworkManager.cs | 6 +--- .../NetworkManagement/NetworkShares.cs | 31 ++++++++++--------- .../Properties/AssemblyInfo.cs | 1 - .../ScheduledTasks/ScheduledTaskWorker.cs | 14 +++++++-- .../Tasks/DeleteCacheFileTask.cs | 10 +----- .../ScheduledTasks/Tasks/DeleteLogFileTask.cs | 10 +----- .../ScheduledTasks/Tasks/ReloadLoggerTask.cs | 9 +----- 11 files changed, 52 insertions(+), 63 deletions(-) diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 6be6826f4..4578da827 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -149,7 +149,7 @@ namespace MediaBrowser.Common.Implementations protected IConfigurationManager ConfigurationManager { get; private set; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// protected BaseApplicationHost() { diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index 56e699b35..0bd8b9df8 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations /// /// Gets the path to the system folder /// - public string ProgramSystemPath { get { return Path.Combine(ProgramDataPath, "System"); }} + public string ProgramSystemPath { get { return Path.Combine(ProgramDataPath, "System"); } } /// /// The _data directory @@ -291,7 +291,7 @@ namespace MediaBrowser.Common.Implementations /// Gets the path to the application's ProgramDataFolder /// /// System.String. - private string GetProgramDataPath() + private string GetProgramDataPath() { var programDataPath = _useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : Path.Combine(ConfigurationManager.AppSettings["ReleaseProgramDataPath"], ConfigurationManager.AppSettings["ProgramDataFolderName"]); @@ -303,11 +303,16 @@ namespace MediaBrowser.Common.Implementations var path = Assembly.GetExecutingAssembly().Location; path = Path.GetDirectoryName(path); + if (string.IsNullOrEmpty(path)) + { + throw new ApplicationException("Unable to determine running assembly location"); + } + programDataPath = Path.Combine(path, programDataPath); programDataPath = Path.GetFullPath(programDataPath); } - + if (!Directory.Exists(programDataPath)) { Directory.CreateDirectory(programDataPath); diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 8508fcdf5..f8edda203 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -1,6 +1,4 @@ -using System.Globalization; -using System.Net.Http.Headers; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; using MediaBrowser.Model.Logging; @@ -8,6 +6,7 @@ using MediaBrowser.Model.Net; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Net.Cache; @@ -214,21 +213,20 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager { var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp"); - return GetTempFile(options, tempFile, 0); + return GetTempFile(options, tempFile); } protected static readonly CultureInfo UsCulture = new CultureInfo("en-US"); - + /// /// Gets the temp file. /// /// The options. /// The temp file. - /// The resume count. /// Task{System.String}. /// progress /// - private async Task GetTempFile(HttpRequestOptions options, string tempFile, int resumeCount) + private async Task GetTempFile(HttpRequestOptions options, string tempFile) { ValidateParams(options.Url, options.CancellationToken); diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index ec93fbd8e..2917632b8 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -52,10 +52,11 @@ namespace MediaBrowser.Common.Implementations.Logging /// The level. private void AddFileTarget(string path, LogSeverity level) { - var logFile = new FileTarget(); - - logFile.FileName = path; - logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}"; + var logFile = new FileTarget + { + FileName = path, + Layout = "${longdate}, ${level}, ${logger}, ${message}" + }; RemoveTarget("ApplicationLogFile"); logFile.Name = "ApplicationLogFile"; diff --git a/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs b/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs index d88b57be5..3c42d340b 100644 --- a/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs +++ b/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs @@ -308,11 +308,7 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement //check if we have an IPv6 or ports if (values.Length <= 2) // ipv4 or hostname { - if (values.Length == 1) - //no port is specified, default - port = defaultport; - else - port = GetPort(values[1]); + port = values.Length == 1 ? defaultport : GetPort(values[1]); //try to use the address as IPv4, otherwise get hostname if (!IPAddress.TryParse(values[0], out ipaddy)) diff --git a/MediaBrowser.Common.Implementations/NetworkManagement/NetworkShares.cs b/MediaBrowser.Common.Implementations/NetworkManagement/NetworkShares.cs index e2a8275cf..d06c6b2e2 100644 --- a/MediaBrowser.Common.Implementations/NetworkManagement/NetworkShares.cs +++ b/MediaBrowser.Common.Implementations/NetworkManagement/NetworkShares.cs @@ -45,8 +45,11 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement /// /// Constructor /// - /// - /// + /// The server. + /// Name of the net. + /// The path. + /// Type of the share. + /// The remark. public Share(string server, string netName, string path, ShareType shareType, string remark) { if (ShareType.Special == shareType && "IPC$" == netName) @@ -423,9 +426,9 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement int nRet = 0; ushort entriesRead, totalEntries; - Type t = typeof(SHARE_INFO_50); - int size = Marshal.SizeOf(t); - ushort cbBuffer = (ushort)(MAX_SI50_ENTRIES * size); + var t = typeof(SHARE_INFO_50); + var size = Marshal.SizeOf(t); + var cbBuffer = (ushort)(MAX_SI50_ENTRIES * size); //On Win9x, must allocate buffer before calling API IntPtr pBuffer = Marshal.AllocHGlobal(cbBuffer); @@ -448,16 +451,16 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement { for (int i = 0, lpItem = pBuffer.ToInt32(); i < entriesRead; i++, lpItem += size) { - IntPtr pItem = new IntPtr(lpItem); + var pItem = new IntPtr(lpItem); if (1 == level) { - SHARE_INFO_1_9x si = (SHARE_INFO_1_9x)Marshal.PtrToStructure(pItem, t); + var si = (SHARE_INFO_1_9x)Marshal.PtrToStructure(pItem, t); shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark); } else { - SHARE_INFO_50 si = (SHARE_INFO_50)Marshal.PtrToStructure(pItem, t); + var si = (SHARE_INFO_50)Marshal.PtrToStructure(pItem, t); shares.Add(si.NetName, si.Path, si.ShareType, si.Remark); } } @@ -542,7 +545,7 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement /// /// Constructor /// - /// + /// The server. public ShareCollection(string server) { _server = server; @@ -598,9 +601,9 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement Share match = null; - for (int i = 0; i < InnerList.Count; i++) + foreach (object t in InnerList) { - Share s = (Share)InnerList[i]; + var s = (Share)t; if (s.IsFileSystem && s.MatchesPath(path)) { @@ -608,9 +611,9 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement if (null == match) match = s; - // If this has a longer path, - // and this is a disk share or match is a special share, - // then this is a better match + // If this has a longer path, + // and this is a disk share or match is a special share, + // then this is a better match else if (match.Path.Length < s.Path.Length) { if (ShareType.Disk == s.ShareType || ShareType.Disk != match.ShareType) diff --git a/MediaBrowser.Common.Implementations/Properties/AssemblyInfo.cs b/MediaBrowser.Common.Implementations/Properties/AssemblyInfo.cs index f9c3e0bd1..63a83e003 100644 --- a/MediaBrowser.Common.Implementations/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Common.Implementations/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index f57d48f07..94fb3ce86 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -56,7 +56,17 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// The task manager. /// The json serializer. /// The logger. - /// The server manager. + /// + /// scheduledTask + /// or + /// applicationPaths + /// or + /// taskManager + /// or + /// jsonSerializer + /// or + /// logger + /// public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger) { if (scheduledTask == null) @@ -217,7 +227,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { get { - LazyInitializer.EnsureInitialized(ref _triggers, ref _triggersInitialized, ref _triggersSyncLock, () => LoadTriggers()); + LazyInitializer.EnsureInitialized(ref _triggers, ref _triggersInitialized, ref _triggersSyncLock, LoadTriggers); return _triggers; } diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index c7a19c0c0..be3dd89f7 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.ScheduledTasks; -using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.IO; @@ -20,21 +19,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// /// The application paths. private IApplicationPaths ApplicationPaths { get; set; } - /// - /// Gets or sets the logger. - /// - /// The logger. - private ILogger Logger { get; set; } /// /// Initializes a new instance of the class. /// /// The app paths. - /// The logger. - public DeleteCacheFileTask(IApplicationPaths appPaths, ILogger logger) + public DeleteCacheFileTask(IApplicationPaths appPaths) { ApplicationPaths = appPaths; - Logger = logger; } /// diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs index faeb39735..bcead321d 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.ScheduledTasks; -using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.IO; @@ -20,21 +19,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// /// The configuration manager. private IConfigurationManager ConfigurationManager { get; set; } - /// - /// Gets or sets the logger. - /// - /// The logger. - private ILogger Logger { get; set; } /// /// Initializes a new instance of the class. /// /// The configuration manager. - /// The logger. - public DeleteLogFileTask(IConfigurationManager configurationManager, ILogger logger) + public DeleteLogFileTask(IConfigurationManager configurationManager) { ConfigurationManager = configurationManager; - Logger = logger; } /// diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs index a02f9dec6..e860834ec 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs @@ -19,11 +19,6 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// The log manager. private ILogManager LogManager { get; set; } /// - /// Gets or sets the logger. - /// - /// The logger. - private ILogger Logger { get; set; } - /// /// Gets or sets the configuration manager. /// /// The configuration manager. @@ -33,12 +28,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// Initializes a new instance of the class. /// /// The logManager. - /// The logger. /// The configuration manager. - public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IConfigurationManager configurationManager) + public ReloadLoggerFileTask(ILogManager logManager, IConfigurationManager configurationManager) { LogManager = logManager; - Logger = logger; ConfigurationManager = configurationManager; }