read 3d format from xml
This commit is contained in:
parent
934584313e
commit
6025a89235
|
@ -562,7 +562,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
|
||||
|
||||
var items = _itemRepo.RetrieveItems<Audio>(item.ThemeSongIds)
|
||||
var items = item.ThemeSongIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user))
|
||||
.Select(t => t.Result)
|
||||
|
@ -602,7 +602,7 @@ namespace MediaBrowser.Api
|
|||
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
|
||||
|
||||
var items =
|
||||
_itemRepo.RetrieveItems<Video>(item.ThemeVideoIds)
|
||||
item.ThemeVideoIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user))
|
||||
.Select(t => t.Result)
|
||||
|
|
|
@ -399,7 +399,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
|
||||
|
||||
var items = _itemRepo.RetrieveItems<Video>(movie.SpecialFeatureIds).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, fields, user)).Select(t => t.Result).ToList();
|
||||
var items = movie.SpecialFeatureIds.Select(_itemRepo.RetrieveItem).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, fields, user)).Select(t => t.Result).ToList();
|
||||
|
||||
return ToOptimizedResult(items);
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
|
||||
|
||||
var items = _itemRepo.RetrieveItems<Trailer>(item.LocalTrailerIds).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, fields, user)).Select(t => t.Result).ToList();
|
||||
var items = item.LocalTrailerIds.Select(_itemRepo.RetrieveItem).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, fields, user)).Select(t => t.Result).ToList();
|
||||
|
||||
return ToOptimizedResult(items);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
var video = (Video)item;
|
||||
|
||||
var items = _itemRepo.RetrieveItems<Video>(video.AdditionalPartIds)
|
||||
var items = video.AdditionalPartIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user))
|
||||
.Select(t => t.Result)
|
||||
|
|
|
@ -663,7 +663,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
return LibraryManager.ResolvePaths<Trailer>(files, null).Select(video =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = LibraryManager.RetrieveItem(video.Id, typeof(Trailer)) as Trailer;
|
||||
var dbItem = LibraryManager.RetrieveItem(video.Id) as Trailer;
|
||||
|
||||
if (dbItem != null)
|
||||
{
|
||||
|
@ -724,7 +724,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
return LibraryManager.ResolvePaths<Audio.Audio>(files, null).Select(audio =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = LibraryManager.RetrieveItem(audio.Id, typeof(Audio.Audio)) as Audio.Audio;
|
||||
var dbItem = LibraryManager.RetrieveItem(audio.Id) as Audio.Audio;
|
||||
|
||||
if (dbItem != null)
|
||||
{
|
||||
|
@ -782,7 +782,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
return LibraryManager.ResolvePaths<Video>(files, null).Select(item =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = LibraryManager.RetrieveItem(item.Id, typeof(Video)) as Video;
|
||||
var dbItem = LibraryManager.RetrieveItem(item.Id) as Video;
|
||||
|
||||
if (dbItem != null)
|
||||
{
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ChildDefinition
|
||||
/// </summary>
|
||||
public class ChildDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the item id.
|
||||
/// </summary>
|
||||
/// <value>The item id.</value>
|
||||
public Guid ItemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type.
|
||||
/// </summary>
|
||||
/// <value>The type.</value>
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ using MediaBrowser.Common.Progress;
|
|||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Localization;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Reflection;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
|
@ -22,8 +21,6 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// </summary>
|
||||
public class Folder : BaseItem
|
||||
{
|
||||
private static readonly TypeMapper TypeMapper = new TypeMapper();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is folder.
|
||||
/// </summary>
|
||||
|
@ -118,12 +115,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
await LibraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => new ChildDefinition
|
||||
{
|
||||
ItemId = i.Id,
|
||||
Type = i.GetType().FullName
|
||||
|
||||
}), cancellationToken).ConfigureAwait(false);
|
||||
await ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => i.Id), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -161,12 +153,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
LibraryManager.ReportItemRemoved(item);
|
||||
|
||||
return ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => new ChildDefinition
|
||||
{
|
||||
ItemId = i.Id,
|
||||
Type = i.GetType().FullName
|
||||
|
||||
}), cancellationToken);
|
||||
return ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => i.Id), cancellationToken);
|
||||
}
|
||||
|
||||
#region Indexing
|
||||
|
@ -729,12 +716,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
await ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => new ChildDefinition
|
||||
{
|
||||
ItemId = i.Id,
|
||||
Type = i.GetType().FullName
|
||||
|
||||
}), cancellationToken).ConfigureAwait(false);
|
||||
await ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => i.Id), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
//force the indexes to rebuild next time
|
||||
IndexCache.Clear();
|
||||
|
@ -872,26 +854,20 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// </summary>
|
||||
/// <param name="child">The child.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
private BaseItem RetrieveChild(ChildDefinition child)
|
||||
private BaseItem RetrieveChild(Guid child)
|
||||
{
|
||||
var type = child.Type;
|
||||
var item = LibraryManager.RetrieveItem(child);
|
||||
|
||||
var itemType = TypeMapper.GetType(type);
|
||||
|
||||
if (itemType == null)
|
||||
if (item != null)
|
||||
{
|
||||
Logger.Error("Cannot find type {0}. Probably belongs to plug-in that is no longer loaded.", type);
|
||||
return null;
|
||||
if (item is IByReferenceItem)
|
||||
{
|
||||
return LibraryManager.GetOrAddByReferenceItem(item);
|
||||
}
|
||||
|
||||
item.Parent = this;
|
||||
}
|
||||
|
||||
var item = LibraryManager.RetrieveItem(child.ItemId, itemType);
|
||||
|
||||
if (item is IByReferenceItem)
|
||||
{
|
||||
return LibraryManager.GetOrAddByReferenceItem(item);
|
||||
}
|
||||
|
||||
item.Parent = this;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ namespace MediaBrowser.Controller.Entities.Movies
|
|||
return LibraryManager.ResolvePaths<Video>(files, null).Select(video =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = LibraryManager.RetrieveItem(video.Id, typeof(Video)) as Video;
|
||||
var dbItem = LibraryManager.RetrieveItem(video.Id) as Video;
|
||||
|
||||
if (dbItem != null)
|
||||
{
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
return LibraryManager.ResolvePaths<Video>(files, null).Select(video =>
|
||||
{
|
||||
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
||||
var dbItem = LibraryManager.RetrieveItem(video.Id, typeof(Video)) as Video;
|
||||
var dbItem = LibraryManager.RetrieveItem(video.Id) as Video;
|
||||
|
||||
if (dbItem != null)
|
||||
{
|
||||
|
|
|
@ -216,9 +216,8 @@ namespace MediaBrowser.Controller.Library
|
|||
/// Retrieves the item.
|
||||
/// </summary>
|
||||
/// <param name="id">The id.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
BaseItem RetrieveItem(Guid id, Type type);
|
||||
BaseItem RetrieveItem(Guid id);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the artists.
|
||||
|
|
|
@ -74,7 +74,6 @@
|
|||
<Compile Include="Dto\SessionInfoDtoBuilder.cs" />
|
||||
<Compile Include="Entities\Audio\MusicAlbumDisc.cs" />
|
||||
<Compile Include="Entities\Audio\MusicGenre.cs" />
|
||||
<Compile Include="Entities\ChildDefinition.cs" />
|
||||
<Compile Include="Entities\Game.cs" />
|
||||
<Compile Include="Entities\IByReferenceItem.cs" />
|
||||
<Compile Include="Entities\MusicVideo.cs" />
|
||||
|
@ -83,7 +82,6 @@
|
|||
<Compile Include="Library\IMetadataSaver.cs" />
|
||||
<Compile Include="Library\ItemUpdateType.cs" />
|
||||
<Compile Include="Localization\ILocalizationManager.cs" />
|
||||
<Compile Include="Reflection\TypeMapper.cs" />
|
||||
<Compile Include="Session\ISessionManager.cs" />
|
||||
<Compile Include="Drawing\ImageExtensions.cs" />
|
||||
<Compile Include="Drawing\ImageHeader.cs" />
|
||||
|
|
|
@ -54,9 +54,8 @@ namespace MediaBrowser.Controller.Persistence
|
|||
/// Retrieves the item.
|
||||
/// </summary>
|
||||
/// <param name="id">The id.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
BaseItem RetrieveItem(Guid id, Type type);
|
||||
BaseItem RetrieveItem(Guid id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets chapters for an item
|
||||
|
@ -87,7 +86,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||
/// </summary>
|
||||
/// <param name="parentId">The parent id.</param>
|
||||
/// <returns>IEnumerable{ChildDefinition}.</returns>
|
||||
IEnumerable<ChildDefinition> GetChildren(Guid parentId);
|
||||
IEnumerable<Guid> GetChildren(Guid parentId);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the children.
|
||||
|
@ -96,39 +95,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||
/// <param name="children">The children.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveChildren(Guid parentId, IEnumerable<ChildDefinition> children, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class ItemRepositoryExtensions
|
||||
/// </summary>
|
||||
public static class ItemRepositoryExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the item.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="repository">The repository.</param>
|
||||
/// <param name="id">The id.</param>
|
||||
/// <returns>``0.</returns>
|
||||
public static T RetrieveItem<T>(this IItemRepository repository, Guid id)
|
||||
where T : BaseItem, new()
|
||||
{
|
||||
return repository.RetrieveItem(id, typeof(T)) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the item.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="repository">The repository.</param>
|
||||
/// <param name="idList">The id list.</param>
|
||||
/// <returns>IEnumerable{``0}.</returns>
|
||||
public static IEnumerable<T> RetrieveItems<T>(this IItemRepository repository, IEnumerable<Guid> idList)
|
||||
where T : BaseItem, new()
|
||||
{
|
||||
return idList.Select(repository.RetrieveItem<T>).Where(i => i != null);
|
||||
}
|
||||
Task SaveChildren(Guid parentId, IEnumerable<Guid> children, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case "CustomRating":
|
||||
{
|
||||
var val = reader.ReadElementContentAsString();
|
||||
|
@ -476,7 +476,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
item.SetProviderId(MetadataProviders.Tmdb, tmdb);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "CollectionNumber":
|
||||
var tmdbCollection = reader.ReadElementContentAsString();
|
||||
if (!string.IsNullOrWhiteSpace(tmdbCollection))
|
||||
|
@ -523,12 +523,94 @@ namespace MediaBrowser.Controller.Providers
|
|||
FetchFromStudiosNode(reader.ReadSubtree(), item);
|
||||
break;
|
||||
|
||||
case "MediaInfo":
|
||||
FetchFromMediaInfoNode(reader.ReadSubtree(), item);
|
||||
break;
|
||||
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches from media info node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The reader.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
private void FetchFromMediaInfoNode(XmlReader reader, T item)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "Video":
|
||||
FetchFromMediaInfoVideoNode(reader.ReadSubtree(), item);
|
||||
break;
|
||||
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches from media info video node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The reader.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
private void FetchFromMediaInfoVideoNode(XmlReader reader, T item)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "3DFormat":
|
||||
{
|
||||
var video = item as Video;
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
var val = reader.ReadElementContentAsString();
|
||||
|
||||
if (string.Equals("HSBS", val))
|
||||
{
|
||||
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
||||
}
|
||||
else if (string.Equals("HTAB", val))
|
||||
{
|
||||
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
||||
}
|
||||
else if (string.Equals("FTAB", val))
|
||||
{
|
||||
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
||||
}
|
||||
else if (string.Equals("FSBS", val))
|
||||
{
|
||||
video.Video3DFormat = Video3DFormat.FullSideBySide;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches from taglines node.
|
||||
/// </summary>
|
||||
|
|
|
@ -573,7 +573,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
Directory.CreateDirectory(rootFolderPath);
|
||||
}
|
||||
|
||||
var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder)), typeof(AggregateFolder)) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath));
|
||||
var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath));
|
||||
|
||||
// Add in the plug-in folders
|
||||
foreach (var child in PluginFolderCreators)
|
||||
|
@ -598,7 +598,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>UserRootFolder.</returns>
|
||||
public UserRootFolder GetUserRootFolder(string userRootPath)
|
||||
{
|
||||
return _userRootFolders.GetOrAdd(userRootPath, key => RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder)), typeof(UserRootFolder)) as UserRootFolder ??
|
||||
return _userRootFolders.GetOrAdd(userRootPath, key => RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ??
|
||||
(UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath)));
|
||||
}
|
||||
|
||||
|
@ -793,7 +793,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
var id = path.GetMBId(type);
|
||||
|
||||
var item = RetrieveItem(id, type) as T;
|
||||
var item = RetrieveItem(id) as T;
|
||||
if (item == null)
|
||||
{
|
||||
item = new T
|
||||
|
@ -1350,11 +1350,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// Retrieves the item.
|
||||
/// </summary>
|
||||
/// <param name="id">The id.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
public BaseItem RetrieveItem(Guid id, Type type)
|
||||
public BaseItem RetrieveItem(Guid id)
|
||||
{
|
||||
return ItemRepository.RetrieveItem(id, type);
|
||||
return ItemRepository.RetrieveItem(id);
|
||||
}
|
||||
|
||||
private readonly ConcurrentDictionary<string, SemaphoreSlim> _fileLocks = new ConcurrentDictionary<string, SemaphoreSlim>();
|
||||
|
|
|
@ -146,6 +146,7 @@
|
|||
<Compile Include="MediaEncoder\MediaEncoder.cs" />
|
||||
<Compile Include="Persistence\SqliteChapterRepository.cs" />
|
||||
<Compile Include="Persistence\SqliteExtensions.cs" />
|
||||
<Compile Include="Persistence\TypeMapper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Providers\ProviderManager.cs" />
|
||||
<Compile Include="ScheduledTasks\ArtistValidationTask.cs" />
|
||||
|
|
|
@ -23,6 +23,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
private SQLiteConnection _connection;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private TypeMapper _typeMapper = new TypeMapper();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the repository
|
||||
|
@ -103,11 +105,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists baseitems (guid GUID primary key, data BLOB)",
|
||||
"create index if not exists idx_baseitems on baseitems(guid)",
|
||||
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB)",
|
||||
"create index if not exists idx_TypedBaseItems on baseitems(guid)",
|
||||
|
||||
"create table if not exists ChildDefinitions (ParentId GUID, ItemId GUID, Type TEXT, PRIMARY KEY (ParentId, ItemId))",
|
||||
"create index if not exists idx_ChildDefinitions on ChildDefinitions(ParentId,ItemId)",
|
||||
"create table if not exists ChildrenIds (ParentId GUID, ItemId GUID, PRIMARY KEY (ParentId, ItemId))",
|
||||
"create index if not exists idx_ChildrenIds on ChildrenIds(ParentId,ItemId)",
|
||||
|
||||
//pragmas
|
||||
"pragma temp_store = memory"
|
||||
|
@ -132,27 +134,27 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
{
|
||||
_saveItemCommand = new SQLiteCommand
|
||||
{
|
||||
CommandText = "replace into baseitems (guid, data) values (@1, @2)"
|
||||
CommandText = "replace into TypedBaseItems (guid, type, data) values (@1, @2, @3)"
|
||||
};
|
||||
|
||||
_saveItemCommand.Parameters.Add(new SQLiteParameter("@1"));
|
||||
_saveItemCommand.Parameters.Add(new SQLiteParameter("@2"));
|
||||
_saveItemCommand.Parameters.Add(new SQLiteParameter("@3"));
|
||||
|
||||
_deleteChildrenCommand = new SQLiteCommand
|
||||
{
|
||||
CommandText = "delete from ChildDefinitions where ParentId=@ParentId"
|
||||
CommandText = "delete from ChildrenIds where ParentId=@ParentId"
|
||||
};
|
||||
|
||||
_deleteChildrenCommand.Parameters.Add(new SQLiteParameter("@ParentId"));
|
||||
|
||||
_saveChildrenCommand = new SQLiteCommand
|
||||
{
|
||||
CommandText = "replace into ChildDefinitions (ParentId, ItemId, Type) values (@ParentId, @ItemId, @Type)"
|
||||
CommandText = "replace into ChildrenIds (ParentId, ItemId) values (@ParentId, @ItemId)"
|
||||
};
|
||||
|
||||
_saveChildrenCommand.Parameters.Add(new SQLiteParameter("@ParentId"));
|
||||
_saveChildrenCommand.Parameters.Add(new SQLiteParameter("@ItemId"));
|
||||
_saveChildrenCommand.Parameters.Add(new SQLiteParameter("@Type"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -210,7 +212,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
_saveItemCommand.Parameters[0].Value = item.Id;
|
||||
_saveItemCommand.Parameters[1].Value = _jsonSerializer.SerializeToBytes(item);
|
||||
_saveItemCommand.Parameters[1].Value = item.GetType().FullName;
|
||||
_saveItemCommand.Parameters[2].Value = _jsonSerializer.SerializeToBytes(item);
|
||||
|
||||
_saveItemCommand.Transaction = transaction;
|
||||
|
||||
|
@ -254,11 +257,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
/// Internal retrieve from items or users table
|
||||
/// </summary>
|
||||
/// <param name="id">The id.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>BaseItem.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">id</exception>
|
||||
/// <exception cref="System.ArgumentException"></exception>
|
||||
public BaseItem RetrieveItem(Guid id, Type type)
|
||||
public BaseItem RetrieveItem(Guid id)
|
||||
{
|
||||
if (id == Guid.Empty)
|
||||
{
|
||||
|
@ -267,7 +269,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select data from baseitems where guid = @guid";
|
||||
cmd.CommandText = "select type,data from TypedBaseItems where guid = @guid";
|
||||
var guidParam = cmd.Parameters.Add("@guid", DbType.Guid);
|
||||
guidParam.Value = id;
|
||||
|
||||
|
@ -275,7 +277,18 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
using (var stream = reader.GetMemoryStream(0))
|
||||
var typeString = reader.GetString(0);
|
||||
|
||||
var type = _typeMapper.GetType(typeString);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
_logger.Debug("Unknown type {0}", typeString);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var stream = reader.GetMemoryStream(1))
|
||||
{
|
||||
return _jsonSerializer.DeserializeFromStream(stream, type) as BaseItem;
|
||||
}
|
||||
|
@ -424,7 +437,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ChildDefinition> GetChildren(Guid parentId)
|
||||
public IEnumerable<Guid> GetChildren(Guid parentId)
|
||||
{
|
||||
if (parentId == Guid.Empty)
|
||||
{
|
||||
|
@ -433,7 +446,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select ItemId,Type from ChildDefinitions where ParentId = @ParentId";
|
||||
cmd.CommandText = "select ItemId from ChildrenIds where ParentId = @ParentId";
|
||||
|
||||
cmd.Parameters.Add("@ParentId", DbType.Guid).Value = parentId;
|
||||
|
||||
|
@ -441,17 +454,13 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
yield return new ChildDefinition
|
||||
{
|
||||
ItemId = reader.GetGuid(0),
|
||||
Type = reader.GetString(1)
|
||||
};
|
||||
yield return reader.GetGuid(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveChildren(Guid parentId, IEnumerable<ChildDefinition> children, CancellationToken cancellationToken)
|
||||
public async Task SaveChildren(Guid parentId, IEnumerable<Guid> children, CancellationToken cancellationToken)
|
||||
{
|
||||
if (parentId == Guid.Empty)
|
||||
{
|
||||
|
@ -483,13 +492,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
_deleteChildrenCommand.Transaction = transaction;
|
||||
await _deleteChildrenCommand.ExecuteNonQueryAsync(cancellationToken);
|
||||
|
||||
foreach (var chapter in children)
|
||||
foreach (var id in children)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
_saveChildrenCommand.Parameters[0].Value = parentId;
|
||||
_saveChildrenCommand.Parameters[1].Value = chapter.ItemId;
|
||||
_saveChildrenCommand.Parameters[2].Value = chapter.Type;
|
||||
_saveChildrenCommand.Parameters[1].Value = id;
|
||||
|
||||
_saveChildrenCommand.Transaction = transaction;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Controller.Reflection
|
||||
namespace MediaBrowser.Server.Implementations.Persistence
|
||||
{
|
||||
/// <summary>
|
||||
/// Class TypeMapper
|
|
@ -210,9 +210,9 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
|||
{
|
||||
var allItems = sourceItems.ToList();
|
||||
|
||||
var localTrailers = allItems.SelectMany(i => _itemRepo.RetrieveItems<Trailer>(i.LocalTrailerIds));
|
||||
var localTrailers = allItems.SelectMany(i => i.LocalTrailerIds.Select(_itemRepo.RetrieveItem)).Cast<Video>();
|
||||
|
||||
var themeVideos = allItems.SelectMany(i => _itemRepo.RetrieveItems<Video>(i.ThemeVideoIds));
|
||||
var themeVideos = allItems.SelectMany(i => i.ThemeVideoIds.Select(_itemRepo.RetrieveItem)).Cast<Video>();
|
||||
|
||||
var videos = allItems.OfType<Video>().ToList();
|
||||
|
||||
|
@ -222,8 +222,8 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
|||
|
||||
items.AddRange(themeVideos);
|
||||
|
||||
items.AddRange(videos.SelectMany(i => _itemRepo.RetrieveItems<Video>(i.AdditionalPartIds)).ToList());
|
||||
items.AddRange(videos.OfType<Movie>().SelectMany(i => _itemRepo.RetrieveItems<Video>(i.SpecialFeatureIds)).ToList());
|
||||
items.AddRange(videos.SelectMany(i => i.AdditionalPartIds).Select(_itemRepo.RetrieveItem).Cast<Video>());
|
||||
items.AddRange(videos.OfType<Movie>().SelectMany(i => i.SpecialFeatureIds).Select(_itemRepo.RetrieveItem).Cast<Video>());
|
||||
|
||||
return items.Where(i =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user