From 670a53258ef79ee92f578335577df4f768c9d7d4 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 11 Sep 2012 14:20:12 -0400 Subject: [PATCH] Some minor code cleanups --- MediaBrowser.Api/ApiService.cs | 47 +- MediaBrowser.Api/HttpHandlers/AudioHandler.cs | 2 +- .../HttpHandlers/BaseMediaHandler.cs | 22 +- .../HttpHandlers/FavoriteStatusHandler.cs | 7 +- .../HttpHandlers/GenresHandler.cs | 2 +- MediaBrowser.Api/HttpHandlers/ImageHandler.cs | 34 +- MediaBrowser.Api/HttpHandlers/ItemHandler.cs | 6 +- .../HttpHandlers/ItemListHandler.cs | 22 +- .../MovieSpecialFeaturesHandler.cs | 10 +- .../HttpHandlers/PlayedStatusHandler.cs | 7 +- .../HttpHandlers/PluginAssemblyHandler.cs | 2 +- .../PluginConfigurationHandler.cs | 10 +- .../HttpHandlers/PluginsHandler.cs | 4 +- .../ServerConfigurationHandler.cs | 2 +- .../HttpHandlers/StudiosHandler.cs | 2 +- MediaBrowser.Api/HttpHandlers/UserHandler.cs | 10 +- .../HttpHandlers/UserItemRatingHandler.cs | 7 +- MediaBrowser.Api/HttpHandlers/UsersHandler.cs | 6 +- MediaBrowser.Api/HttpHandlers/VideoHandler.cs | 24 +- MediaBrowser.Api/HttpHandlers/YearsHandler.cs | 2 +- MediaBrowser.Api/Properties/AssemblyInfo.cs | 1 - .../DataSerializer.cs | 2 +- .../ApiClient.cs | 585 ------------------ ...ediaBrowser.ApiInteraction.Portable.csproj | 72 --- .../Properties/AssemblyInfo.cs | 30 - MediaBrowser.ApiInteraction.sln | 6 - MediaBrowser.ApiInteraction/BaseApiClient.cs | 4 +- .../BaseHttpApiClient.cs | 72 +-- MediaBrowser.ApiInteraction/DataSerializer.cs | 8 +- .../Properties/AssemblyInfo.cs | 1 - MediaBrowser.Common/Kernel/BaseKernel.cs | 10 +- MediaBrowser.Common/Logging/BaseLogger.cs | 2 +- MediaBrowser.Common/Logging/LogRow.cs | 4 +- MediaBrowser.Common/Logging/StreamLogger.cs | 12 +- MediaBrowser.Common/Logging/ThreadedLogger.cs | 73 --- .../MediaBrowser.Common.csproj | 1 - .../Handlers/BaseEmbeddedResourceHandler.cs | 4 +- .../Net/Handlers/BaseHandler.cs | 11 +- .../Net/Handlers/BaseSerializationHandler.cs | 24 +- .../Net/Handlers/StaticFileHandler.cs | 24 +- MediaBrowser.Common/Net/HttpServer.cs | 2 +- MediaBrowser.Common/Net/MimeTypes.cs | 64 +- MediaBrowser.Common/Plugins/BasePlugin.cs | 4 +- .../Properties/AssemblyInfo.cs | 1 - .../Serialization/JsonSerializer.cs | 6 +- .../Serialization/JsvSerializer.cs | 4 +- .../Serialization/ProtobufSerializer.cs | 4 +- .../Serialization/XmlSerializer.cs | 2 +- MediaBrowser.Common/UI/BaseApplication.cs | 4 +- MediaBrowser.Common/UI/SingleInstance.cs | 9 +- MediaBrowser.Common/UI/Splash.xaml.cs | 4 +- MediaBrowser.Controller/Entities/Folder.cs | 2 +- .../Entities/UserItemData.cs | 2 +- MediaBrowser.Controller/FFMpeg/FFProbe.cs | 2 +- .../IO/DirectoryWatchers.cs | 10 +- MediaBrowser.Controller/IO/FileData.cs | 2 +- MediaBrowser.Controller/Kernel.cs | 6 +- .../Library/ItemController.cs | 12 +- .../Properties/AssemblyInfo.cs | 1 - .../Providers/AudioInfoProvider.cs | 9 +- .../Providers/BaseItemXmlParser.cs | 8 +- .../ImageFromMediaLocationProvider.cs | 6 +- .../Resolvers/Movies/MovieResolver.cs | 2 +- .../Resolvers/TV/SeriesResolver.cs | 4 +- .../Resolvers/TV/TVUtils.cs | 14 +- .../Resolvers/VideoResolver.cs | 8 +- .../ServerApplicationPaths.cs | 12 +- .../Weather/WeatherClient.cs | 16 +- MediaBrowser.Controller/Xml/XmlExtensions.cs | 2 +- MediaBrowser.Model/DTO/DTOBaseItem.cs | 8 +- MediaBrowser.Model/DTO/DTOUser.cs | 5 +- MediaBrowser.Model/DTO/DTOUserItemData.cs | 2 +- MediaBrowser.Model/DTO/VideoOutputFormats.cs | 4 +- .../Entities/IHasProviderIds.cs | 2 +- MediaBrowser.Model/Entities/VideoType.cs | 2 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 6 +- .../Plugins/BasePluginConfiguration.cs | 4 +- MediaBrowser.Model/Properties/AssemblyInfo.cs | 6 +- .../Properties/AssemblyInfo.cs | 2 - .../Properties/AssemblyInfo.cs | 1 - 80 files changed, 318 insertions(+), 1120 deletions(-) delete mode 100644 MediaBrowser.ApiInteraction.Portable/ApiClient.cs delete mode 100644 MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj delete mode 100644 MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs delete mode 100644 MediaBrowser.Common/Logging/ThreadedLogger.cs diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs index 88af0f8134..938a34f60c 100644 --- a/MediaBrowser.Api/ApiService.cs +++ b/MediaBrowser.Api/ApiService.cs @@ -3,7 +3,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.DTO; -using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -33,9 +32,9 @@ namespace MediaBrowser.Api /// Whether or not to update the user's LastActivityDate public static User GetUserById(string id, bool logActivity) { - Guid guid = new Guid(id); + var guid = new Guid(id); - User user = Kernel.Instance.Users.FirstOrDefault(u => u.Id == guid); + var user = Kernel.Instance.Users.FirstOrDefault(u => u.Id == guid); if (logActivity) { @@ -73,11 +72,11 @@ namespace MediaBrowser.Api /// /// Converts a BaseItem to a DTOBaseItem /// - public async static Task GetDTOBaseItem(BaseItem item, User user, + public async static Task GetDtoBaseItem(BaseItem item, User user, bool includeChildren = true, bool includePeople = true) { - DTOBaseItem dto = new DTOBaseItem(); + DtoBaseItem dto = new DtoBaseItem(); List tasks = new List(); @@ -108,7 +107,7 @@ namespace MediaBrowser.Api /// /// Sets simple property values on a DTOBaseItem /// - private static void AttachBasicFields(DTOBaseItem dto, BaseItem item, User user) + private static void AttachBasicFields(DtoBaseItem dto, BaseItem item, User user) { dto.AspectRatio = item.AspectRatio; dto.BackdropCount = item.BackdropImagePaths == null ? 0 : item.BackdropImagePaths.Count(); @@ -173,7 +172,7 @@ namespace MediaBrowser.Api dto.Type = item.GetType().Name; dto.UserRating = item.UserRating; - dto.UserData = GetDTOUserItemData(item.GetUserData(user, false)); + dto.UserData = GetDtoUserItemData(item.GetUserData(user, false)); Folder folder = item as Folder; @@ -190,7 +189,7 @@ namespace MediaBrowser.Api if (audio != null) { - dto.AudioInfo = new AudioInfo() + dto.AudioInfo = new AudioInfo { Album = audio.Album, AlbumArtist = audio.AlbumArtist, @@ -205,7 +204,7 @@ namespace MediaBrowser.Api if (video != null) { - dto.VideoInfo = new VideoInfo() + dto.VideoInfo = new VideoInfo { Height = video.Height, Width = video.Width, @@ -232,7 +231,7 @@ namespace MediaBrowser.Api { DayOfWeek[] airDays = series.AirDays == null ? new DayOfWeek[] { } : series.AirDays.ToArray(); ; - dto.SeriesInfo = new SeriesInfo() + dto.SeriesInfo = new SeriesInfo { AirDays = airDays, AirTime = series.AirTime, @@ -247,7 +246,7 @@ namespace MediaBrowser.Api { int specialFeatureCount = movie.SpecialFeatures == null ? 0 : movie.SpecialFeatures.Count(); - dto.MovieInfo = new MovieInfo() + dto.MovieInfo = new MovieInfo { SpecialFeatureCount = specialFeatureCount }; @@ -257,12 +256,12 @@ namespace MediaBrowser.Api /// /// Attaches Studio DTO's to a DTOBaseItem /// - private static async Task AttachStudios(DTOBaseItem dto, BaseItem item) + private static async Task AttachStudios(DtoBaseItem dto, BaseItem item) { // Attach Studios by transforming them into BaseItemStudio (DTO) if (item.Studios != null) { - Studio[] entities = await Task.WhenAll(item.Studios.Select(c => Kernel.Instance.ItemController.GetStudio(c))).ConfigureAwait(false); + Studio[] entities = await Task.WhenAll(item.Studios.Select(c => Kernel.Instance.ItemController.GetStudio(c))).ConfigureAwait(false); dto.Studios = new BaseItemStudio[entities.Length]; @@ -283,7 +282,7 @@ namespace MediaBrowser.Api /// /// Attaches child DTO's to a DTOBaseItem /// - private static async Task AttachChildren(DTOBaseItem dto, BaseItem item, User user) + private static async Task AttachChildren(DtoBaseItem dto, BaseItem item, User user) { var folder = item as Folder; @@ -291,30 +290,30 @@ namespace MediaBrowser.Api { IEnumerable children = folder.GetParentalAllowedChildren(user); - dto.Children = await Task.WhenAll(children.Select(c => GetDTOBaseItem(c, user, false, false))).ConfigureAwait(false); + dto.Children = await Task.WhenAll(children.Select(c => GetDtoBaseItem(c, user, false, false))).ConfigureAwait(false); } } /// /// Attaches trailer DTO's to a DTOBaseItem /// - private static async Task AttachLocalTrailers(DTOBaseItem dto, BaseItem item, User user) + private static async Task AttachLocalTrailers(DtoBaseItem dto, BaseItem item, User user) { if (item.LocalTrailers != null && item.LocalTrailers.Any()) { - dto.LocalTrailers = await Task.WhenAll(item.LocalTrailers.Select(c => GetDTOBaseItem(c, user, false, false))).ConfigureAwait(false); + dto.LocalTrailers = await Task.WhenAll(item.LocalTrailers.Select(c => GetDtoBaseItem(c, user, false, false))).ConfigureAwait(false); } } /// /// Attaches People DTO's to a DTOBaseItem /// - private static async Task AttachPeople(DTOBaseItem dto, BaseItem item) + private static async Task AttachPeople(DtoBaseItem dto, BaseItem item) { // Attach People by transforming them into BaseItemPerson (DTO) if (item.People != null) { - IEnumerable entities = await Task.WhenAll(item.People.Select(c => Kernel.Instance.ItemController.GetPerson(c.Key))).ConfigureAwait(false); + IEnumerable entities = await Task.WhenAll(item.People.Select(c => Kernel.Instance.ItemController.GetPerson(c.Key))).ConfigureAwait(false); dto.People = item.People.Select(p => { @@ -384,7 +383,7 @@ namespace MediaBrowser.Api /// public static IBNItem GetIBNItem(BaseEntity entity, int itemCount) { - return new IBNItem() + return new IBNItem { Id = entity.Id, BaseItemCount = itemCount, @@ -396,9 +395,9 @@ namespace MediaBrowser.Api /// /// Converts a User to a DTOUser /// - public static DTOUser GetDTOUser(User user) + public static DtoUser GetDtoUser(User user) { - return new DTOUser() + return new DtoUser { Id = user.Id, Name = user.Name, @@ -412,14 +411,14 @@ namespace MediaBrowser.Api /// /// Converts a UserItemData to a DTOUserItemData /// - public static DTOUserItemData GetDTOUserItemData(UserItemData data) + public static DtoUserItemData GetDtoUserItemData(UserItemData data) { if (data == null) { return null; } - return new DTOUserItemData() + return new DtoUserItemData { IsFavorite = data.IsFavorite, Likes = data.Likes, diff --git a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs index 3d17a3d6a2..9c16acd2ef 100644 --- a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs @@ -86,7 +86,7 @@ namespace MediaBrowser.Api.HttpHandlers /// protected override string GetCommandLineArguments() { - List audioTranscodeParams = new List(); + var audioTranscodeParams = new List(); AudioOutputFormats outputFormat = GetConversionOutputFormat(); diff --git a/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs b/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs index e87af76ea5..32fdb7efa2 100644 --- a/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs @@ -38,7 +38,7 @@ namespace MediaBrowser.Api.HttpHandlers } } - private TBaseItemType _LibraryItem; + private TBaseItemType _libraryItem; /// /// Gets the library item that will be played, if any /// @@ -46,17 +46,17 @@ namespace MediaBrowser.Api.HttpHandlers { get { - if (_LibraryItem == null) + if (_libraryItem == null) { string id = QueryString["id"]; if (!string.IsNullOrEmpty(id)) { - _LibraryItem = Kernel.Instance.GetItemById(Guid.Parse(id)) as TBaseItemType; + _libraryItem = Kernel.Instance.GetItemById(Guid.Parse(id)) as TBaseItemType; } } - return _LibraryItem; + return _libraryItem; } } @@ -92,7 +92,7 @@ namespace MediaBrowser.Api.HttpHandlers public override Task GetContentType() { - return Task.FromResult(MimeTypes.GetMimeType("." + GetConversionOutputFormat())); + return Task.FromResult(MimeTypes.GetMimeType("." + GetConversionOutputFormat())); } public override bool ShouldCompressResponse(string contentType) @@ -106,12 +106,10 @@ namespace MediaBrowser.Api.HttpHandlers if (!RequiresConversion()) { - return new StaticFileHandler() { Path = LibraryItem.Path }.ProcessRequest(ctx); - } - else - { - return base.ProcessRequest(ctx); + return new StaticFileHandler { Path = LibraryItem.Path }.ProcessRequest(ctx); } + + return base.ProcessRequest(ctx); } protected abstract string GetCommandLineArguments(); @@ -173,7 +171,7 @@ namespace MediaBrowser.Api.HttpHandlers process.EnableRaisingEvents = true; - process.Exited += process_Exited; + process.Exited += ProcessExited; try { @@ -203,7 +201,7 @@ namespace MediaBrowser.Api.HttpHandlers } } - void process_Exited(object sender, EventArgs e) + void ProcessExited(object sender, EventArgs e) { if (LogFileStream != null) { diff --git a/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs b/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs index 4125b940f1..19c175d8b8 100644 --- a/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs @@ -1,7 +1,6 @@ using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.DTO; -using MediaBrowser.Model.Entities; using System.ComponentModel.Composition; using System.Net; using System.Threading.Tasks; @@ -12,14 +11,14 @@ namespace MediaBrowser.Api.HttpHandlers /// Provides a handler to set user favorite status for an item /// [Export(typeof(BaseHandler))] - public class FavoriteStatusHandler : BaseSerializationHandler + public class FavoriteStatusHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("FavoriteStatus", request); } - protected override Task GetObjectToSerialize() + protected override Task GetObjectToSerialize() { // Get the item BaseItem item = ApiService.GetItemById(QueryString["id"]); @@ -33,7 +32,7 @@ namespace MediaBrowser.Api.HttpHandlers // Set favorite status data.IsFavorite = QueryString["isfavorite"] == "1"; - return Task.FromResult(ApiService.GetDTOUserItemData(data)); + return Task.FromResult(ApiService.GetDtoUserItemData(data)); } } } \ No newline at end of file diff --git a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs index 0ff48761ca..2694756dd3 100644 --- a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.Api.HttpHandlers } // Get the Genre objects - Genre[] entities = await Task.WhenAll(data.Keys.Select(key => { return Kernel.Instance.ItemController.GetGenre(key); })).ConfigureAwait(false); + Genre[] entities = await Task.WhenAll(data.Keys.Select(key => { return Kernel.Instance.ItemController.GetGenre(key); })).ConfigureAwait(false); // Convert to an array of IBNItem IBNItem[] items = new IBNItem[entities.Length]; diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs index c5949122fa..11246d4058 100644 --- a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs @@ -21,15 +21,15 @@ namespace MediaBrowser.Api.HttpHandlers return ApiService.IsApiUrlMatch("image", request); } - private string _ImagePath = null; + private string _imagePath; private async Task GetImagePath() { - if (_ImagePath == null) + if (_imagePath == null) { - _ImagePath = await DiscoverImagePath(); + _imagePath = await DiscoverImagePath(); } - return _ImagePath; + return _imagePath; } private async Task DiscoverImagePath() @@ -77,21 +77,21 @@ namespace MediaBrowser.Api.HttpHandlers return GetImagePathFromTypes(item, ImageType, index); } - private Stream _SourceStream = null; + private Stream _sourceStream; private async Task GetSourceStream() { await EnsureSourceStream().ConfigureAwait(false); - return _SourceStream; + return _sourceStream; } - private bool _SourceStreamEnsured = false; + private bool _sourceStreamEnsured; private async Task EnsureSourceStream() { - if (!_SourceStreamEnsured) + if (!_sourceStreamEnsured) { try { - _SourceStream = File.OpenRead(await GetImagePath().ConfigureAwait(false)); + _sourceStream = File.OpenRead(await GetImagePath().ConfigureAwait(false)); } catch (FileNotFoundException ex) { @@ -110,7 +110,7 @@ namespace MediaBrowser.Api.HttpHandlers } finally { - _SourceStreamEnsured = true; + _sourceStreamEnsured = true; } } } @@ -248,26 +248,24 @@ namespace MediaBrowser.Api.HttpHandlers { return item.LogoImagePath; } - else if (imageType == ImageType.Backdrop) + if (imageType == ImageType.Backdrop) { return item.BackdropImagePaths.ElementAt(imageIndex); } - else if (imageType == ImageType.Banner) + if (imageType == ImageType.Banner) { return item.BannerImagePath; } - else if (imageType == ImageType.Art) + if (imageType == ImageType.Art) { return item.ArtImagePath; } - else if (imageType == ImageType.Thumbnail) + if (imageType == ImageType.Thumbnail) { return item.ThumbnailImagePath; } - else - { - return item.PrimaryImagePath; - } + + return item.PrimaryImagePath; } } } diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index 491f45446d..60b328d1a3 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -11,14 +11,14 @@ namespace MediaBrowser.Api.HttpHandlers /// Provides a handler to retrieve a single item /// [Export(typeof(BaseHandler))] - public class ItemHandler : BaseSerializationHandler + public class ItemHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("item", request); } - protected override Task GetObjectToSerialize() + protected override Task GetObjectToSerialize() { User user = ApiService.GetUserById(QueryString["userid"], true); @@ -29,7 +29,7 @@ namespace MediaBrowser.Api.HttpHandlers return null; } - return ApiService.GetDTOBaseItem(item, user); + return ApiService.GetDtoBaseItem(item, user); } } } diff --git a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs index bce018d3ef..e4044b1d7b 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs @@ -11,20 +11,20 @@ using System.Threading.Tasks; namespace MediaBrowser.Api.HttpHandlers { [Export(typeof(BaseHandler))] - public class ItemListHandler : BaseSerializationHandler + public class ItemListHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("itemlist", request); } - protected override Task GetObjectToSerialize() + protected override Task GetObjectToSerialize() { User user = ApiService.GetUserById(QueryString["userid"], true); - return Task.WhenAll(GetItemsToSerialize(user).Select(i => + return Task.WhenAll(GetItemsToSerialize(user).Select(i => { - return ApiService.GetDTOBaseItem(i, user, includeChildren: false, includePeople: false); + return ApiService.GetDtoBaseItem(i, user, includeChildren: false, includePeople: false); })); } @@ -36,31 +36,31 @@ namespace MediaBrowser.Api.HttpHandlers { return parent.GetInProgressItems(user); } - else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase)) { return parent.GetRecentlyAddedItems(user); } - else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase)) { return parent.GetRecentlyAddedUnplayedItems(user); } - else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase)) { return parent.GetItemsWithGenre(QueryString["name"], user); } - else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase)) { return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user); } - else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase)) { return parent.GetItemsWithStudio(QueryString["name"], user); } - else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase)) { return parent.GetItemsWithPerson(QueryString["name"], null, user); } - else if (ListType.Equals("favorites", StringComparison.OrdinalIgnoreCase)) + if (ListType.Equals("favorites", StringComparison.OrdinalIgnoreCase)) { return parent.GetFavoriteItems(user); } diff --git a/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs b/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs index 63426be47d..cfd75c8cfa 100644 --- a/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs @@ -13,14 +13,14 @@ namespace MediaBrowser.Api.HttpHandlers /// This handler retrieves special features for movies /// [Export(typeof(BaseHandler))] - public class MovieSpecialFeaturesHandler : BaseSerializationHandler + public class MovieSpecialFeaturesHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("MovieSpecialFeatures", request); } - protected override Task GetObjectToSerialize() + protected override Task GetObjectToSerialize() { User user = ApiService.GetUserById(QueryString["userid"], true); @@ -29,12 +29,12 @@ namespace MediaBrowser.Api.HttpHandlers // If none if (movie.SpecialFeatures == null) { - return Task.FromResult(new DTOBaseItem[] { }); + return Task.FromResult(new DtoBaseItem[] { }); } - return Task.WhenAll(movie.SpecialFeatures.Select(i => + return Task.WhenAll(movie.SpecialFeatures.Select(i => { - return ApiService.GetDTOBaseItem(i, user, includeChildren: false, includePeople: true); + return ApiService.GetDtoBaseItem(i, user, includeChildren: false); })); } diff --git a/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs b/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs index 4fe790c801..c010bcb023 100644 --- a/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs @@ -1,7 +1,6 @@ using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.DTO; -using MediaBrowser.Model.Entities; using System.ComponentModel.Composition; using System.Net; using System.Threading.Tasks; @@ -12,14 +11,14 @@ namespace MediaBrowser.Api.HttpHandlers /// Provides a handler to set played status for an item /// [Export(typeof(BaseHandler))] - public class PlayedStatusHandler : BaseSerializationHandler + public class PlayedStatusHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("PlayedStatus", request); } - protected override Task GetObjectToSerialize() + protected override Task GetObjectToSerialize() { // Get the item BaseItem item = ApiService.GetItemById(QueryString["id"]); @@ -33,7 +32,7 @@ namespace MediaBrowser.Api.HttpHandlers UserItemData data = item.GetUserData(user, true); - return Task.FromResult(ApiService.GetDTOUserItemData(data)); + return Task.FromResult(ApiService.GetDtoUserItemData(data)); } } } \ No newline at end of file diff --git a/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs index 07e6115a59..88161c1140 100644 --- a/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Api.HttpHandlers string path = Path.Combine(Kernel.Instance.ApplicationPaths.PluginsPath, filename); - return new StaticFileHandler() { Path = path }.ProcessRequest(ctx); + return new StaticFileHandler { Path = path }.ProcessRequest(ctx); } } } diff --git a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs index 6dafd41707..95af9a3442 100644 --- a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs @@ -18,25 +18,25 @@ namespace MediaBrowser.Api.HttpHandlers return ApiService.IsApiUrlMatch("pluginconfiguration", request); } - private BasePlugin _Plugin = null; + private BasePlugin _plugin; private BasePlugin Plugin { get { - if (_Plugin == null) + if (_plugin == null) { string name = QueryString["assemblyfilename"]; - _Plugin = Kernel.Instance.Plugins.First(p => p.AssemblyFileName.Equals(name, StringComparison.OrdinalIgnoreCase)); + _plugin = Kernel.Instance.Plugins.First(p => p.AssemblyFileName.Equals(name, StringComparison.OrdinalIgnoreCase)); } - return _Plugin; + return _plugin; } } protected override Task GetObjectToSerialize() { - return Task.FromResult(Plugin.Configuration); + return Task.FromResult(Plugin.Configuration); } public override TimeSpan CacheDuration diff --git a/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs index e90f322391..e9de0c476a 100644 --- a/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs @@ -24,7 +24,7 @@ namespace MediaBrowser.Api.HttpHandlers { var plugins = Kernel.Instance.Plugins.Select(p => { - return new PluginInfo() + return new PluginInfo { Name = p.Name, Enabled = p.Enabled, @@ -35,7 +35,7 @@ namespace MediaBrowser.Api.HttpHandlers }; }); - return Task.FromResult>(plugins); + return Task.FromResult(plugins); } } } diff --git a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs index bbda31dc61..64ba44ec2f 100644 --- a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Api.HttpHandlers protected override Task GetObjectToSerialize() { - return Task.FromResult(Kernel.Instance.Configuration); + return Task.FromResult(Kernel.Instance.Configuration); } public override TimeSpan CacheDuration diff --git a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs index f80bed0896..86aa7c9c94 100644 --- a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.Api.HttpHandlers } // Get the Studio objects - Studio[] entities = await Task.WhenAll(data.Keys.Select(key => { return Kernel.Instance.ItemController.GetStudio(key); })).ConfigureAwait(false); + Studio[] entities = await Task.WhenAll(data.Keys.Select(key => { return Kernel.Instance.ItemController.GetStudio(key); })).ConfigureAwait(false); // Convert to an array of IBNItem IBNItem[] items = new IBNItem[entities.Length]; diff --git a/MediaBrowser.Api/HttpHandlers/UserHandler.cs b/MediaBrowser.Api/HttpHandlers/UserHandler.cs index 5ccf3bb619..8b9e657661 100644 --- a/MediaBrowser.Api/HttpHandlers/UserHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/UserHandler.cs @@ -8,22 +8,22 @@ using System.Threading.Tasks; namespace MediaBrowser.Api.HttpHandlers { [Export(typeof(BaseHandler))] - class UserHandler : BaseSerializationHandler + class UserHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("user", request); } - - protected override Task GetObjectToSerialize() + + protected override Task GetObjectToSerialize() { string id = QueryString["id"]; User user = string.IsNullOrEmpty(id) ? ApiService.GetDefaultUser(false) : ApiService.GetUserById(id, false); ; - DTOUser dto = ApiService.GetDTOUser(user); + DtoUser dto = ApiService.GetDtoUser(user); - return Task.FromResult(dto); + return Task.FromResult(dto); } } } diff --git a/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs b/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs index d040414088..aed0804b6d 100644 --- a/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs @@ -1,7 +1,6 @@ using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.DTO; -using MediaBrowser.Model.Entities; using System.ComponentModel.Composition; using System.Net; using System.Threading.Tasks; @@ -12,14 +11,14 @@ namespace MediaBrowser.Api.HttpHandlers /// Provides a handler to set a user's rating for an item /// [Export(typeof(BaseHandler))] - public class UserItemRatingHandler : BaseSerializationHandler + public class UserItemRatingHandler : BaseSerializationHandler { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("UserItemRating", request); } - protected override Task GetObjectToSerialize() + protected override Task GetObjectToSerialize() { // Get the item BaseItem item = ApiService.GetItemById(QueryString["id"]); @@ -41,7 +40,7 @@ namespace MediaBrowser.Api.HttpHandlers data.Likes = QueryString["likes"] == "1"; } - return Task.FromResult(ApiService.GetDTOUserItemData(data)); + return Task.FromResult(ApiService.GetDtoUserItemData(data)); } } } \ No newline at end of file diff --git a/MediaBrowser.Api/HttpHandlers/UsersHandler.cs b/MediaBrowser.Api/HttpHandlers/UsersHandler.cs index 1451216bc6..3fc3a7d585 100644 --- a/MediaBrowser.Api/HttpHandlers/UsersHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/UsersHandler.cs @@ -10,16 +10,16 @@ using System.Threading.Tasks; namespace MediaBrowser.Api.HttpHandlers { [Export(typeof(BaseHandler))] - class UsersHandler : BaseSerializationHandler> + class UsersHandler : BaseSerializationHandler> { public override bool HandlesRequest(HttpListenerRequest request) { return ApiService.IsApiUrlMatch("users", request); } - protected override Task> GetObjectToSerialize() + protected override Task> GetObjectToSerialize() { - return Task.FromResult>(Kernel.Instance.Users.Select(u => ApiService.GetDTOUser(u))); + return Task.FromResult(Kernel.Instance.Users.Select(u => ApiService.GetDtoUser(u))); } } } diff --git a/MediaBrowser.Api/HttpHandlers/VideoHandler.cs b/MediaBrowser.Api/HttpHandlers/VideoHandler.cs index 4f8621ce7e..5e61127c6c 100644 --- a/MediaBrowser.Api/HttpHandlers/VideoHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/VideoHandler.cs @@ -34,7 +34,7 @@ namespace MediaBrowser.Api.HttpHandlers // mp4, 3gp, mov - muxer does not support non-seekable output // avi, mov, mkv, m4v - can't stream these when encoding. the player will try to download them completely before starting playback. // wmv - can't seem to figure out the output format name - return new VideoOutputFormats[] { VideoOutputFormats.Mp4, VideoOutputFormats.ThreeGP, VideoOutputFormats.M4v, VideoOutputFormats.Mkv, VideoOutputFormats.Avi, VideoOutputFormats.Mov, VideoOutputFormats.Wmv }; + return new VideoOutputFormats[] { VideoOutputFormats.Mp4, VideoOutputFormats.ThreeGp, VideoOutputFormats.M4V, VideoOutputFormats.Mkv, VideoOutputFormats.Avi, VideoOutputFormats.Mov, VideoOutputFormats.Wmv }; } } @@ -87,11 +87,11 @@ namespace MediaBrowser.Api.HttpHandlers { return "matroska"; } - else if (outputFormat == VideoOutputFormats.Ts) + if (outputFormat == VideoOutputFormats.Ts) { return "mpegts"; } - else if (outputFormat == VideoOutputFormats.Ogv) + if (outputFormat == VideoOutputFormats.Ogv) { return "ogg"; } @@ -104,8 +104,6 @@ namespace MediaBrowser.Api.HttpHandlers /// protected override string GetCommandLineArguments() { - List audioTranscodeParams = new List(); - VideoOutputFormats outputFormat = GetConversionOutputFormat(); return string.Format("-i \"{0}\" -threads 0 {1} {2} -f {3} -", @@ -195,15 +193,15 @@ namespace MediaBrowser.Api.HttpHandlers // Per webm specification, it must be vpx return "libvpx"; } - else if (outputFormat == VideoOutputFormats.Asf) + if (outputFormat == VideoOutputFormats.Asf) { return "wmv2"; } - else if (outputFormat == VideoOutputFormats.Wmv) + if (outputFormat == VideoOutputFormats.Wmv) { return "wmv2"; } - else if (outputFormat == VideoOutputFormats.Ogv) + if (outputFormat == VideoOutputFormats.Ogv) { return "libtheora"; } @@ -223,21 +221,21 @@ namespace MediaBrowser.Api.HttpHandlers private string GetAudioCodec(AudioStream audioStream, VideoOutputFormats outputFormat) { // Some output containers require specific codecs - + if (outputFormat == VideoOutputFormats.Webm) { // Per webm specification, it must be vorbis return "libvorbis"; } - else if (outputFormat == VideoOutputFormats.Asf) + if (outputFormat == VideoOutputFormats.Asf) { return "wmav2"; } - else if (outputFormat == VideoOutputFormats.Wmv) + if (outputFormat == VideoOutputFormats.Wmv) { return "wmav2"; } - else if (outputFormat == VideoOutputFormats.Ogv) + if (outputFormat == VideoOutputFormats.Ogv) { return "libvorbis"; } @@ -263,7 +261,7 @@ namespace MediaBrowser.Api.HttpHandlers // libvo_aacenc currently only supports two channel output return 2; } - else if (audioCodec.Equals("wmav2")) + if (audioCodec.Equals("wmav2")) { // wmav2 currently only supports two channel output return 2; diff --git a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs index c33464c4cc..a8c97294c4 100644 --- a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs @@ -57,7 +57,7 @@ namespace MediaBrowser.Api.HttpHandlers } // Get the Year objects - Year[] entities = await Task.WhenAll(data.Keys.Select(key => { return Kernel.Instance.ItemController.GetYear(key); })).ConfigureAwait(false); + Year[] entities = await Task.WhenAll(data.Keys.Select(key => { return Kernel.Instance.ItemController.GetYear(key); })).ConfigureAwait(false); // Convert to an array of IBNItem IBNItem[] items = new IBNItem[entities.Length]; diff --git a/MediaBrowser.Api/Properties/AssemblyInfo.cs b/MediaBrowser.Api/Properties/AssemblyInfo.cs index bd747ea7da..c92346bac1 100644 --- a/MediaBrowser.Api/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Api/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.ApiInteraction.Metro/DataSerializer.cs b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs index d63e3f0213..92e3f7c2b7 100644 --- a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs +++ b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.ApiInteraction /// This means that this class can currently only handle types within the Model project. /// If we need to, we can always add a param indicating whether or not the model serializer should be used. /// - private static ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); + private static readonly ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); public static T DeserializeFromStream(Stream stream, SerializationFormats format) where T : class diff --git a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs b/MediaBrowser.ApiInteraction.Portable/ApiClient.cs deleted file mode 100644 index b41572cd36..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/ApiClient.cs +++ /dev/null @@ -1,585 +0,0 @@ -using MediaBrowser.Model.Authentication; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.DTO; -using MediaBrowser.Model.Weather; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; - -namespace MediaBrowser.ApiInteraction.Portable -{ - public class ApiClient : BaseApiClient - { - private HttpWebRequest GetNewRequest(string url) - { - return HttpWebRequest.CreateHttp(url); - } - - /// - /// Gets an image stream based on a url - /// - public void GetImageStreamAsync(string url, Action callback) - { - GetStreamAsync(url, callback); - } - - /// - /// Gets an image stream based on a url - /// - private void GetStreamAsync(string url, Action callback) - { - HttpWebRequest request = GetNewRequest(url); - - request.BeginGetResponse(new AsyncCallback(result => - { - using (WebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result)) - { - Stream stream = response.GetResponseStream(); - callback(stream); - } - - }), request); - } - - /// - /// Gets a BaseItem - /// - public void GetItemAsync(Guid id, Guid userId, Action callback) - { - string url = ApiUrl + "/item?userId=" + userId.ToString(); - - if (id != Guid.Empty) - { - url += "&id=" + id.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets all users - /// - public void GetAllUsersAsync(Action callback) - { - string url = ApiUrl + "/users"; - - GetDataAsync(url, callback); - } - - /// - /// Gets all Genres - /// - public void GetAllGenresAsync(Guid userId, Action callback) - { - string url = ApiUrl + "/genres?userId=" + userId.ToString(); - - GetDataAsync(url, callback); - } - - /// - /// Gets in-progress items - /// - /// The user id. - /// (Optional) Specify a folder Id to localize the search to a specific folder. - public void GetInProgressItemsItemsAsync(Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=inprogressitems&userId=" + userId.ToString(); - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets recently added items - /// - /// The user id. - /// (Optional) Specify a folder Id to localize the search to a specific folder. - public void GetRecentlyAddedItemsAsync(Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=recentlyaddeditems&userId=" + userId.ToString(); - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets favorite items - /// - /// The user id. - /// (Optional) Specify a folder Id to localize the search to a specific folder. - public void GetFavoriteItemsAsync(Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=favorites&userId=" + userId.ToString(); - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets recently added items that are unplayed. - /// - /// The user id. - /// (Optional) Specify a folder Id to localize the search to a specific folder. - public void GetRecentlyAddedUnplayedItemsAsync(Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=recentlyaddedunplayeditems&userId=" + userId.ToString(); - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets all Years - /// - public void GetAllYearsAsync(Guid userId, Action callback) - { - string url = ApiUrl + "/years?userId=" + userId.ToString(); - - GetDataAsync(url, callback); - } - - /// - /// Gets all items that contain a given Year - /// - public void GetItemsWithYearAsync(string name, Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=itemswithyear&userId=" + userId.ToString() + "&name=" + name; - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets all items that contain a given Genre - /// - public void GetItemsWithGenreAsync(string name, Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=itemswithgenre&userId=" + userId.ToString() + "&name=" + name; - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets all items that contain a given Person - /// - public void GetItemsWithPersonAsync(string name, Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=itemswithperson&userId=" + userId.ToString() + "&name=" + name; - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets all items that contain a given Person - /// - public void GetItemsWithPersonAsync(string name, string personType, Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=itemswithperson&userId=" + userId.ToString() + "&name=" + name; - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - url += "&persontype=" + personType; - - GetDataAsync(url, callback); - } - - /// - /// Gets all studious - /// - public void GetAllStudiosAsync(Guid userId, Action callback) - { - string url = ApiUrl + "/studios?userId=" + userId.ToString(); - - GetDataAsync(url, callback); - } - - /// - /// Gets all items that contain a given Studio - /// - public void GetItemsWithStudioAsync(string name, Guid userId, Action callback, Guid? folderId = null) - { - string url = ApiUrl + "/itemlist?listtype=itemswithstudio&userId=" + userId.ToString() + "&name=" + name; - - if (folderId.HasValue) - { - url += "&id=" + folderId.ToString(); - } - - GetDataAsync(url, callback); - } - - /// - /// Gets a studio - /// - public void GetStudioAsync(Guid userId, string name, Action callback) - { - string url = ApiUrl + "/studio?userId=" + userId.ToString() + "&name=" + name; - - GetDataAsync(url, callback); - } - - /// - /// Gets a genre - /// - public void GetGenreAsync(Guid userId, string name, Action callback) - { - string url = ApiUrl + "/genre?userId=" + userId.ToString() + "&name=" + name; - - GetDataAsync(url, callback); - } - - /// - /// Gets a person - /// - public void GetPersonAsync(Guid userId, string name, Action callback) - { - string url = ApiUrl + "/person?userId=" + userId.ToString() + "&name=" + name; - - GetDataAsync(url, callback); - } - - /// - /// Gets a year - /// - public void GetYearAsync(Guid userId, int year, Action callback) - { - string url = ApiUrl + "/year?userId=" + userId.ToString() + "&year=" + year; - - GetDataAsync(url, callback); - } - - /// - /// Gets a list of plugins installed on the server - /// - public void GetInstalledPluginsAsync(Action callback) - { - string url = ApiUrl + "/plugins"; - - GetDataAsync(url, callback); - } - - /// - /// Gets a list of plugins installed on the server - /// - public void GetPluginAssemblyAsync(PluginInfo plugin, Action callback) - { - string url = ApiUrl + "/pluginassembly?assemblyfilename=" + plugin.AssemblyFileName; - - GetStreamAsync(url, callback); - } - - /// - /// Gets the current server configuration - /// - public void GetServerConfigurationAsync(Action callback) - { - string url = ApiUrl + "/ServerConfiguration"; - - GetDataAsync(url, callback); - } - - /// - /// Gets weather information for the default location as set in configuration - /// - public void GetPluginConfigurationAsync(PluginInfo plugin, Type configurationType, Action callback) - { - string url = ApiUrl + "/PluginConfiguration?assemblyfilename=" + plugin.AssemblyFileName; - - // At the moment this can't be retrieved in protobuf format - SerializationFormats format = DataSerializer.CanDeSerializeJsv ? SerializationFormats.Jsv : SerializationFormats.Json; - - GetDataAsync(url, callback, configurationType, format); - } - - /// - /// Gets the default user - /// - public void GetDefaultUserAsync(Action callback) - { - string url = ApiUrl + "/user"; - - GetDataAsync(url, callback); - } - - /// - /// Gets a user by id - /// - public void GetUserAsync(Guid id, Action callback) - { - string url = ApiUrl + "/user?id=" + id.ToString(); - - GetDataAsync(url, callback); - } - - /// - /// Gets weather information for the default location as set in configuration - /// - public void GetWeatherInfoAsync(Action callback) - { - string url = ApiUrl + "/weather"; - - GetDataAsync(url, callback); - } - - /// - /// Gets weather information for a specific zip code - /// - public void GetWeatherInfoAsync(string zipCode, Action callback) - { - string url = ApiUrl + "/weather?zipcode=" + zipCode; - - GetDataAsync(url, callback); - } - - /// - /// Gets special features for a Movie - /// - public void GetMovieSpecialFeaturesAsync(Guid itemId, Guid userId, Action callback) - { - string url = ApiUrl + "/MovieSpecialFeatures?id=" + itemId; - url += "&userid=" + userId; - - GetDataAsync(url, callback); - } - - /// - /// Authenticates a user and returns the result - /// - public void AuthenticateUserAsync(Guid userId, string password, Action callback) - { - string url = ApiUrl + "/UserAuthentication?dataformat=" + SerializationFormat.ToString(); - - Dictionary formValues = new Dictionary(); - - formValues["userid"] = userId.ToString(); - - if (!string.IsNullOrEmpty(password)) - { - formValues["password"] = password; - } - - PostDataAsync(url, formValues, callback, SerializationFormat); - } - - /// - /// Updates a user's favorite status for an item and returns the updated UserItemData object. - /// - public void UpdateFavoriteStatusAsync(Guid itemId, Guid userId, bool isFavorite, Action callback) - { - string url = ApiUrl + "/favoritestatus?id=" + itemId; - - url += "&userid=" + userId; - url += "&isfavorite=" + (isFavorite ? "1" : "0"); - - GetDataAsync(url, callback); - } - - /// - /// Updates played status for an item - /// - public void UpdatePlayedStatusAsync(Guid itemId, Guid userId, bool wasPlayed, Action callback) - { - string url = ApiUrl + "/PlayedStatus?id=" + itemId; - - url += "&userid=" + userId; - url += "&played=" + (wasPlayed ? "1" : "0"); - - GetDataAsync(url, callback); - } - - /// - /// Clears a user's rating for an item - /// - public void ClearUserItemRatingAsync(Guid itemId, Guid userId, Action callback) - { - string url = ApiUrl + "/UserItemRating?id=" + itemId; - - url += "&userid=" + userId; - url += "&clear=1"; - - GetDataAsync(url, callback); - } - - /// - /// Updates a user's rating for an item, based on likes or dislikes - /// - public void UpdateUserItemRatingAsync(Guid itemId, Guid userId, bool likes, Action callback) - { - string url = ApiUrl + "/UserItemRating?id=" + itemId; - - url += "&userid=" + userId; - url += "&likes=" + (likes ? "1" : "0"); - - GetDataAsync(url, callback); - } - - /// - /// Performs a GET request, and deserializes the response stream to an object of Type T - /// - private void GetDataAsync(string url, Action callback) - where T : class - { - GetDataAsync(url, callback, SerializationFormat); - } - - /// - /// Performs a GET request, and deserializes the response stream to an object of Type T - /// - private void GetDataAsync(string url, Action callback, SerializationFormats serializationFormat) - where T : class - { - if (url.IndexOf('?') == -1) - { - url += "?dataformat=" + serializationFormat.ToString(); - } - else - { - url += "&dataformat=" + serializationFormat.ToString(); - } - - HttpWebRequest request = GetNewRequest(url); - - request.BeginGetResponse(new AsyncCallback(result => - { - T value; - - using (WebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result)) - { - using (Stream stream = response.GetResponseStream()) - { - value = DeserializeFromStream(stream); - } - } - - callback(value); - - }), request); - } - - /// - /// Performs a GET request, and deserializes the response stream to an object of Type T - /// - private void GetDataAsync(string url, Action callback, Type type, SerializationFormats serializationFormat) - { - if (url.IndexOf('?') == -1) - { - url += "?dataformat=" + serializationFormat.ToString(); - } - else - { - url += "&dataformat=" + serializationFormat.ToString(); - } - - HttpWebRequest request = GetNewRequest(url); - - request.BeginGetResponse(new AsyncCallback(result => - { - object value; - - using (WebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result)) - { - using (Stream stream = response.GetResponseStream()) - { - value = DataSerializer.DeserializeFromStream(stream, serializationFormat, type); - } - } - - callback(value); - - }), request); - } - - /// - /// Performs a POST request, and deserializes the response stream to an object of Type T - /// - private void PostDataAsync(string url, Dictionary formValues, Action callback, SerializationFormats serializationFormat) - where T : class - { - if (url.IndexOf('?') == -1) - { - url += "?dataformat=" + serializationFormat.ToString(); - } - else - { - url += "&dataformat=" + serializationFormat.ToString(); - } - - HttpWebRequest request = GetNewRequest(url); - - request.Method = "POST"; - request.ContentType = "application/x-www-form-urlencoded"; - - // Begin getting request stream - request.BeginGetRequestStream(new AsyncCallback(beginGetRequestStreamResult => - { - // Once we have the request stream, write the post data - using (Stream requestStream = request.EndGetRequestStream(beginGetRequestStreamResult)) - { - // Construct the body - string postBody = string.Join("&", formValues.Keys.Select(s => string.Format("{0}={1}", s, formValues[s])).ToArray()); - - // Convert the string into a byte array. - byte[] byteArray = Encoding.UTF8.GetBytes(postBody); - - // Write to the request stream. - requestStream.Write(byteArray, 0, byteArray.Length); - } - - // Begin getting response stream - request.BeginGetResponse(new AsyncCallback(result => - { - // Once we have it, deserialize the data and execute the callback - T value; - - using (WebResponse response = request.EndGetResponse(result)) - { - using (Stream responseStream = response.GetResponseStream()) - { - value = DeserializeFromStream(responseStream); - } - } - - callback(value); - - }), null); - - }), null); - } - } -} diff --git a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj b/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj deleted file mode 100644 index b46505e9db..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/MediaBrowser.ApiInteraction.Portable.csproj +++ /dev/null @@ -1,72 +0,0 @@ - - - - - Debug - AnyCPU - {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB} - Library - Properties - MediaBrowser.ApiInteraction.Portable - MediaBrowser.ApiInteraction.Portable - v4.0 - Profile4 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - BaseApiClient.cs - - - DataSerializer.cs - - - SerializationFormats.cs - - - - - - - ..\Json.Net\Portable\Newtonsoft.Json.dll - - - ..\protobuf-net\Full\portable\protobuf-net.dll - - - ..\MediaBrowser.Model\bin\ProtobufModelSerializer.dll - - - - - {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} - MediaBrowser.Model - - - - - \ No newline at end of file diff --git a/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs b/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs deleted file mode 100644 index c7628135dc..0000000000 --- a/MediaBrowser.ApiInteraction.Portable/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.ApiInteraction.Portable")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.ApiInteraction.Portable")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.ApiInteraction.sln b/MediaBrowser.ApiInteraction.sln index b5bcc1cddb..4484801a2b 100644 --- a/MediaBrowser.ApiInteraction.sln +++ b/MediaBrowser.ApiInteraction.sln @@ -12,18 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F0E0E6 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.ApiInteraction.Metro", "MediaBrowser.ApiInteraction.Metro\MediaBrowser.ApiInteraction.Metro.csproj", "{94CEA07A-307C-4663-AA43-7BD852808574}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.ApiInteraction.Portable", "MediaBrowser.ApiInteraction.Portable\MediaBrowser.ApiInteraction.Portable.csproj", "{756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {756B93D2-5FFA-4B8D-BDCA-127476F1E6FB}.Release|Any CPU.Build.0 = Release|Any CPU {7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}.Debug|Any CPU.Build.0 = Debug|Any CPU {7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/MediaBrowser.ApiInteraction/BaseApiClient.cs b/MediaBrowser.ApiInteraction/BaseApiClient.cs index 7952129cf4..18588e9204 100644 --- a/MediaBrowser.ApiInteraction/BaseApiClient.cs +++ b/MediaBrowser.ApiInteraction/BaseApiClient.cs @@ -299,7 +299,7 @@ namespace MediaBrowser.ApiInteraction /// Use if a max width is required. Aspect ratio will be preserved. /// Use if a max height is required. Aspect ratio will be preserved. /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. - public string[] GetBackdropImageUrls(DTOBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + public string[] GetBackdropImageUrls(DtoBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) { Guid? backdropItemId = null; int backdropCount = 0; @@ -339,7 +339,7 @@ namespace MediaBrowser.ApiInteraction /// Use if a max width is required. Aspect ratio will be preserved. /// Use if a max height is required. Aspect ratio will be preserved. /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. - public string GetLogoImageUrl(DTOBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + public string GetLogoImageUrl(DtoBaseItem item, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) { Guid? logoItemId = item.HasLogo ? item.Id : item.ParentLogoItemId; diff --git a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs b/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs index 0b87ef4cd1..6bc052afcb 100644 --- a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs +++ b/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs @@ -50,7 +50,7 @@ namespace MediaBrowser.ApiInteraction /// /// Gets a BaseItem /// - public async Task GetItemAsync(Guid id, Guid userId) + public async Task GetItemAsync(Guid id, Guid userId) { string url = ApiUrl + "/item?userId=" + userId.ToString(); @@ -61,20 +61,20 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } /// /// Gets all Users /// - public async Task GetAllUsersAsync() + public async Task GetAllUsersAsync() { string url = ApiUrl + "/users"; using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -96,7 +96,7 @@ namespace MediaBrowser.ApiInteraction /// /// The user id. /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetInProgressItemsItemsAsync(Guid userId, Guid? folderId = null) + public async Task GetInProgressItemsItemsAsync(Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=inprogressitems&userId=" + userId.ToString(); @@ -107,7 +107,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -116,7 +116,7 @@ namespace MediaBrowser.ApiInteraction /// /// The user id. /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetRecentlyAddedItemsAsync(Guid userId, Guid? folderId = null) + public async Task GetRecentlyAddedItemsAsync(Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=recentlyaddeditems&userId=" + userId.ToString(); @@ -127,7 +127,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -136,7 +136,7 @@ namespace MediaBrowser.ApiInteraction /// /// The user id. /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetFavoriteItemsAsync(Guid userId, Guid? folderId = null) + public async Task GetFavoriteItemsAsync(Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=favorites&userId=" + userId.ToString(); @@ -147,7 +147,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -156,7 +156,7 @@ namespace MediaBrowser.ApiInteraction /// /// The user id. /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetRecentlyAddedUnplayedItemsAsync(Guid userId, Guid? folderId = null) + public async Task GetRecentlyAddedUnplayedItemsAsync(Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=recentlyaddedunplayeditems&userId=" + userId.ToString(); @@ -167,7 +167,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -188,7 +188,7 @@ namespace MediaBrowser.ApiInteraction /// Gets all items that contain a given Year /// /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetItemsWithYearAsync(string name, Guid userId, Guid? folderId = null) + public async Task GetItemsWithYearAsync(string name, Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=itemswithyear&userId=" + userId.ToString() + "&name=" + name; @@ -199,7 +199,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -207,7 +207,7 @@ namespace MediaBrowser.ApiInteraction /// Gets all items that contain a given Genre /// /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetItemsWithGenreAsync(string name, Guid userId, Guid? folderId = null) + public async Task GetItemsWithGenreAsync(string name, Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=itemswithgenre&userId=" + userId.ToString() + "&name=" + name; @@ -218,7 +218,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -226,7 +226,7 @@ namespace MediaBrowser.ApiInteraction /// Gets all items that contain a given Person /// /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetItemsWithPersonAsync(string name, Guid userId, Guid? folderId = null) + public async Task GetItemsWithPersonAsync(string name, Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=itemswithperson&userId=" + userId.ToString() + "&name=" + name; @@ -237,7 +237,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -245,7 +245,7 @@ namespace MediaBrowser.ApiInteraction /// Gets all items that contain a given Person /// /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetItemsWithPersonAsync(string name, string personType, Guid userId, Guid? folderId = null) + public async Task GetItemsWithPersonAsync(string name, string personType, Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=itemswithperson&userId=" + userId.ToString() + "&name=" + name; @@ -258,7 +258,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -279,7 +279,7 @@ namespace MediaBrowser.ApiInteraction /// Gets all items that contain a given Studio /// /// (Optional) Specify a folder Id to localize the search to a specific folder. - public async Task GetItemsWithStudioAsync(string name, Guid userId, Guid? folderId = null) + public async Task GetItemsWithStudioAsync(string name, Guid userId, Guid? folderId = null) { string url = ApiUrl + "/itemlist?listtype=itemswithstudio&userId=" + userId.ToString() + "&name=" + name; @@ -290,7 +290,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -401,26 +401,26 @@ namespace MediaBrowser.ApiInteraction /// /// Gets the default user /// - public async Task GetDefaultUserAsync() + public async Task GetDefaultUserAsync() { string url = ApiUrl + "/user"; using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } /// /// Gets a user by id /// - public async Task GetUserAsync(Guid id) + public async Task GetUserAsync(Guid id) { string url = ApiUrl + "/user?id=" + id.ToString(); using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } @@ -453,21 +453,21 @@ namespace MediaBrowser.ApiInteraction /// /// Gets special features for a Movie /// - public async Task GetMovieSpecialFeaturesAsync(Guid itemId, Guid userId) + public async Task GetMovieSpecialFeaturesAsync(Guid itemId, Guid userId) { string url = ApiUrl + "/MovieSpecialFeatures?id=" + itemId; url += "&userid=" + userId; using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } /// /// Updates played status for an item /// - public async Task UpdatePlayedStatusAsync(Guid itemId, Guid userId, bool wasPlayed) + public async Task UpdatePlayedStatusAsync(Guid itemId, Guid userId, bool wasPlayed) { string url = ApiUrl + "/PlayedStatus?id=" + itemId; @@ -476,14 +476,14 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } /// /// Updates a user's favorite status for an item and returns the updated UserItemData object. /// - public async Task UpdateFavoriteStatusAsync(Guid itemId, Guid userId, bool isFavorite) + public async Task UpdateFavoriteStatusAsync(Guid itemId, Guid userId, bool isFavorite) { string url = ApiUrl + "/favoritestatus?id=" + itemId; @@ -492,14 +492,14 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } /// /// Clears a user's rating for an item /// - public async Task ClearUserItemRatingAsync(Guid itemId, Guid userId) + public async Task ClearUserItemRatingAsync(Guid itemId, Guid userId) { string url = ApiUrl + "/UserItemRating?id=" + itemId; @@ -508,14 +508,14 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } /// /// Updates a user's rating for an item, based on likes or dislikes /// - public async Task UpdateUserItemRatingAsync(Guid itemId, Guid userId, bool likes) + public async Task UpdateUserItemRatingAsync(Guid itemId, Guid userId, bool likes) { string url = ApiUrl + "/UserItemRating?id=" + itemId; @@ -524,7 +524,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false)) { - return DeserializeFromStream(stream); + return DeserializeFromStream(stream); } } diff --git a/MediaBrowser.ApiInteraction/DataSerializer.cs b/MediaBrowser.ApiInteraction/DataSerializer.cs index ae3a72e622..2783f4ea12 100644 --- a/MediaBrowser.ApiInteraction/DataSerializer.cs +++ b/MediaBrowser.ApiInteraction/DataSerializer.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.ApiInteraction /// This means that this class can currently only handle types within the Model project. /// If we need to, we can always add a param indicating whether or not the model serializer should be used. /// - private static ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); + private static readonly ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); /// /// Deserializes an object using generics @@ -20,16 +20,16 @@ namespace MediaBrowser.ApiInteraction public static T DeserializeFromStream(Stream stream, SerializationFormats format) where T : class { - if (format == ApiInteraction.SerializationFormats.Protobuf) + if (format == SerializationFormats.Protobuf) { //return Serializer.Deserialize(stream); return ProtobufModelSerializer.Deserialize(stream, null, typeof(T)) as T; } - else if (format == ApiInteraction.SerializationFormats.Jsv) + else if (format == SerializationFormats.Jsv) { return TypeSerializer.DeserializeFromStream(stream); } - else if (format == ApiInteraction.SerializationFormats.Json) + else if (format == SerializationFormats.Json) { return JsonSerializer.DeserializeFromStream(stream); } diff --git a/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs b/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs index 5dd263f0a0..74742759f3 100644 --- a/MediaBrowser.ApiInteraction/Properties/AssemblyInfo.cs +++ b/MediaBrowser.ApiInteraction/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/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 3c8fff2128..7f484acaa6 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Common.Kernel /// public abstract KernelContext KernelContext { get; } - public BaseKernel() + protected BaseKernel() { ApplicationPaths = new TApplicationPathsType(); } @@ -76,13 +76,13 @@ namespace MediaBrowser.Common.Kernel { ReloadLogger(); - progress.Report(new TaskProgress() { Description = "Loading configuration", PercentComplete = 0 }); + progress.Report(new TaskProgress { Description = "Loading configuration", PercentComplete = 0 }); ReloadConfiguration(); - progress.Report(new TaskProgress() { Description = "Starting Http server", PercentComplete = 5 }); + progress.Report(new TaskProgress { Description = "Starting Http server", PercentComplete = 5 }); ReloadHttpServer(); - progress.Report(new TaskProgress() { Description = "Loading Plugins", PercentComplete = 10 }); + progress.Report(new TaskProgress { Description = "Loading Plugins", PercentComplete = 10 }); await ReloadComposableParts().ConfigureAwait(false); } @@ -192,7 +192,7 @@ namespace MediaBrowser.Common.Kernel HttpServer = new HttpServer(HttpServerUrlPrefix); - HttpListener = HttpServer.Subscribe((ctx) => + HttpListener = HttpServer.Subscribe(ctx => { BaseHandler handler = HttpHandlers.FirstOrDefault(h => h.HandlesRequest(ctx.Request)); diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs index 16eb96e208..bcf10d7dc0 100644 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Common.Logging Thread currentThread = Thread.CurrentThread; - LogRow row = new LogRow() + LogRow row = new LogRow { Severity = severity, Message = message, diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs index 052f6062aa..6fecef59cc 100644 --- a/MediaBrowser.Common/Logging/LogRow.cs +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -1,7 +1,5 @@ using System; -using System.Text; using System.Collections.Generic; -using System.Linq; namespace MediaBrowser.Common.Logging { @@ -17,7 +15,7 @@ namespace MediaBrowser.Common.Logging public override string ToString() { - List data = new List(); + var data = new List(); data.Add(Time.ToString(TimePattern)); diff --git a/MediaBrowser.Common/Logging/StreamLogger.cs b/MediaBrowser.Common/Logging/StreamLogger.cs index caeb803bd1..03b9bd6d26 100644 --- a/MediaBrowser.Common/Logging/StreamLogger.cs +++ b/MediaBrowser.Common/Logging/StreamLogger.cs @@ -7,7 +7,7 @@ namespace MediaBrowser.Common.Logging /// /// Provides a Logger that can write to any Stream /// - public class StreamLogger : ThreadedLogger + public class StreamLogger : BaseLogger { private Stream Stream { get; set; } @@ -17,11 +17,15 @@ namespace MediaBrowser.Common.Logging Stream = stream; } - protected override void AsyncLogMessage(LogRow row) + protected override void LogEntry(LogRow row) { byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine); - Stream.Write(bytes, 0, bytes.Length); - Stream.Flush(); + + lock (Stream) + { + Stream.Write(bytes, 0, bytes.Length); + Stream.Flush(); + } } public override void Dispose() diff --git a/MediaBrowser.Common/Logging/ThreadedLogger.cs b/MediaBrowser.Common/Logging/ThreadedLogger.cs deleted file mode 100644 index f53b3d4260..0000000000 --- a/MediaBrowser.Common/Logging/ThreadedLogger.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; - -namespace MediaBrowser.Common.Logging -{ - public abstract class ThreadedLogger : BaseLogger - { - Thread loggingThread; - Queue queue = new Queue(); - AutoResetEvent hasNewItems = new AutoResetEvent(false); - volatile bool terminate = false; - bool waiting = false; - - public ThreadedLogger() - : base() - { - loggingThread = new Thread(new ThreadStart(ProcessQueue)); - loggingThread.IsBackground = true; - loggingThread.Start(); - } - - - void ProcessQueue() - { - while (!terminate) - { - waiting = true; - hasNewItems.WaitOne(10000, true); - waiting = false; - - Queue queueCopy; - lock (queue) - { - queueCopy = new Queue(queue); - queue.Clear(); - } - - foreach (var log in queueCopy) - { - log(); - } - } - } - - protected override void LogEntry(LogRow row) - { - lock (queue) - { - queue.Enqueue(() => AsyncLogMessage(row)); - } - hasNewItems.Set(); - } - - protected abstract void AsyncLogMessage(LogRow row); - - protected override void Flush() - { - while (!waiting) - { - Thread.Sleep(1); - } - } - - public override void Dispose() - { - Flush(); - terminate = true; - hasNewItems.Set(); - base.Dispose(); - } - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 9b801d9498..6eb5804ab1 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -83,7 +83,6 @@ - diff --git a/MediaBrowser.Common/Net/Handlers/BaseEmbeddedResourceHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseEmbeddedResourceHandler.cs index 9d9e2a0e03..3ce85a688d 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseEmbeddedResourceHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseEmbeddedResourceHandler.cs @@ -5,7 +5,7 @@ namespace MediaBrowser.Common.Net.Handlers { public abstract class BaseEmbeddedResourceHandler : BaseHandler { - public BaseEmbeddedResourceHandler(string resourcePath) + protected BaseEmbeddedResourceHandler(string resourcePath) : base() { ResourcePath = resourcePath; @@ -15,7 +15,7 @@ namespace MediaBrowser.Common.Net.Handlers public override Task GetContentType() { - return Task.FromResult(MimeTypes.GetMimeType(ResourcePath)); + return Task.FromResult(MimeTypes.GetMimeType(ResourcePath)); } protected override Task WriteResponseToOutputStream(Stream stream) diff --git a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs index ecc58b3165..7c18152655 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs @@ -25,8 +25,8 @@ namespace MediaBrowser.Common.Net.Handlers } } - private bool _TotalContentLengthDiscovered = false; - private long? _TotalContentLength = null; + private bool _TotalContentLengthDiscovered; + private long? _TotalContentLength; public long? TotalContentLength { get @@ -34,6 +34,7 @@ namespace MediaBrowser.Common.Net.Handlers if (!_TotalContentLengthDiscovered) { _TotalContentLength = GetTotalContentLength(); + _TotalContentLengthDiscovered = true; } return _TotalContentLength; @@ -64,7 +65,7 @@ namespace MediaBrowser.Common.Net.Handlers } } - protected List> _RequestedRanges = null; + private List> _RequestedRanges; protected IEnumerable> RequestedRanges { get @@ -367,7 +368,7 @@ namespace MediaBrowser.Common.Net.Handlers { DateTime? value = null; - return Task.FromResult(value); + return Task.FromResult(value); } private bool IsResponseValid @@ -378,7 +379,7 @@ namespace MediaBrowser.Common.Net.Handlers } } - private Hashtable _FormValues = null; + private Hashtable _FormValues; /// /// Gets a value from form POST data diff --git a/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs index dd3020e035..1983c408de 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseSerializationHandler.cs @@ -15,7 +15,7 @@ namespace MediaBrowser.Common.Net.Handlers if (string.IsNullOrEmpty(format)) { - return Handlers.SerializationFormat.Json; + return SerializationFormat.Json; } return (SerializationFormat)Enum.Parse(typeof(SerializationFormat), format, true); @@ -26,16 +26,16 @@ namespace MediaBrowser.Common.Net.Handlers { switch (SerializationFormat) { - case Handlers.SerializationFormat.Jsv: - return Task.FromResult("text/plain"); - case Handlers.SerializationFormat.Protobuf: - return Task.FromResult("application/x-protobuf"); + case SerializationFormat.Jsv: + return Task.FromResult("text/plain"); + case SerializationFormat.Protobuf: + return Task.FromResult("application/x-protobuf"); default: - return Task.FromResult(MimeTypes.JsonMimeType); + return Task.FromResult(MimeTypes.JsonMimeType); } } - private bool _ObjectToSerializeEnsured = false; + private bool _ObjectToSerializeEnsured; private T _ObjectToSerialize; private async Task EnsureObjectToSerialize() @@ -66,14 +66,14 @@ namespace MediaBrowser.Common.Net.Handlers switch (SerializationFormat) { - case Handlers.SerializationFormat.Jsv: - JsvSerializer.SerializeToStream(_ObjectToSerialize, stream); + case SerializationFormat.Jsv: + JsvSerializer.SerializeToStream(_ObjectToSerialize, stream); break; - case Handlers.SerializationFormat.Protobuf: - ProtobufSerializer.SerializeToStream(_ObjectToSerialize, stream); + case SerializationFormat.Protobuf: + ProtobufSerializer.SerializeToStream(_ObjectToSerialize, stream); break; default: - JsonSerializer.SerializeToStream(_ObjectToSerialize, stream); + JsonSerializer.SerializeToStream(_ObjectToSerialize, stream); break; } } diff --git a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs index bc367403b8..f5c4413102 100644 --- a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs @@ -33,8 +33,8 @@ namespace MediaBrowser.Common.Net.Handlers } } - private bool _SourceStreamEnsured = false; - private Stream _SourceStream = null; + private bool _SourceStreamEnsured; + private Stream _SourceStream; private Stream SourceStream { get @@ -116,12 +116,12 @@ namespace MediaBrowser.Common.Net.Handlers value = File.GetLastWriteTimeUtc(Path); } - return Task.FromResult(value); + return Task.FromResult(value); } public override Task GetContentType() { - return Task.FromResult(MimeTypes.GetMimeType(Path)); + return Task.FromResult(MimeTypes.GetMimeType(Path)); } protected override Task PrepareResponse() @@ -141,21 +141,17 @@ namespace MediaBrowser.Common.Net.Handlers { return ServeCompleteRangeRequest(requestedRange, stream); } - else if (TotalContentLength.HasValue) + if (TotalContentLength.HasValue) { // This will have to buffer a portion of the content into memory return ServePartialRangeRequestWithKnownTotalContentLength(requestedRange, stream); } - else - { - // This will have to buffer the entire content into memory - return ServePartialRangeRequestWithUnknownTotalContentLength(requestedRange, stream); - } - } - else - { - return SourceStream.CopyToAsync(stream); + + // This will have to buffer the entire content into memory + return ServePartialRangeRequestWithUnknownTotalContentLength(requestedRange, stream); } + + return SourceStream.CopyToAsync(stream); } protected override void DisposeResponseStream() diff --git a/MediaBrowser.Common/Net/HttpServer.cs b/MediaBrowser.Common/Net/HttpServer.cs index 69ded6f816..1b3a272f11 100644 --- a/MediaBrowser.Common/Net/HttpServer.cs +++ b/MediaBrowser.Common/Net/HttpServer.cs @@ -20,7 +20,7 @@ namespace MediaBrowser.Common.Net private IObservable ObservableHttpContext() { return Observable.Create(obs => - Observable.FromAsync(() => listener.GetContextAsync()) + Observable.FromAsync(() => listener.GetContextAsync()) .Subscribe(obs)) .Repeat() .Retry() diff --git a/MediaBrowser.Common/Net/MimeTypes.cs b/MediaBrowser.Common/Net/MimeTypes.cs index 3ec13ce83f..fb85b0f2a3 100644 --- a/MediaBrowser.Common/Net/MimeTypes.cs +++ b/MediaBrowser.Common/Net/MimeTypes.cs @@ -9,7 +9,7 @@ namespace MediaBrowser.Common.Net public static string GetMimeType(string path) { - string ext = Path.GetExtension(path); + var ext = Path.GetExtension(path); // http://en.wikipedia.org/wiki/Internet_media_type // Add more as needed @@ -19,137 +19,137 @@ namespace MediaBrowser.Common.Net { return "video/mpeg"; } - else if (ext.EndsWith("mp4", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("mp4", StringComparison.OrdinalIgnoreCase)) { return "video/mp4"; } - else if (ext.EndsWith("ogv", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("ogv", StringComparison.OrdinalIgnoreCase)) { return "video/ogg"; } - else if (ext.EndsWith("mov", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("mov", StringComparison.OrdinalIgnoreCase)) { return "video/quicktime"; } - else if (ext.EndsWith("webm", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("webm", StringComparison.OrdinalIgnoreCase)) { return "video/webm"; } - else if (ext.EndsWith("mkv", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("mkv", StringComparison.OrdinalIgnoreCase)) { return "video/x-matroska"; } - else if (ext.EndsWith("wmv", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("wmv", StringComparison.OrdinalIgnoreCase)) { return "video/x-ms-wmv"; } - else if (ext.EndsWith("flv", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("flv", StringComparison.OrdinalIgnoreCase)) { return "video/x-flv"; } - else if (ext.EndsWith("avi", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("avi", StringComparison.OrdinalIgnoreCase)) { return "video/avi"; } - else if (ext.EndsWith("m4v", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("m4v", StringComparison.OrdinalIgnoreCase)) { return "video/x-m4v"; } - else if (ext.EndsWith("asf", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("asf", StringComparison.OrdinalIgnoreCase)) { return "video/x-ms-asf"; } - else if (ext.EndsWith("3gp", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("3gp", StringComparison.OrdinalIgnoreCase)) { return "video/3gpp"; } - else if (ext.EndsWith("3g2", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("3g2", StringComparison.OrdinalIgnoreCase)) { return "video/3gpp2"; } - else if (ext.EndsWith("ts", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("ts", StringComparison.OrdinalIgnoreCase)) { return "video/mp2t"; } // Type text - else if (ext.EndsWith("css", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("css", StringComparison.OrdinalIgnoreCase)) { return "text/css"; } - else if (ext.EndsWith("csv", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("csv", StringComparison.OrdinalIgnoreCase)) { return "text/csv"; } - else if (ext.EndsWith("html", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("html", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("html", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("html", StringComparison.OrdinalIgnoreCase)) { return "text/html"; } - else if (ext.EndsWith("txt", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("txt", StringComparison.OrdinalIgnoreCase)) { return "text/plain"; } // Type image - else if (ext.EndsWith("gif", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("gif", StringComparison.OrdinalIgnoreCase)) { return "image/gif"; } - else if (ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("jpeg", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("jpeg", StringComparison.OrdinalIgnoreCase)) { return "image/jpeg"; } - else if (ext.EndsWith("png", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("png", StringComparison.OrdinalIgnoreCase)) { return "image/png"; } - else if (ext.EndsWith("ico", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("ico", StringComparison.OrdinalIgnoreCase)) { return "image/vnd.microsoft.icon"; } // Type audio - else if (ext.EndsWith("mp3", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("mp3", StringComparison.OrdinalIgnoreCase)) { return "audio/mpeg"; } - else if (ext.EndsWith("m4a", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("aac", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("m4a", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("aac", StringComparison.OrdinalIgnoreCase)) { return "audio/mp4"; } - else if (ext.EndsWith("webma", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("webma", StringComparison.OrdinalIgnoreCase)) { return "audio/webm"; } - else if (ext.EndsWith("wav", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("wav", StringComparison.OrdinalIgnoreCase)) { return "audio/wav"; } - else if (ext.EndsWith("wma", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("wma", StringComparison.OrdinalIgnoreCase)) { return "audio/x-ms-wma"; } - else if (ext.EndsWith("flac", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("flac", StringComparison.OrdinalIgnoreCase)) { return "audio/flac"; } - else if (ext.EndsWith("aac", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("aac", StringComparison.OrdinalIgnoreCase)) { return "audio/x-aac"; } - else if (ext.EndsWith("ogg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("oga", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("ogg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("oga", StringComparison.OrdinalIgnoreCase)) { return "audio/ogg"; } // Playlists - else if (ext.EndsWith("m3u8", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("m3u8", StringComparison.OrdinalIgnoreCase)) { return "application/x-mpegURL"; } // Misc - else if (ext.EndsWith("dll", StringComparison.OrdinalIgnoreCase)) + if (ext.EndsWith("dll", StringComparison.OrdinalIgnoreCase)) { return "application/x-msdownload"; } diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 705e15f173..1ed32109fb 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -74,7 +74,7 @@ namespace MediaBrowser.Common.Plugins } } - private DateTime? _ConfigurationDateLastModified = null; + private DateTime? _ConfigurationDateLastModified; public DateTime ConfigurationDateLastModified { get @@ -123,7 +123,7 @@ namespace MediaBrowser.Common.Plugins } } - private string _DataFolderPath = null; + private string _DataFolderPath; /// /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed /// diff --git a/MediaBrowser.Common/Properties/AssemblyInfo.cs b/MediaBrowser.Common/Properties/AssemblyInfo.cs index 53e9df0f6e..ff70e8db7f 100644 --- a/MediaBrowser.Common/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Common/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/Serialization/JsonSerializer.cs b/MediaBrowser.Common/Serialization/JsonSerializer.cs index bfca014a90..c44ceac1e5 100644 --- a/MediaBrowser.Common/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common/Serialization/JsonSerializer.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.Common.Serialization { Configure(); - ServiceStack.Text.JsonSerializer.SerializeToStream(obj, stream); + ServiceStack.Text.JsonSerializer.SerializeToStream(obj, stream); } public static void SerializeToFile(T obj, string file) @@ -21,7 +21,7 @@ namespace MediaBrowser.Common.Serialization using (Stream stream = File.Open(file, FileMode.Create)) { - ServiceStack.Text.JsonSerializer.SerializeToStream(obj, stream); + ServiceStack.Text.JsonSerializer.SerializeToStream(obj, stream); } } @@ -59,7 +59,7 @@ namespace MediaBrowser.Common.Serialization return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream); } - private static bool IsConfigured = false; + private static bool IsConfigured; private static void Configure() { if (!IsConfigured) diff --git a/MediaBrowser.Common/Serialization/JsvSerializer.cs b/MediaBrowser.Common/Serialization/JsvSerializer.cs index d482348af4..41e5ea800a 100644 --- a/MediaBrowser.Common/Serialization/JsvSerializer.cs +++ b/MediaBrowser.Common/Serialization/JsvSerializer.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.Common.Serialization { public static void SerializeToStream(T obj, Stream stream) { - ServiceStack.Text.TypeSerializer.SerializeToStream(obj, stream); + ServiceStack.Text.TypeSerializer.SerializeToStream(obj, stream); } public static T DeserializeFromStream(Stream stream) @@ -29,7 +29,7 @@ namespace MediaBrowser.Common.Serialization { using (Stream stream = File.Open(file, FileMode.Create)) { - SerializeToStream(obj, stream); + SerializeToStream(obj, stream); } } diff --git a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs index 7c8a5f96e7..1c79a272d5 100644 --- a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs +++ b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs @@ -15,7 +15,7 @@ namespace MediaBrowser.Common.Serialization /// This means that this class can currently only handle types within the Model project. /// If we need to, we can always add a param indicating whether or not the model serializer should be used. /// - private static ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); + private static readonly ProtobufModelSerializer ProtobufModelSerializer = new ProtobufModelSerializer(); public static void SerializeToStream(T obj, Stream stream) { @@ -37,7 +37,7 @@ namespace MediaBrowser.Common.Serialization { using (Stream stream = File.Open(file, FileMode.Create)) { - SerializeToStream(obj, stream); + SerializeToStream(obj, stream); } } diff --git a/MediaBrowser.Common/Serialization/XmlSerializer.cs b/MediaBrowser.Common/Serialization/XmlSerializer.cs index b881591dd8..69853f97a6 100644 --- a/MediaBrowser.Common/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common/Serialization/XmlSerializer.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Common.Serialization { using (FileStream stream = new FileStream(file, FileMode.Create)) { - SerializeToStream(obj, stream); + SerializeToStream(obj, stream); } } diff --git a/MediaBrowser.Common/UI/BaseApplication.cs b/MediaBrowser.Common/UI/BaseApplication.cs index 4cbc57c0d3..d763f202f9 100644 --- a/MediaBrowser.Common/UI/BaseApplication.cs +++ b/MediaBrowser.Common/UI/BaseApplication.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Common.UI protected override void OnStartup(StartupEventArgs e) { // Without this the app will shutdown after the splash screen closes - this.ShutdownMode = ShutdownMode.OnExplicitShutdown; + ShutdownMode = ShutdownMode.OnExplicitShutdown; LoadKernel(); } @@ -42,7 +42,7 @@ namespace MediaBrowser.Common.UI Logger.LogInfo("Kernel.Init completed in {0} seconds.", (DateTime.UtcNow - now).TotalSeconds); splash.Close(); - this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose; + ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose; InstantiateMainWindow().ShowDialog(); } catch (Exception ex) diff --git a/MediaBrowser.Common/UI/SingleInstance.cs b/MediaBrowser.Common/UI/SingleInstance.cs index 837d3bb578..2b2b6fb459 100644 --- a/MediaBrowser.Common/UI/SingleInstance.cs +++ b/MediaBrowser.Common/UI/SingleInstance.cs @@ -13,18 +13,17 @@ namespace Microsoft.Shell using System; using System.Collections; using System.Collections.Generic; + using System.ComponentModel; using System.IO; + using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Ipc; using System.Runtime.Serialization.Formatters; + using System.Security; using System.Threading; using System.Windows; using System.Windows.Threading; - using System.Xml.Serialization; - using System.Security; - using System.Runtime.InteropServices; - using System.ComponentModel; internal enum WM { @@ -184,7 +183,7 @@ namespace Microsoft.Shell finally { - IntPtr p = _LocalFree(argv); + _LocalFree(argv); // Otherwise LocalFree failed. // Assert.AreEqual(IntPtr.Zero, p); } diff --git a/MediaBrowser.Common/UI/Splash.xaml.cs b/MediaBrowser.Common/UI/Splash.xaml.cs index f66f9ec8fc..0956702295 100644 --- a/MediaBrowser.Common/UI/Splash.xaml.cs +++ b/MediaBrowser.Common/UI/Splash.xaml.cs @@ -27,8 +27,8 @@ namespace MediaBrowser.Common.UI Logger.LogInfo(e.Description); } - this.lblProgress.Content = e.Description; - this.pbProgress.Value = (double)e.PercentComplete; + lblProgress.Content = e.Description; + pbProgress.Value = (double)e.PercentComplete; } private void Splash_Loaded(object sender, RoutedEventArgs e) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index c0f1604b1f..8d7fc40218 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Entities /// public ItemSpecialCounts GetSpecialCounts(User user) { - ItemSpecialCounts counts = new ItemSpecialCounts(); + var counts = new ItemSpecialCounts(); IEnumerable recursiveChildren = GetParentalAllowedRecursiveChildren(user); diff --git a/MediaBrowser.Controller/Entities/UserItemData.cs b/MediaBrowser.Controller/Entities/UserItemData.cs index 3eacdae5bc..271ecf5478 100644 --- a/MediaBrowser.Controller/Entities/UserItemData.cs +++ b/MediaBrowser.Controller/Entities/UserItemData.cs @@ -5,7 +5,7 @@ namespace MediaBrowser.Controller.Entities { public class UserItemData { - private float? _Rating = null; + private float? _Rating; /// /// Gets or sets the users 0-10 rating /// diff --git a/MediaBrowser.Controller/FFMpeg/FFProbe.cs b/MediaBrowser.Controller/FFMpeg/FFProbe.cs index d4c07f07b0..db113bb8a3 100644 --- a/MediaBrowser.Controller/FFMpeg/FFProbe.cs +++ b/MediaBrowser.Controller/FFMpeg/FFProbe.cs @@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.FFMpeg { try { - ProtobufSerializer.SerializeToFile(result, outputCachePath); + ProtobufSerializer.SerializeToFile(result, outputCachePath); } catch (Exception ex) { diff --git a/MediaBrowser.Controller/IO/DirectoryWatchers.cs b/MediaBrowser.Controller/IO/DirectoryWatchers.cs index 837c02cb90..f8037984eb 100644 --- a/MediaBrowser.Controller/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Controller/IO/DirectoryWatchers.cs @@ -10,8 +10,8 @@ namespace MediaBrowser.Controller.IO { public class DirectoryWatchers { - private List FileSystemWatchers = new List(); - private Timer updateTimer = null; + private readonly List FileSystemWatchers = new List(); + private Timer updateTimer; private List affectedPaths = new List(); 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) diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index b7a6579daf..4ae2ee72f3 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -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(); /// /// Takes a filename and removes invalid characters diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 47a3773b34..0de57593b9 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -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() diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index 9e0c94b793..4115ea7b8b 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Controller.Library /// public async Task 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(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; } /// @@ -231,7 +229,7 @@ namespace MediaBrowser.Controller.Library return GetImagesByNameItem(Kernel.Instance.ApplicationPaths.YearPath, value.ToString()); } - private ConcurrentDictionary ImagesByNameItemCache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary ImagesByNameItemCache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); /// /// Generically retrieves an IBN item diff --git a/MediaBrowser.Controller/Properties/AssemblyInfo.cs b/MediaBrowser.Controller/Properties/AssemblyInfo.cs index 350165b1c6..63cc65d7aa 100644 --- a/MediaBrowser.Controller/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Controller/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.Controller/Providers/AudioInfoProvider.cs b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs index 09cd80a210..f7242ce053 100644 --- a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs +++ b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs @@ -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"); diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index a3b0d2c600..837e4c3884 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -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); } diff --git a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs index 6ccb6df7c1..f556d671e3 100644 --- a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs @@ -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(null); diff --git a/MediaBrowser.Controller/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Controller/Resolvers/Movies/MovieResolver.cs index ae30a63872..a25968a943 100644 --- a/MediaBrowser.Controller/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Controller/Resolvers/Movies/MovieResolver.cs @@ -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) diff --git a/MediaBrowser.Controller/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Controller/Resolvers/TV/SeriesResolver.cs index 3c43e460c5..b8ff2c37be 100644 --- a/MediaBrowser.Controller/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Controller/Resolvers/TV/SeriesResolver.cs @@ -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) { diff --git a/MediaBrowser.Controller/Resolvers/TV/TVUtils.cs b/MediaBrowser.Controller/Resolvers/TV/TVUtils.cs index ebfcda6028..c40f3fa63f 100644 --- a/MediaBrowser.Controller/Resolvers/TV/TVUtils.cs +++ b/MediaBrowser.Controller/Resolvers/TV/TVUtils.cs @@ -9,7 +9,7 @@ namespace MediaBrowser.Controller.Resolvers.TV /// /// A season folder must contain one of these somewhere in the name /// - 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 diff --git a/MediaBrowser.Controller/Resolvers/VideoResolver.cs b/MediaBrowser.Controller/Resolvers/VideoResolver.cs index 316c7798a1..e162fa509d 100644 --- a/MediaBrowser.Controller/Resolvers/VideoResolver.cs +++ b/MediaBrowser.Controller/Resolvers/VideoResolver.cs @@ -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) diff --git a/MediaBrowser.Controller/ServerApplicationPaths.cs b/MediaBrowser.Controller/ServerApplicationPaths.cs index 0f4932fd04..f657ee259d 100644 --- a/MediaBrowser.Controller/ServerApplicationPaths.cs +++ b/MediaBrowser.Controller/ServerApplicationPaths.cs @@ -153,7 +153,7 @@ namespace MediaBrowser.Controller } } - private string _CacheDirectory = null; + private string _CacheDirectory; /// /// Gets the folder path to the cache directory /// @@ -175,7 +175,7 @@ namespace MediaBrowser.Controller } } - private string _FFProbeAudioCacheDirectory = null; + private string _FFProbeAudioCacheDirectory; /// /// Gets the folder path to the ffprobe audio cache directory /// @@ -197,7 +197,7 @@ namespace MediaBrowser.Controller } } - private string _FFProbeVideoCacheDirectory = null; + private string _FFProbeVideoCacheDirectory; /// /// Gets the folder path to the ffprobe video cache directory /// @@ -219,7 +219,7 @@ namespace MediaBrowser.Controller } } - private string _FFMpegDirectory = null; + private string _FFMpegDirectory; /// /// Gets the folder path to ffmpeg /// @@ -241,7 +241,7 @@ namespace MediaBrowser.Controller } } - private string _FFMpegPath = null; + private string _FFMpegPath; /// /// Gets the path to ffmpeg.exe /// @@ -258,7 +258,7 @@ namespace MediaBrowser.Controller } } - private string _FFProbePath = null; + private string _FFProbePath; /// /// Gets the path to ffprobe.exe /// diff --git a/MediaBrowser.Controller/Weather/WeatherClient.cs b/MediaBrowser.Controller/Weather/WeatherClient.cs index c4abdc171e..a16244820c 100644 --- a/MediaBrowser.Controller/Weather/WeatherClient.cs +++ b/MediaBrowser.Controller/Weather/WeatherClient.cs @@ -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), diff --git a/MediaBrowser.Controller/Xml/XmlExtensions.cs b/MediaBrowser.Controller/Xml/XmlExtensions.cs index e706baa614..d2e8e19832 100644 --- a/MediaBrowser.Controller/Xml/XmlExtensions.cs +++ b/MediaBrowser.Controller/Xml/XmlExtensions.cs @@ -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"); /// /// Reads a float from the current element of an XmlReader diff --git a/MediaBrowser.Model/DTO/DTOBaseItem.cs b/MediaBrowser.Model/DTO/DTOBaseItem.cs index 8d2cadd872..66049d3fd3 100644 --- a/MediaBrowser.Model/DTO/DTOBaseItem.cs +++ b/MediaBrowser.Model/DTO/DTOBaseItem.cs @@ -10,7 +10,7 @@ namespace MediaBrowser.Model.DTO /// This holds information about a BaseItem in a format that is convenient for the client. /// [ProtoContract] - public class DTOBaseItem : IHasProviderIds + public class DtoBaseItem : IHasProviderIds { [ProtoMember(1)] public string Name { get; set; } @@ -91,7 +91,7 @@ namespace MediaBrowser.Model.DTO public int BackdropCount { get; set; } [ProtoMember(27)] - public DTOBaseItem[] Children { get; set; } + public DtoBaseItem[] Children { get; set; } [ProtoMember(28)] public bool IsFolder { get; set; } @@ -136,7 +136,7 @@ namespace MediaBrowser.Model.DTO public int? ParentBackdropCount { get; set; } [ProtoMember(38)] - public DTOBaseItem[] LocalTrailers { get; set; } + public DtoBaseItem[] LocalTrailers { get; set; } [ProtoMember(39)] public int LocalTrailerCount { get; set; } @@ -145,7 +145,7 @@ namespace MediaBrowser.Model.DTO /// User data for this item based on the user it's being requested for /// [ProtoMember(40)] - public DTOUserItemData UserData { get; set; } + public DtoUserItemData UserData { get; set; } [ProtoMember(41)] public ItemSpecialCounts SpecialCounts { get; set; } diff --git a/MediaBrowser.Model/DTO/DTOUser.cs b/MediaBrowser.Model/DTO/DTOUser.cs index be13825f0b..766cd741ee 100644 --- a/MediaBrowser.Model/DTO/DTOUser.cs +++ b/MediaBrowser.Model/DTO/DTOUser.cs @@ -1,11 +1,10 @@ -using MediaBrowser.Model.Entities; -using ProtoBuf; +using ProtoBuf; using System; namespace MediaBrowser.Model.DTO { [ProtoContract] - public class DTOUser + public class DtoUser { [ProtoMember(1)] public string Name { get; set; } diff --git a/MediaBrowser.Model/DTO/DTOUserItemData.cs b/MediaBrowser.Model/DTO/DTOUserItemData.cs index 33ff797afd..ce258f16f6 100644 --- a/MediaBrowser.Model/DTO/DTOUserItemData.cs +++ b/MediaBrowser.Model/DTO/DTOUserItemData.cs @@ -3,7 +3,7 @@ namespace MediaBrowser.Model.DTO { [ProtoContract] - public class DTOUserItemData + public class DtoUserItemData { [ProtoMember(1)] public float? Rating { get; set; } diff --git a/MediaBrowser.Model/DTO/VideoOutputFormats.cs b/MediaBrowser.Model/DTO/VideoOutputFormats.cs index 3059f6acaf..c3840bff63 100644 --- a/MediaBrowser.Model/DTO/VideoOutputFormats.cs +++ b/MediaBrowser.Model/DTO/VideoOutputFormats.cs @@ -9,12 +9,12 @@ namespace MediaBrowser.Model.DTO { Avi, Asf, - M4v, + M4V, Mkv, Mov, Mp4, Ogv, - ThreeGP, + ThreeGp, Ts, Webm, Wmv diff --git a/MediaBrowser.Model/Entities/IHasProviderIds.cs b/MediaBrowser.Model/Entities/IHasProviderIds.cs index 8b9852dda3..96eb78f243 100644 --- a/MediaBrowser.Model/Entities/IHasProviderIds.cs +++ b/MediaBrowser.Model/Entities/IHasProviderIds.cs @@ -10,7 +10,7 @@ namespace MediaBrowser.Model.Entities Dictionary ProviderIds { get; set; } } - public static class IProviderIdsExtensions + public static class ProviderIdsExtensions { /// /// Gets a provider id diff --git a/MediaBrowser.Model/Entities/VideoType.cs b/MediaBrowser.Model/Entities/VideoType.cs index 56308426e3..b30b146904 100644 --- a/MediaBrowser.Model/Entities/VideoType.cs +++ b/MediaBrowser.Model/Entities/VideoType.cs @@ -5,7 +5,7 @@ namespace MediaBrowser.Model.Entities { VideoFile, Iso, - DVD, + Dvd, BluRay } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 67d6dfd764..13d132601b 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -36,12 +36,12 @@ - + - - + + diff --git a/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs b/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs index 55c5133a8e..e33ebcce78 100644 --- a/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs +++ b/MediaBrowser.Model/Plugins/BasePluginConfiguration.cs @@ -1,6 +1,4 @@ -using System; -using System.Runtime.Serialization; - + namespace MediaBrowser.Model.Plugins { public class BasePluginConfiguration diff --git a/MediaBrowser.Model/Properties/AssemblyInfo.cs b/MediaBrowser.Model/Properties/AssemblyInfo.cs index 6c64a5de60..a67dc993f2 100644 --- a/MediaBrowser.Model/Properties/AssemblyInfo.cs +++ b/MediaBrowser.Model/Properties/AssemblyInfo.cs @@ -1,7 +1,5 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using System.Reflection; +using System.Resources; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/MediaBrowser.ServerApplication/Properties/AssemblyInfo.cs b/MediaBrowser.ServerApplication/Properties/AssemblyInfo.cs index 09882706fd..35b3c6f98c 100644 --- a/MediaBrowser.ServerApplication/Properties/AssemblyInfo.cs +++ b/MediaBrowser.ServerApplication/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows; diff --git a/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs b/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs index 17aca6c5cd..a33fd44622 100644 --- a/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs +++ b/MediaBrowser.WebDashboard/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