resharper suggestions in common implementations

This commit is contained in:
Luke Pulverenti 2013-04-10 11:45:15 -04:00
parent 7806ccd42f
commit d8263c7057
11 changed files with 52 additions and 63 deletions

View File

@ -149,7 +149,7 @@ namespace MediaBrowser.Common.Implementations
protected IConfigurationManager ConfigurationManager { get; private set; } protected IConfigurationManager ConfigurationManager { get; private set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost" /> class. /// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary> /// </summary>
protected BaseApplicationHost() protected BaseApplicationHost()
{ {

View File

@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations
/// <summary> /// <summary>
/// Gets the path to the system folder /// Gets the path to the system folder
/// </summary> /// </summary>
public string ProgramSystemPath { get { return Path.Combine(ProgramDataPath, "System"); }} public string ProgramSystemPath { get { return Path.Combine(ProgramDataPath, "System"); } }
/// <summary> /// <summary>
/// The _data directory /// The _data directory
@ -303,6 +303,11 @@ namespace MediaBrowser.Common.Implementations
var path = Assembly.GetExecutingAssembly().Location; var path = Assembly.GetExecutingAssembly().Location;
path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path);
if (string.IsNullOrEmpty(path))
{
throw new ApplicationException("Unable to determine running assembly location");
}
programDataPath = Path.Combine(path, programDataPath); programDataPath = Path.Combine(path, programDataPath);
programDataPath = Path.GetFullPath(programDataPath); programDataPath = Path.GetFullPath(programDataPath);

View File

@ -1,6 +1,4 @@
using System.Globalization; using MediaBrowser.Common.Configuration;
using System.Net.Http.Headers;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO; using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
@ -8,6 +6,7 @@ using MediaBrowser.Model.Net;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Cache; using System.Net.Cache;
@ -214,7 +213,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
{ {
var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp"); 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"); protected static readonly CultureInfo UsCulture = new CultureInfo("en-US");
@ -224,11 +223,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// </summary> /// </summary>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="tempFile">The temp file.</param> /// <param name="tempFile">The temp file.</param>
/// <param name="resumeCount">The resume count.</param>
/// <returns>Task{System.String}.</returns> /// <returns>Task{System.String}.</returns>
/// <exception cref="System.ArgumentNullException">progress</exception> /// <exception cref="System.ArgumentNullException">progress</exception>
/// <exception cref="HttpException"></exception> /// <exception cref="HttpException"></exception>
private async Task<string> GetTempFile(HttpRequestOptions options, string tempFile, int resumeCount) private async Task<string> GetTempFile(HttpRequestOptions options, string tempFile)
{ {
ValidateParams(options.Url, options.CancellationToken); ValidateParams(options.Url, options.CancellationToken);

View File

@ -52,10 +52,11 @@ namespace MediaBrowser.Common.Implementations.Logging
/// <param name="level">The level.</param> /// <param name="level">The level.</param>
private void AddFileTarget(string path, LogSeverity level) private void AddFileTarget(string path, LogSeverity level)
{ {
var logFile = new FileTarget(); var logFile = new FileTarget
{
logFile.FileName = path; FileName = path,
logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}"; Layout = "${longdate}, ${level}, ${logger}, ${message}"
};
RemoveTarget("ApplicationLogFile"); RemoveTarget("ApplicationLogFile");
logFile.Name = "ApplicationLogFile"; logFile.Name = "ApplicationLogFile";

View File

@ -308,11 +308,7 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement
//check if we have an IPv6 or ports //check if we have an IPv6 or ports
if (values.Length <= 2) // ipv4 or hostname if (values.Length <= 2) // ipv4 or hostname
{ {
if (values.Length == 1) port = values.Length == 1 ? defaultport : GetPort(values[1]);
//no port is specified, default
port = defaultport;
else
port = GetPort(values[1]);
//try to use the address as IPv4, otherwise get hostname //try to use the address as IPv4, otherwise get hostname
if (!IPAddress.TryParse(values[0], out ipaddy)) if (!IPAddress.TryParse(values[0], out ipaddy))

View File

@ -45,8 +45,11 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
/// <param name="Server"></param> /// <param name="server">The server.</param>
/// <param name="shi"></param> /// <param name="netName">Name of the net.</param>
/// <param name="path">The path.</param>
/// <param name="shareType">Type of the share.</param>
/// <param name="remark">The remark.</param>
public Share(string server, string netName, string path, ShareType shareType, string remark) public Share(string server, string netName, string path, ShareType shareType, string remark)
{ {
if (ShareType.Special == shareType && "IPC$" == netName) if (ShareType.Special == shareType && "IPC$" == netName)
@ -423,9 +426,9 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement
int nRet = 0; int nRet = 0;
ushort entriesRead, totalEntries; ushort entriesRead, totalEntries;
Type t = typeof(SHARE_INFO_50); var t = typeof(SHARE_INFO_50);
int size = Marshal.SizeOf(t); var size = Marshal.SizeOf(t);
ushort cbBuffer = (ushort)(MAX_SI50_ENTRIES * size); var cbBuffer = (ushort)(MAX_SI50_ENTRIES * size);
//On Win9x, must allocate buffer before calling API //On Win9x, must allocate buffer before calling API
IntPtr pBuffer = Marshal.AllocHGlobal(cbBuffer); 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) 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) 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); shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark);
} }
else 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); shares.Add(si.NetName, si.Path, si.ShareType, si.Remark);
} }
} }
@ -542,7 +545,7 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
/// <param name="Server"></param> /// <param name="server">The server.</param>
public ShareCollection(string server) public ShareCollection(string server)
{ {
_server = server; _server = server;
@ -598,9 +601,9 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement
Share match = null; 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)) if (s.IsFileSystem && s.MatchesPath(path))
{ {

View File

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following

View File

@ -56,7 +56,17 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// <param name="taskManager">The task manager.</param> /// <param name="taskManager">The task manager.</param>
/// <param name="jsonSerializer">The json serializer.</param> /// <param name="jsonSerializer">The json serializer.</param>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="serverManager">The server manager.</param> /// <exception cref="System.ArgumentNullException">
/// scheduledTask
/// or
/// applicationPaths
/// or
/// taskManager
/// or
/// jsonSerializer
/// or
/// logger
/// </exception>
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger) public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger)
{ {
if (scheduledTask == null) if (scheduledTask == null)
@ -217,7 +227,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
{ {
get get
{ {
LazyInitializer.EnsureInitialized(ref _triggers, ref _triggersInitialized, ref _triggersSyncLock, () => LoadTriggers()); LazyInitializer.EnsureInitialized(ref _triggers, ref _triggersInitialized, ref _triggersSyncLock, LoadTriggers);
return _triggers; return _triggers;
} }

View File

@ -1,6 +1,5 @@
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -20,21 +19,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// </summary> /// </summary>
/// <value>The application paths.</value> /// <value>The application paths.</value>
private IApplicationPaths ApplicationPaths { get; set; } private IApplicationPaths ApplicationPaths { get; set; }
/// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
private ILogger Logger { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DeleteCacheFileTask" /> class. /// Initializes a new instance of the <see cref="DeleteCacheFileTask" /> class.
/// </summary> /// </summary>
/// <param name="appPaths">The app paths.</param> /// <param name="appPaths">The app paths.</param>
/// <param name="logger">The logger.</param> public DeleteCacheFileTask(IApplicationPaths appPaths)
public DeleteCacheFileTask(IApplicationPaths appPaths, ILogger logger)
{ {
ApplicationPaths = appPaths; ApplicationPaths = appPaths;
Logger = logger;
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,5 @@
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -20,21 +19,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// </summary> /// </summary>
/// <value>The configuration manager.</value> /// <value>The configuration manager.</value>
private IConfigurationManager ConfigurationManager { get; set; } private IConfigurationManager ConfigurationManager { get; set; }
/// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
private ILogger Logger { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DeleteLogFileTask" /> class. /// Initializes a new instance of the <see cref="DeleteLogFileTask" /> class.
/// </summary> /// </summary>
/// <param name="configurationManager">The configuration manager.</param> /// <param name="configurationManager">The configuration manager.</param>
/// <param name="logger">The logger.</param> public DeleteLogFileTask(IConfigurationManager configurationManager)
public DeleteLogFileTask(IConfigurationManager configurationManager, ILogger logger)
{ {
ConfigurationManager = configurationManager; ConfigurationManager = configurationManager;
Logger = logger;
} }
/// <summary> /// <summary>

View File

@ -19,11 +19,6 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// <value>The log manager.</value> /// <value>The log manager.</value>
private ILogManager LogManager { get; set; } private ILogManager LogManager { get; set; }
/// <summary> /// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
private ILogger Logger { get; set; }
/// <summary>
/// Gets or sets the configuration manager. /// Gets or sets the configuration manager.
/// </summary> /// </summary>
/// <value>The configuration manager.</value> /// <value>The configuration manager.</value>
@ -33,12 +28,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class. /// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class.
/// </summary> /// </summary>
/// <param name="logManager">The logManager.</param> /// <param name="logManager">The logManager.</param>
/// <param name="logger">The logger.</param>
/// <param name="configurationManager">The configuration manager.</param> /// <param name="configurationManager">The configuration manager.</param>
public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IConfigurationManager configurationManager) public ReloadLoggerFileTask(ILogManager logManager, IConfigurationManager configurationManager)
{ {
LogManager = logManager; LogManager = logManager;
Logger = logger;
ConfigurationManager = configurationManager; ConfigurationManager = configurationManager;
} }