resharper suggestions in controller project

pull/702/head
Luke Pulverenti 11 years ago
parent d8263c7057
commit ff1db0a173

@ -1,5 +1,4 @@
using System.Globalization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
@ -7,13 +6,13 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
@ -208,7 +207,7 @@ namespace MediaBrowser.Controller.Drawing
var outputFormat = originalImage.RawFormat;
using (var memoryStream = new MemoryStream { })
using (var memoryStream = new MemoryStream())
{
// Save to the memory stream
thumbnail.Save(outputFormat, memoryStream, quality.Value);

@ -1,5 +1,4 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
@ -313,7 +312,7 @@ namespace MediaBrowser.Controller.Entities
var path = Path;
// non file-system entries will not have a path
if (this.LocationType != LocationType.FileSystem || string.IsNullOrEmpty(path))
if (LocationType != LocationType.FileSystem || string.IsNullOrEmpty(path))
{
return new ItemResolveArgs(ConfigurationManager.ApplicationPaths)
{
@ -637,12 +636,12 @@ namespace MediaBrowser.Controller.Entities
catch (IOException ex)
{
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
return new List<Video> { };
return new List<Video>();
}
if (!resolveArgs.IsDirectory)
{
return new List<Video> { };
return new List<Video>();
}
var folder = resolveArgs.GetFileSystemEntryByName(TrailerFolderName);
@ -650,7 +649,7 @@ namespace MediaBrowser.Controller.Entities
// Path doesn't exist. No biggie
if (folder == null)
{
return new List<Video> { };
return new List<Video>();
}
IEnumerable<WIN32_FIND_DATA> files;
@ -662,7 +661,7 @@ namespace MediaBrowser.Controller.Entities
catch (IOException ex)
{
Logger.ErrorException("Error loading trailers for {0}", ex, Name);
return new List<Video> { };
return new List<Video>();
}
return LibraryManager.ResolvePaths<Video>(files, null).Select(video =>

@ -4,7 +4,6 @@ using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Concurrent;
@ -714,7 +713,7 @@ namespace MediaBrowser.Controller.Entities
catch (IOException ex)
{
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
return new List<BaseItem> { };
return new List<BaseItem>();
}
return LibraryManager.ResolvePaths<BaseItem>(fileSystemChildren, this);
@ -754,12 +753,7 @@ namespace MediaBrowser.Controller.Entities
}
// If indexed is false or the indexing function is null
if (result == null)
{
result = ActualChildren.Where(c => c.IsVisible(user));
}
return result;
return result ?? (ActualChildren.Where(c => c.IsVisible(user)));
}
/// <summary>
@ -799,7 +793,7 @@ namespace MediaBrowser.Controller.Entities
{
await base.ChangedExternally().ConfigureAwait(false);
var progress = new Progress<double> { };
var progress = new Progress<double>();
await ValidateChildren(progress, CancellationToken.None).ConfigureAwait(false);
}

@ -118,14 +118,12 @@ namespace MediaBrowser.Controller.Entities.Movies
cancellationToken.ThrowIfCancellationRequested();
return result;
}
}
/// <summary>
/// Loads special features from the file system
/// Loads the special features.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>List{Video}.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
/// <returns>IEnumerable{Video}.</returns>
private IEnumerable<Video> LoadSpecialFeatures()
{
WIN32_FIND_DATA? folder;
@ -137,13 +135,13 @@ namespace MediaBrowser.Controller.Entities.Movies
catch (IOException ex)
{
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
return new List<Video> { };
return new List<Video>();
}
// Path doesn't exist. No biggie
if (folder == null)
{
return new List<Video> { };
return new List<Video>();
}
IEnumerable<WIN32_FIND_DATA> files;
@ -155,7 +153,7 @@ namespace MediaBrowser.Controller.Entities.Movies
catch (IOException ex)
{
Logger.ErrorException("Error loading trailers for {0}", ex, Name);
return new List<Video> { };
return new List<Video>();
}
return LibraryManager.ResolvePaths<Video>(files, null).Select(video =>

@ -5,7 +5,6 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
@ -266,7 +265,7 @@ namespace MediaBrowser.Controller.Entities
RootFolder = null;
// Kick off a task to validate the media library
Task.Run(() => ValidateMediaLibrary(new Progress<double> { }, CancellationToken.None));
Task.Run(() => ValidateMediaLibrary(new Progress<double>(), CancellationToken.None));
return RefreshMetadata(CancellationToken.None, forceSave: true, forceRefresh: true);
}

@ -76,6 +76,7 @@ namespace MediaBrowser.Controller
/// <value>The FF MPEG stream cache path.</value>
string EncodedMediaCachePath { get; }
/// <summary>
/// Gets the downloaded images data path.
/// </summary>
/// <value>The downloaded images data path.</value>

@ -1,6 +1,5 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Entities;
@ -20,9 +19,9 @@ namespace MediaBrowser.Controller.Library
event EventHandler<ChildrenChangedEventArgs> LibraryChanged;
/// <summary>
/// Raises the <see cref="E:LibraryChanged" /> event.
/// Reports the library changed.
/// </summary>
/// <param name="args">The <see cref="ChildrenChangedEventArgs" /> instance containing the event data.</param>
/// <param name="args">The <see cref="ChildrenChangedEventArgs"/> instance containing the event data.</param>
void ReportLibraryChanged(ChildrenChangedEventArgs args);
/// <summary>

@ -12,16 +12,16 @@ namespace MediaBrowser.Controller.Library
/// <summary>
/// The name
/// </summary>
readonly string name;
readonly string _name;
/// <summary>
/// The stopwatch
/// </summary>
readonly Stopwatch stopwatch;
readonly Stopwatch _stopwatch;
/// <summary>
/// The _logger
/// </summary>
private ILogger _logger;
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="Profiler" /> class.
@ -30,12 +30,12 @@ namespace MediaBrowser.Controller.Library
/// <param name="logger">The logger.</param>
public Profiler(string name, ILogger logger)
{
this.name = name;
this._name = name;
_logger = logger;
stopwatch = new Stopwatch();
stopwatch.Start();
_stopwatch = new Stopwatch();
_stopwatch.Start();
}
#region IDisposable Members
@ -56,17 +56,17 @@ namespace MediaBrowser.Controller.Library
{
if (dispose)
{
stopwatch.Stop();
_stopwatch.Stop();
string message;
if (stopwatch.ElapsedMilliseconds > 300000)
if (_stopwatch.ElapsedMilliseconds > 300000)
{
message = string.Format("{0} took {1} minutes.",
name, ((float)stopwatch.ElapsedMilliseconds / 60000).ToString("F"));
_name, ((float)_stopwatch.ElapsedMilliseconds / 60000).ToString("F"));
}
else
{
message = string.Format("{0} took {1} seconds.",
name, ((float)stopwatch.ElapsedMilliseconds / 1000).ToString("#0.000"));
_name, ((float)_stopwatch.ElapsedMilliseconds / 1000).ToString("#0.000"));
}
_logger.Info(message);
}

@ -277,9 +277,7 @@ namespace MediaBrowser.Controller.Library
};
}
return new List<DayOfWeek>
{
};
return new List<DayOfWeek>();
}
return null;
}

@ -1,12 +1,9 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Logging;
using System;
using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Serialization;
namespace MediaBrowser.Controller.Localization
{
@ -30,7 +27,7 @@ namespace MediaBrowser.Controller.Localization
/// </summary>
private static LocalizedStrings _instance;
private IServerApplicationPaths _appPaths;
private readonly IServerApplicationPaths _appPaths;
/// <summary>
/// Gets the instance.

@ -1,6 +1,4 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Logging;
using MediaBrowser.Controller.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -44,17 +42,16 @@ namespace MediaBrowser.Controller.Localization
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private static bool TryAdd<TKey, TValue>(Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
private static void TryAdd<TKey, TValue>(Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
if (dictionary.ContainsKey(key))
{
return false;
return;
}
dictionary.Add(key, value);
return true;
}
/// <summary>
/// Initializes the specified block unrated.
/// </summary>
@ -65,7 +62,7 @@ namespace MediaBrowser.Controller.Localization
//build our ratings dictionary from the combined local one and us one
ratingsDef = new RatingsDefinition(Path.Combine(configurationManager.ApplicationPaths.LocalizationPath, "Ratings-" + configurationManager.Configuration.MetadataCountryCode + ".txt"), configurationManager);
//global value of None
var dict = new Dictionary<string, int> {{"None", -1}};
var dict = new Dictionary<string, int> { { "None", -1 } };
foreach (var pair in ratingsDef.RatingsDict)
{
TryAdd(dict, pair.Key, pair.Value);
@ -85,7 +82,7 @@ namespace MediaBrowser.Controller.Localization
//and rating reverse lookup dictionary (non-redundant ones)
ratingsStrings.Clear();
var lastLevel = -10;
ratingsStrings.Add(-1,LocalizedStrings.Instance.GetString("Any"));
ratingsStrings.Add(-1, LocalizedStrings.Instance.GetString("Any"));
foreach (var pair in ratingsDef.RatingsDict.OrderBy(p => p.Value))
{
if (pair.Value > lastLevel)
@ -147,7 +144,7 @@ namespace MediaBrowser.Controller.Localization
public static string ToString(int level)
{
//return the closest one
while (level > 0)
while (level > 0)
{
if (ratingsStrings.ContainsKey(level))
return ratingsStrings[level];

@ -1,5 +1,4 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.IO;
@ -15,7 +14,6 @@ namespace MediaBrowser.Controller.Localization
/// Initializes a new instance of the <see cref="RatingsDefinition" /> class.
/// </summary>
/// <param name="file">The file.</param>
/// <param name="logger">The logger.</param>
/// <param name="configurationManager">The configuration manager.</param>
public RatingsDefinition(string file, IServerConfigurationManager configurationManager)
{

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;

@ -27,6 +27,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="isoManager">The iso manager.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="mediaEncoder">The media encoder.</param>
public FfMpegVideoImageProvider(IIsoManager isoManager, ILogManager logManager, IServerConfigurationManager configurationManager, IMediaEncoder mediaEncoder)
: base(logManager, configurationManager, mediaEncoder)
{

@ -309,7 +309,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
long currentChapterTicks = 0;
var index = 1;
var chapters = new List<ChapterInfo> { };
var chapters = new List<ChapterInfo>();
while (currentChapterTicks < runtime)
{
@ -372,7 +372,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
}
// Fill video properties from the BDInfo result
Fetch(video, inputPath, result);
Fetch(video, result);
videoStream = video.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video);
@ -399,9 +399,8 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// Fills video properties from the VideoStream of the largest playlist
/// </summary>
/// <param name="video">The video.</param>
/// <param name="inputPath">The input path.</param>
/// <param name="stream">The stream.</param>
private void Fetch(Video video, string inputPath, BlurayDiscInfo stream)
private void Fetch(Video video, BlurayDiscInfo stream)
{
// Check all input for null/empty/zero

@ -19,8 +19,6 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
class FanArtMovieProvider : FanartBaseProvider, IDisposable
{
internal static FanArtMovieProvider Current { get; private set; }
/// <summary>
/// Gets the HTTP client.
/// </summary>
@ -28,13 +26,14 @@ namespace MediaBrowser.Controller.Providers.Movies
protected IHttpClient HttpClient { get; private set; }
private readonly IProviderManager _providerManager;
/// <summary>
/// Initializes a new instance of the <see cref="FanArtMovieProvider" /> class.
/// </summary>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="providerManager">The provider manager.</param>
/// <exception cref="System.ArgumentNullException">httpClient</exception>
public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)

@ -60,6 +60,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="providerManager">The provider manager.</param>
public MovieDbProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, IProviderManager providerManager)
: base(logManager, configurationManager)
{
@ -157,7 +158,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{
try
{
using (var json = await httpClient.Get(String.Format(TmdbConfigUrl, ApiKey), MovieDbProvider.Current.MovieDbResourcePool, CancellationToken.None).ConfigureAwait(false))
using (var json = await httpClient.Get(String.Format(TmdbConfigUrl, ApiKey), Current.MovieDbResourcePool, CancellationToken.None).ConfigureAwait(false))
{
return jsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
}

@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Common.Extensions;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers.Music
{

@ -1,15 +1,13 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

@ -36,7 +36,7 @@ namespace MediaBrowser.Controller.Providers.Music
// Get albu info using artist and album name
var url = RootUrl + string.Format("method=album.getInfo&artist={0}&album={1}&api_key={2}&format=json", UrlEncode(item.Parent.Name), UrlEncode(item.Name), ApiKey);
LastfmGetAlbumResult result = null;
LastfmGetAlbumResult result;
try
{

@ -1,19 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers.Music
{
@ -28,7 +24,7 @@ namespace MediaBrowser.Controller.Providers.Music
LocalMetaFileName = LastfmHelper.LocalArtistMetaFileName;
}
protected override async Task<string> FindId(Entities.BaseItem item, System.Threading.CancellationToken cancellationToken)
protected override async Task<string> FindId(BaseItem item, CancellationToken cancellationToken)
{
//Execute the Artist search against our name and assume first one is the one we want
var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey);
@ -99,7 +95,7 @@ namespace MediaBrowser.Controller.Providers.Music
}
}
public override bool Supports(Entities.BaseItem item)
public override bool Supports(BaseItem item)
{
return item is MusicArtist;
}

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using System;
@ -17,19 +16,12 @@ namespace MediaBrowser.Controller.Providers.Music
artist.Overview = overview;
var yearFormed = 0;
try
{
yearFormed = Convert.ToInt32(data.bio.yearformed);
}
catch (FormatException)
{
}
catch (NullReferenceException)
{
}
catch (OverflowException)
if (data.bio != null)
{
Int32.TryParse(data.bio.yearformed, out yearFormed);
}
artist.PremiereDate = yearFormed > 0 ? new DateTime(yearFormed, 1,1) : DateTime.MinValue;
artist.ProductionYear = yearFormed;
if (data.tags != null)
@ -46,7 +38,7 @@ namespace MediaBrowser.Controller.Providers.Music
item.Overview = overview;
var release = DateTime.MinValue;
DateTime release;
DateTime.TryParse(data.releasedate, out release);
item.PremiereDate = release;
item.ProductionYear = release.Year;

@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers.Music
{

@ -3,7 +3,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers.Movies;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;

@ -148,6 +148,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// </summary>
/// <param name="episode">The episode.</param>
/// <param name="seriesId">The series id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
private async Task<bool> FetchEpisodeData(Episode episode, string seriesId, CancellationToken cancellationToken)
{

@ -45,6 +45,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="httpClient">The HTTP client.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="providerManager">The provider manager.</param>
/// <exception cref="System.ArgumentNullException">httpClient</exception>
public RemoteSeriesProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)

Loading…
Cancel
Save