2012-07-13 03:50:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2012-07-20 02:22:44 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-07-20 02:22:44 +00:00
|
|
|
|
using MediaBrowser.Model.Users;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains some helpers for the api
|
|
|
|
|
/// </summary>
|
2012-07-13 03:50:50 +00:00
|
|
|
|
public static class ApiService
|
|
|
|
|
{
|
|
|
|
|
public static BaseItem GetItemById(string id)
|
|
|
|
|
{
|
2012-07-16 16:50:44 +00:00
|
|
|
|
Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
return Kernel.Instance.GetItemById(guid);
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <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)
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
ApiBaseItemWrapper<BaseItem> wrapper = new ApiBaseItemWrapper<BaseItem>()
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
Item = item,
|
|
|
|
|
UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id),
|
2012-07-29 15:19:25 +00:00
|
|
|
|
Type = item.GetType().Name,
|
|
|
|
|
IsFolder = (item is Folder)
|
2012-07-20 02:22:44 +00:00
|
|
|
|
};
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (includeChildren)
|
2012-07-16 16:50:44 +00:00
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
var folder = item as Folder;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (folder != null)
|
2012-07-16 16:50:44 +00:00
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
wrapper.Children = Kernel.Instance.GetParentalAllowedChildren(folder, userId).Select(c => GetSerializationObject(c, false, userId));
|
2012-07-16 16:50:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
return wrapper;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|