From 846857b60eb795fc7fd7384b24be5ce4737d65d8 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 1 Nov 2019 16:53:16 +0100 Subject: [PATCH] Deserialize with the correct type (and warning fixes) --- .../Data/SqliteItemRepository.cs | 11 +++++------ .../Library/LibraryManager.cs | 2 -- .../Entities/ICollectionFolder.cs | 3 +++ MediaBrowser.Controller/Entities/UserView.cs | 16 +++++++++------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 31a661c5d9..30027ff0d5 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -3,10 +3,8 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; -using System.Runtime.Serialization; using System.Text; using System.Text.Json; -using System.Text.Json.Serialization; using System.Threading; using Emby.Server.Implementations.Playlists; using MediaBrowser.Common.Json; @@ -28,7 +26,6 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Querying; -using MediaBrowser.Model.Serialization; using Microsoft.Extensions.Logging; using SQLitePCL.pretty; @@ -659,12 +656,14 @@ namespace Emby.Server.Implementations.Data private void SaveItem(BaseItem item, BaseItem topParent, string userDataKey, IStatement saveItemStatement) { + Type type = item.GetType(); + saveItemStatement.TryBind("@guid", item.Id); - saveItemStatement.TryBind("@type", item.GetType().FullName); + saveItemStatement.TryBind("@type", type.FullName); - if (TypeRequiresDeserialization(item.GetType())) + if (TypeRequiresDeserialization(type)) { - saveItemStatement.TryBind("@data", JsonSerializer.SerializeToUtf8Bytes(item, _jsonOptions)); + saveItemStatement.TryBind("@data", JsonSerializer.SerializeToUtf8Bytes(item, type, _jsonOptions)); } else { diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 87e951f25d..fc73fc649d 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -2175,7 +2175,6 @@ namespace Emby.Server.Implementations.Library DisplayParentId = parentId }; - CreateItem(item, null); isNew = true; @@ -2197,7 +2196,6 @@ namespace Emby.Server.Implementations.Library { // Need to force save to increment DateLastSaved ForceSave = true - }, RefreshPriority.Normal); } diff --git a/MediaBrowser.Controller/Entities/ICollectionFolder.cs b/MediaBrowser.Controller/Entities/ICollectionFolder.cs index a6a9a07836..4f0760746e 100644 --- a/MediaBrowser.Controller/Entities/ICollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/ICollectionFolder.cs @@ -8,8 +8,11 @@ namespace MediaBrowser.Controller.Entities public interface ICollectionFolder : IHasCollectionType { string Path { get; } + string Name { get; } + Guid Id { get; } + string[] PhysicalLocations { get; } } diff --git a/MediaBrowser.Controller/Entities/UserView.cs b/MediaBrowser.Controller/Entities/UserView.cs index fd045f0dda..4ce9ec6f82 100644 --- a/MediaBrowser.Controller/Entities/UserView.cs +++ b/MediaBrowser.Controller/Entities/UserView.cs @@ -10,34 +10,36 @@ namespace MediaBrowser.Controller.Entities { public class UserView : Folder, IHasCollectionType { + /// public string ViewType { get; set; } + + /// public new Guid DisplayParentId { get; set; } + /// public Guid? UserId { get; set; } public static ITVSeriesManager TVSeriesManager; + /// [JsonIgnore] public string CollectionType => ViewType; + /// public override IEnumerable GetIdsForAncestorQuery() { - var list = new List(); - if (!DisplayParentId.Equals(Guid.Empty)) { - list.Add(DisplayParentId); + yield return DisplayParentId; } else if (!ParentId.Equals(Guid.Empty)) { - list.Add(ParentId); + yield return ParentId; } else { - list.Add(Id); + yield return Id; } - - return list; } [JsonIgnore]