Some minor code cleanups

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-09-11 14:20:12 -04:00
parent 016590529f
commit 670a53258e
80 changed files with 318 additions and 1120 deletions

View File

@@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public ItemSpecialCounts GetSpecialCounts(User user)
{
ItemSpecialCounts counts = new ItemSpecialCounts();
var counts = new ItemSpecialCounts();
IEnumerable<BaseItem> recursiveChildren = GetParentalAllowedRecursiveChildren(user);

View File

@@ -5,7 +5,7 @@ namespace MediaBrowser.Controller.Entities
{
public class UserItemData
{
private float? _Rating = null;
private float? _Rating;
/// <summary>
/// Gets or sets the users 0-10 rating
/// </summary>

View File

@@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.FFMpeg
{
try
{
ProtobufSerializer.SerializeToFile<FFProbeResult>(result, outputCachePath);
ProtobufSerializer.SerializeToFile(result, outputCachePath);
}
catch (Exception ex)
{

View File

@@ -10,8 +10,8 @@ namespace MediaBrowser.Controller.IO
{
public class DirectoryWatchers
{
private List<FileSystemWatcher> FileSystemWatchers = new List<FileSystemWatcher>();
private Timer updateTimer = null;
private readonly List<FileSystemWatcher> FileSystemWatchers = new List<FileSystemWatcher>();
private Timer updateTimer;
private List<string> affectedPaths = new List<string>();
private const int TimerDelayInSeconds = 5;
@@ -107,10 +107,8 @@ namespace MediaBrowser.Controller.IO
{
return Kernel.Instance.ReloadRoot();
}
else
{
return Task.WhenAll(itemsToRefresh.Select(i => Kernel.Instance.ReloadItem(i)));
}
return Task.WhenAll(itemsToRefresh.Select(i => Kernel.Instance.ReloadItem(i)));
}
private BaseItem GetAffectedBaseItem(string path)

View File

@@ -149,7 +149,7 @@ namespace MediaBrowser.Controller.IO
private static extern bool FindClose(IntPtr hFindFile);
private const char SpaceChar = ' ';
private static char[] InvalidFileNameChars = Path.GetInvalidFileNameChars();
private static readonly char[] InvalidFileNameChars = Path.GetInvalidFileNameChars();
/// <summary>
/// Takes a filename and removes invalid characters

View File

@@ -93,13 +93,13 @@ namespace MediaBrowser.Controller
await base.Init(progress).ConfigureAwait(false);
progress.Report(new TaskProgress() { Description = "Loading Users", PercentComplete = 15 });
progress.Report(new TaskProgress { Description = "Loading Users", PercentComplete = 15 });
ReloadUsers();
progress.Report(new TaskProgress() { Description = "Loading Media Library", PercentComplete = 25 });
progress.Report(new TaskProgress { Description = "Loading Media Library", PercentComplete = 25 });
await ReloadRoot(allowInternetProviders: false).ConfigureAwait(false);
progress.Report(new TaskProgress() { Description = "Loading Complete", PercentComplete = 100 });
progress.Report(new TaskProgress { Description = "Loading Complete", PercentComplete = 100 });
}
protected override void OnComposablePartsLoaded()

View File

@@ -68,7 +68,7 @@ namespace MediaBrowser.Controller.Library
/// </summary>
public async Task<BaseItem> GetItem(string path, Folder parent = null, WIN32_FIND_DATA? fileInfo = null, bool allowInternetProviders = true)
{
ItemResolveEventArgs args = new ItemResolveEventArgs()
var args = new ItemResolveEventArgs
{
FileInfo = fileInfo ?? FileData.GetFileData(path),
Parent = parent,
@@ -113,7 +113,7 @@ namespace MediaBrowser.Controller.Library
if (item.IsFolder)
{
// If it's a folder look for child entities
(item as Folder).Children = (await Task.WhenAll<BaseItem>(GetChildren(item as Folder, fileSystemChildren, allowInternetProviders)).ConfigureAwait(false))
(item as Folder).Children = (await Task.WhenAll(GetChildren(item as Folder, fileSystemChildren, allowInternetProviders)).ConfigureAwait(false))
.Where(i => i != null).OrderBy(f =>
{
return string.IsNullOrEmpty(f.SortName) ? f.Name : f.SortName;
@@ -193,10 +193,8 @@ namespace MediaBrowser.Controller.Library
resolvedShortcuts.InsertRange(0, returnArray);
return resolvedShortcuts.ToArray();
}
else
{
return returnArray;
}
return returnArray;
}
/// <summary>
@@ -231,7 +229,7 @@ namespace MediaBrowser.Controller.Library
return GetImagesByNameItem<Year>(Kernel.Instance.ApplicationPaths.YearPath, value.ToString());
}
private ConcurrentDictionary<string, object> ImagesByNameItemCache = new ConcurrentDictionary<string, object>(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentDictionary<string, object> ImagesByNameItemCache = new ConcurrentDictionary<string, object>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Generically retrieves an IBN item

View File

@@ -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

View File

@@ -26,9 +26,6 @@ namespace MediaBrowser.Controller.Providers
{
MediaStream stream = data.streams.First(s => s.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase));
string bitrate = null;
string duration = null;
audio.Channels = stream.channels;
if (!string.IsNullOrEmpty(stream.sample_rate))
@@ -36,8 +33,8 @@ namespace MediaBrowser.Controller.Providers
audio.SampleRate = int.Parse(stream.sample_rate);
}
bitrate = stream.bit_rate;
duration = stream.duration;
string bitrate = stream.bit_rate;
string duration = stream.duration;
if (string.IsNullOrEmpty(bitrate))
{
@@ -78,7 +75,7 @@ namespace MediaBrowser.Controller.Providers
if (!string.IsNullOrEmpty(composer))
{
audio.AddPerson(new PersonInfo() { Name = composer, Type = "Composer" });
audio.AddPerson(new PersonInfo { Name = composer, Type = "Composer" });
}
audio.Album = GetDictionaryValue(tags, "album");

View File

@@ -62,7 +62,7 @@ namespace MediaBrowser.Controller.Providers
item.DisplayMediaType = VideoType.BluRay.ToString();
break;
case "dvd":
item.DisplayMediaType = VideoType.DVD.ToString();
item.DisplayMediaType = VideoType.Dvd.ToString();
break;
case "":
item.DisplayMediaType = null;
@@ -163,7 +163,7 @@ namespace MediaBrowser.Controller.Providers
case "Director":
{
foreach (PersonInfo p in GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo() { Name = v, Type = "Director" }))
foreach (PersonInfo p in GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo { Name = v, Type = "Director" }))
{
item.AddPerson(p);
}
@@ -171,7 +171,7 @@ namespace MediaBrowser.Controller.Providers
}
case "Writer":
{
foreach (PersonInfo p in GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo() { Name = v, Type = "Writer" }))
foreach (PersonInfo p in GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo { Name = v, Type = "Writer" }))
{
item.AddPerson(p);
}
@@ -181,7 +181,7 @@ namespace MediaBrowser.Controller.Providers
case "Actors":
case "GuestStars":
{
foreach (PersonInfo p in GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo() { Name = v, Type = "Actor" }))
foreach (PersonInfo p in GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo { Name = v, Type = "Actor" }))
{
item.AddPerson(p);
}

View File

@@ -34,10 +34,8 @@ namespace MediaBrowser.Controller.Providers
{
return Task.Run(() => { PopulateBaseItemImages(baseItem, args); });
}
else
{
return Task.Run(() => { PopulateImages(item, args); });
}
return Task.Run(() => { PopulateImages(item, args); });
}
return Task.FromResult<object>(null);

View File

@@ -46,7 +46,7 @@ namespace MediaBrowser.Controller.Resolvers.Movies
private void SetProviderIdFromPath(Movie item)
{
string srch = "[tmdbid=";
const string srch = "[tmdbid=";
int index = item.Path.IndexOf(srch, System.StringComparison.OrdinalIgnoreCase);
if (index != -1)

View File

@@ -48,8 +48,8 @@ namespace MediaBrowser.Controller.Resolvers.TV
private void SetProviderIdFromPath(Series item)
{
string srch = "[tvdbid=";
int index = item.Path.IndexOf(srch, System.StringComparison.OrdinalIgnoreCase);
const string srch = "[tvdbid=";
int index = item.Path.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
if (index != -1)
{

View File

@@ -9,7 +9,7 @@ namespace MediaBrowser.Controller.Resolvers.TV
/// <summary>
/// A season folder must contain one of these somewhere in the name
/// </summary>
private static string[] SeasonFolderNames = new string[] {
private static readonly string[] SeasonFolderNames = new string[] {
"season",
"sæson",
"temporada",
@@ -118,14 +118,12 @@ namespace MediaBrowser.Controller.Resolvers.TV
{
return true;
}
else
{
nonSeriesFolders++;
if (nonSeriesFolders >= 3)
{
return false;
}
nonSeriesFolders++;
if (nonSeriesFolders >= 3)
{
return false;
}
}
else

View File

@@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.Resolvers
{
VideoType type = Path.GetExtension(args.Path).EndsWith("iso", System.StringComparison.OrdinalIgnoreCase) ? VideoType.Iso : VideoType.VideoFile;
return new T()
return new T
{
VideoType = type,
Path = args.Path
@@ -77,15 +77,15 @@ namespace MediaBrowser.Controller.Resolvers
{
if (folder.IndexOf("video_ts", System.StringComparison.OrdinalIgnoreCase) != -1)
{
return new T()
return new T
{
VideoType = VideoType.DVD,
VideoType = VideoType.Dvd,
Path = Path.GetDirectoryName(folder)
};
}
if (folder.IndexOf("bdmv", System.StringComparison.OrdinalIgnoreCase) != -1)
{
return new T()
return new T
{
VideoType = VideoType.BluRay,
Path = Path.GetDirectoryName(folder)

View File

@@ -153,7 +153,7 @@ namespace MediaBrowser.Controller
}
}
private string _CacheDirectory = null;
private string _CacheDirectory;
/// <summary>
/// Gets the folder path to the cache directory
/// </summary>
@@ -175,7 +175,7 @@ namespace MediaBrowser.Controller
}
}
private string _FFProbeAudioCacheDirectory = null;
private string _FFProbeAudioCacheDirectory;
/// <summary>
/// Gets the folder path to the ffprobe audio cache directory
/// </summary>
@@ -197,7 +197,7 @@ namespace MediaBrowser.Controller
}
}
private string _FFProbeVideoCacheDirectory = null;
private string _FFProbeVideoCacheDirectory;
/// <summary>
/// Gets the folder path to the ffprobe video cache directory
/// </summary>
@@ -219,7 +219,7 @@ namespace MediaBrowser.Controller
}
}
private string _FFMpegDirectory = null;
private string _FFMpegDirectory;
/// <summary>
/// Gets the folder path to ffmpeg
/// </summary>
@@ -241,7 +241,7 @@ namespace MediaBrowser.Controller
}
}
private string _FFMpegPath = null;
private string _FFMpegPath;
/// <summary>
/// Gets the path to ffmpeg.exe
/// </summary>
@@ -258,7 +258,7 @@ namespace MediaBrowser.Controller
}
}
private string _FFProbePath = null;
private string _FFProbePath;
/// <summary>
/// Gets the path to ffprobe.exe
/// </summary>

View File

@@ -1,13 +1,13 @@
using System;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Weather;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Net.Http;
using System.Threading.Tasks;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Weather;
namespace MediaBrowser.Controller.Weather
{
@@ -36,8 +36,8 @@ namespace MediaBrowser.Controller.Weather
return null;
}
int numDays = 5;
string apiKey = "24902f60f1231941120109";
const int numDays = 5;
const string apiKey = "24902f60f1231941120109";
string url = "http://free.worldweatheronline.com/feed/weather.ashx?q=" + zipCode + "&format=json&num_of_days=" + numDays + "&key=" + apiKey;
@@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.Weather
public WeatherStatus ToWeatherStatus()
{
return new WeatherStatus()
return new WeatherStatus
{
TemperatureCelsius = int.Parse(temp_C),
TemperatureFahrenheit = int.Parse(temp_F),
@@ -122,7 +122,7 @@ namespace MediaBrowser.Controller.Weather
public WeatherForecast ToWeatherForecast()
{
return new WeatherForecast()
return new WeatherForecast
{
Date = DateTime.Parse(date),
HighTemperatureCelsius = int.Parse(tempMaxC),

View File

@@ -5,7 +5,7 @@ namespace MediaBrowser.Controller.Xml
{
public static class XmlExtensions
{
private static CultureInfo _usCulture = new CultureInfo("en-US");
private static readonly CultureInfo _usCulture = new CultureInfo("en-US");
/// <summary>
/// Reads a float from the current element of an XmlReader