Made BaseJsonHandler strongly typed. Moved DTO entities to their own DTO namespace in Model.

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti 2012-08-17 09:16:50 -04:00
parent 8a2e0badae
commit 5c094afd7e
26 changed files with 85 additions and 74 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api
@ -23,9 +24,9 @@ namespace MediaBrowser.Api
/// <summary>
/// Takes a BaseItem and returns the actual object that will be serialized by the api
/// </summary>
public static ApiBaseItemWrapper<BaseItem> GetSerializationObject(BaseItem item, bool includeChildren, Guid userId)
public static BaseItemWrapper<BaseItem> GetSerializationObject(BaseItem item, bool includeChildren, Guid userId)
{
ApiBaseItemWrapper<BaseItem> wrapper = new ApiBaseItemWrapper<BaseItem>()
BaseItemWrapper<BaseItem> wrapper = new BaseItemWrapper<BaseItem>()
{
Item = item,
UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id),

View File

@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public class GenresHandler : BaseJsonHandler
public class GenresHandler : BaseJsonHandler<IEnumerable<CategoryInfo<Genre>>>
{
protected override object GetObjectToSerialize()
protected override IEnumerable<CategoryInfo<Genre>> GetObjectToSerialize()
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
Guid userId = Guid.Parse(QueryString["userid"]);

View File

@ -1,12 +1,13 @@
using System;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public class ItemHandler : BaseJsonHandler
public class ItemHandler : BaseJsonHandler<BaseItemWrapper<BaseItem>>
{
protected sealed override object GetObjectToSerialize()
protected sealed override BaseItemWrapper<BaseItem> GetObjectToSerialize()
{
Guid userId = Guid.Parse(QueryString["userid"]);

View File

@ -2,13 +2,14 @@
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public abstract class ItemListHandler : BaseJsonHandler
public abstract class ItemListHandler : BaseJsonHandler<IEnumerable<BaseItemWrapper<BaseItem>>>
{
protected override object GetObjectToSerialize()
protected override IEnumerable<BaseItemWrapper<BaseItem>> GetObjectToSerialize()
{
return ItemsToSerialize.Select(i =>
{

View File

@ -1,11 +1,12 @@
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public class PersonHandler : BaseJsonHandler
public class PersonHandler : BaseJsonHandler<Person>
{
protected override object GetObjectToSerialize()
protected override Person GetObjectToSerialize()
{
return Kernel.Instance.ItemController.GetPerson(QueryString["name"]);
}

View File

@ -2,12 +2,13 @@
using System.Linq;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Api.HttpHandlers
{
public class PluginConfigurationHandler : BaseJsonHandler
public class PluginConfigurationHandler : BaseJsonHandler<BasePluginConfiguration>
{
protected override object GetObjectToSerialize()
protected override BasePluginConfiguration GetObjectToSerialize()
{
string pluginName = QueryString["name"];

View File

@ -1,16 +1,17 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.DTO;
namespace MediaBrowser.Api.HttpHandlers
{
/// <summary>
/// Provides information about installed plugins
/// </summary>
public class PluginsHandler : BaseJsonHandler
public class PluginsHandler : BaseJsonHandler<IEnumerable<PluginInfo>>
{
protected override object GetObjectToSerialize()
protected override IEnumerable<PluginInfo> GetObjectToSerialize()
{
var plugins = Kernel.Instance.Plugins.Select(p =>
{

View File

@ -1,17 +1,19 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public class StudiosHandler : BaseJsonHandler
public class StudiosHandler : BaseJsonHandler<IEnumerable<CategoryInfo<Studio>>>
{
protected override object GetObjectToSerialize()
protected override IEnumerable<CategoryInfo<Studio>> GetObjectToSerialize()
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
Guid userId = Guid.Parse(QueryString["userid"]);
return Kernel.Instance.GetAllStudios(parent, userId);
}
}

View File

@ -1,12 +1,13 @@
using System;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Configuration;
namespace MediaBrowser.Api.HttpHandlers
{
public class UserConfigurationHandler : BaseJsonHandler
public class UserConfigurationHandler : BaseJsonHandler<UserConfiguration>
{
protected override object GetObjectToSerialize()
protected override UserConfiguration GetObjectToSerialize()
{
Guid userId = Guid.Parse(QueryString["userid"]);

View File

@ -1,11 +1,13 @@
using MediaBrowser.Common.Net.Handlers;
using System.Collections.Generic;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Api.HttpHandlers
{
class UsersHandler : BaseJsonHandler
class UsersHandler : BaseJsonHandler<IEnumerable<User>>
{
protected override object GetObjectToSerialize()
protected override IEnumerable<User> GetObjectToSerialize()
{
return Kernel.Instance.Users;
}

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using MediaBrowser.Model.Entities;
using System.Drawing;
using MediaBrowser.Common.Drawing;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{

View File

@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public class YearsHandler : BaseJsonHandler
public class YearsHandler : BaseJsonHandler<IEnumerable<CategoryInfo<Year>>>
{
protected override object GetObjectToSerialize()
protected override IEnumerable<CategoryInfo<Year>> GetObjectToSerialize()
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
Guid userId = Guid.Parse(QueryString["userid"]);

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Users;
@ -90,7 +91,7 @@ namespace MediaBrowser.ApiInteraction
/// <param name="maxWidth">Use if a max width is required. Aspect ratio will be preserved.</param>
/// <param name="maxHeight">Use if a max height is required. Aspect ratio will be preserved.</param>
/// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param>
public IEnumerable<string> GetBackdropImageUrls(ApiBaseItemWrapper<ApiBaseItem> itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
public IEnumerable<string> GetBackdropImageUrls(BaseItemWrapper<ApiBaseItem> itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
{
Guid? backdropItemId = null;
int backdropCount = 0;
@ -130,7 +131,7 @@ namespace MediaBrowser.ApiInteraction
/// <param name="maxWidth">Use if a max width is required. Aspect ratio will be preserved.</param>
/// <param name="maxHeight">Use if a max height is required. Aspect ratio will be preserved.</param>
/// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param>
public string GetLogoImageUrl(ApiBaseItemWrapper<ApiBaseItem> itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
public string GetLogoImageUrl(BaseItemWrapper<ApiBaseItem> itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null)
{
Guid? logoItemId = !string.IsNullOrEmpty(itemWrapper.Item.LogoImagePath) ? itemWrapper.Item.Id : itemWrapper.ParentLogoItemId;
@ -153,7 +154,7 @@ namespace MediaBrowser.ApiInteraction
/// <summary>
/// Gets a BaseItem
/// </summary>
public async Task<ApiBaseItemWrapper<ApiBaseItem>> GetItemAsync(Guid id, Guid userId)
public async Task<BaseItemWrapper<ApiBaseItem>> GetItemAsync(Guid id, Guid userId)
{
string url = ApiUrl + "/item?userId=" + userId.ToString();
@ -164,7 +165,7 @@ namespace MediaBrowser.ApiInteraction
using (Stream stream = await HttpClient.GetStreamAsync(url))
{
return JsonSerializer.DeserializeFromStream<ApiBaseItemWrapper<ApiBaseItem>>(stream);
return JsonSerializer.DeserializeFromStream<BaseItemWrapper<ApiBaseItem>>(stream);
}
}
@ -210,33 +211,33 @@ namespace MediaBrowser.ApiInteraction
/// <summary>
/// Gets all items that contain a given Year
/// </summary>
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithYearAsync(string name, Guid userId)
public async Task<IEnumerable<BaseItemWrapper<ApiBaseItem>>> GetItemsWithYearAsync(string name, Guid userId)
{
string url = ApiUrl + "/itemswithyear?userId=" + userId.ToString() + "&name=" + name;
using (Stream stream = await HttpClient.GetStreamAsync(url))
{
return JsonSerializer.DeserializeFromStream<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>>(stream);
return JsonSerializer.DeserializeFromStream<IEnumerable<BaseItemWrapper<ApiBaseItem>>>(stream);
}
}
/// <summary>
/// Gets all items that contain a given Genre
/// </summary>
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithGenreAsync(string name, Guid userId)
public async Task<IEnumerable<BaseItemWrapper<ApiBaseItem>>> GetItemsWithGenreAsync(string name, Guid userId)
{
string url = ApiUrl + "/itemswithgenre?userId=" + userId.ToString() + "&name=" + name;
using (Stream stream = await HttpClient.GetStreamAsync(url))
{
return JsonSerializer.DeserializeFromStream<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>>(stream);
return JsonSerializer.DeserializeFromStream<IEnumerable<BaseItemWrapper<ApiBaseItem>>>(stream);
}
}
/// <summary>
/// Gets all items that contain a given Person
/// </summary>
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId)
public async Task<IEnumerable<BaseItemWrapper<ApiBaseItem>>> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId)
{
string url = ApiUrl + "/itemswithperson?userId=" + userId.ToString() + "&name=" + name;
@ -247,7 +248,7 @@ namespace MediaBrowser.ApiInteraction
using (Stream stream = await HttpClient.GetStreamAsync(url))
{
return JsonSerializer.DeserializeFromStream<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>>(stream);
return JsonSerializer.DeserializeFromStream<IEnumerable<BaseItemWrapper<ApiBaseItem>>>(stream);
}
}
@ -280,13 +281,13 @@ namespace MediaBrowser.ApiInteraction
/// <summary>
/// Gets all items that contain a given Studio
/// </summary>
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithStudioAsync(string name, Guid userId)
public async Task<IEnumerable<BaseItemWrapper<ApiBaseItem>>> GetItemsWithStudioAsync(string name, Guid userId)
{
string url = ApiUrl + "/itemswithstudio?userId=" + userId.ToString() + "&name=" + name;
using (Stream stream = await HttpClient.GetStreamAsync(url))
{
return JsonSerializer.DeserializeFromStream<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>>(stream);
return JsonSerializer.DeserializeFromStream<IEnumerable<BaseItemWrapper<ApiBaseItem>>>(stream);
}
}

View File

@ -4,7 +4,7 @@ using MediaBrowser.Common.Serialization;
namespace MediaBrowser.Common.Net.Handlers
{
public abstract class BaseJsonHandler : BaseHandler
public abstract class BaseJsonHandler<T> : BaseHandler
{
public override string ContentType
{
@ -12,7 +12,7 @@ namespace MediaBrowser.Common.Net.Handlers
}
private bool _ObjectToSerializeEnsured = false;
private object _ObjectToSerialize;
private T _ObjectToSerialize;
private void EnsureObjectToSerialize()
{
@ -29,7 +29,7 @@ namespace MediaBrowser.Common.Net.Handlers
}
}
private object ObjectToSerialize
private T ObjectToSerialize
{
get
{
@ -38,7 +38,7 @@ namespace MediaBrowser.Common.Net.Handlers
}
}
protected abstract object GetObjectToSerialize();
protected abstract T GetObjectToSerialize();
protected override void PrepareResponse()
{
@ -51,7 +51,7 @@ namespace MediaBrowser.Common.Net.Handlers
{
return Task.Run(() =>
{
JsonSerializer.SerializeToStream(ObjectToSerialize, stream);
JsonSerializer.SerializeToStream<T>(ObjectToSerialize, stream);
});
}
}

View File

@ -13,6 +13,7 @@ using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Progress;
using MediaBrowser.Model.Users;

View File

@ -113,10 +113,6 @@ namespace MediaBrowser.Controller.Xml
item.CustomRating = reader.ReadString();
break;
case "CustomPin":
item.CustomPin = reader.ReadString();
break;
case "Genre":
{
var genres = (item.Genres ?? new string[] { }).ToList();

View File

@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Model.Entities
namespace MediaBrowser.Model.DTO
{
/// <summary>
/// This is a concrete class that the UI can use to deserialize
@ -10,7 +11,7 @@ namespace MediaBrowser.Model.Entities
/// </summary>
public class ApiBaseItem : BaseItem
{
// TV Series
// Series properties
public string Status { get; set; }
public IEnumerable<DayOfWeek> AirDays { get; set; }
public string AirTime { get; set; }
@ -19,14 +20,14 @@ namespace MediaBrowser.Model.Entities
/// <summary>
/// This is the full return object when requesting an Item
/// </summary>
public class ApiBaseItemWrapper<T>
public class BaseItemWrapper<T>
where T : BaseItem
{
public T Item { get; set; }
public UserItemData UserItemData { get; set; }
public IEnumerable<ApiBaseItemWrapper<T>> Children { get; set; }
public IEnumerable<BaseItemWrapper<T>> Children { get; set; }
public bool IsFolder { get; set; }
@ -55,4 +56,11 @@ namespace MediaBrowser.Model.Entities
public int? ParentBackdropCount { get; set; }
}
/// <summary>
/// This is strictly for convenience so the UI's don't have to use the verbose generic syntax of BaseItemWrapper<ApiBaseItem>
/// </summary>
public class ApiBaseItemWrapper : BaseItemWrapper<ApiBaseItem>
{
}
}

View File

@ -1,5 +1,5 @@

namespace MediaBrowser.Model.Entities
namespace MediaBrowser.Model.DTO
{
/// <summary>
/// This is a stub class used by the api to get IBN types along with their item counts

View File

@ -1,6 +1,6 @@
using System;
namespace MediaBrowser.Model.Plugins
namespace MediaBrowser.Model.DTO
{
/// <summary>
/// This is a serializable stub class that is used by the api to provide information about installed plugins.

View File

@ -26,9 +26,9 @@ namespace MediaBrowser.Model.Entities
public IEnumerable<string> BackdropImagePaths { get; set; }
public string OfficialRating { get; set; }
[IgnoreDataMember]
public string CustomRating { get; set; }
public string CustomPin { get; set; }
public string Overview { get; set; }
public string Tagline { get; set; }

View File

@ -33,11 +33,11 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Configuration\UserConfiguration.cs" />
<Compile Include="Entities\ApiBaseItem.cs" />
<Compile Include="DTO\ApiBaseItem.cs" />
<Compile Include="Entities\Audio.cs" />
<Compile Include="Entities\BaseEntity.cs" />
<Compile Include="Entities\BaseItem.cs" />
<Compile Include="Entities\CategoryInfo.cs" />
<Compile Include="DTO\CategoryInfo.cs" />
<Compile Include="Entities\Folder.cs" />
<Compile Include="Entities\Genre.cs" />
<Compile Include="Entities\ImageType.cs" />
@ -47,7 +47,7 @@
<Compile Include="Entities\Video.cs" />
<Compile Include="Entities\Year.cs" />
<Compile Include="Plugins\BasePluginConfiguration.cs" />
<Compile Include="Plugins\PluginInfo.cs" />
<Compile Include="DTO\PluginInfo.cs" />
<Compile Include="Progress\TaskProgress.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Users\User.cs" />

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Movies.Entities
{

View File

@ -6,9 +6,6 @@ namespace MediaBrowser.Movies.Entities
{
public class Movie : Video
{
public string TmdbId { get; set; }
public string ImdbId { get; set; }
[IgnoreDataMember]
public IEnumerable<Video> SpecialFeatures { get; set; }
}

View File

@ -22,15 +22,15 @@ namespace MediaBrowser.ServerApplication
Progress<TaskProgress> progress = new Progress<TaskProgress>();
Common.UI.Splash splash = new Common.UI.Splash(progress);
splash.Show();
try
{
splash.Show();
new Kernel().Init(progress);
}
catch (Exception ex)
{
MessageBox.Show("There was an error launching Media Browser: " + ex.Message);
MessageBox.Show("There was an error launching Media Browser Server: " + ex.Message);
}
finally
{

View File

@ -4,6 +4,5 @@ namespace MediaBrowser.TV.Entities
{
public class Episode : Video
{
public string SeasonNumber { get; set; }
}
}

View File

@ -31,10 +31,6 @@ namespace MediaBrowser.TV.Metadata
}
break;
case "SeasonNumber":
item.SeasonNumber = reader.ReadString();
break;
case "EpisodeName":
item.Name = reader.ReadString();
break;