From 7291b8d3e4712c393a8493982895d4a7ce3ca233 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Nov 2015 15:34:34 -0500 Subject: [PATCH 1/3] use DateTime.TryParse --- .../Security/PluginSecurityManager.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index 1176407ce..d4fa74a86 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -178,11 +178,35 @@ namespace MediaBrowser.Common.Implementations.Security Email = response.email, PlanType = response.planType, SupporterKey = response.supporterKey, - ExpirationDate = string.IsNullOrWhiteSpace(response.expDate) ? (DateTime?)null : DateTime.Parse(response.expDate), - RegistrationDate = DateTime.Parse(response.regDate), IsActiveSupporter = IsMBSupporter }; + if (!string.IsNullOrWhiteSpace(response.expDate)) + { + DateTime parsedDate; + if (DateTime.TryParse(response.expDate, out parsedDate)) + { + info.ExpirationDate = parsedDate; + } + else + { + _logger.Error("Failed to parse expDate: {0}", response.expDate); + } + } + + if (!string.IsNullOrWhiteSpace(response.regDate)) + { + DateTime parsedDate; + if (DateTime.TryParse(response.regDate, out parsedDate)) + { + info.RegistrationDate = parsedDate; + } + else + { + _logger.Error("Failed to parse regDate: {0}", response.regDate); + } + } + info.IsExpiredSupporter = info.ExpirationDate.HasValue && info.ExpirationDate < DateTime.UtcNow && !string.IsNullOrWhiteSpace(info.SupporterKey); return info; From ba3f23bad4b3956a3d42bb04d21dc3f24d0384c3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Nov 2015 15:45:10 -0500 Subject: [PATCH 2/3] update logging --- .../Persistence/CleanDatabaseScheduledTask.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs index 60b8c00bd..070c5239e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs @@ -144,7 +144,7 @@ namespace MediaBrowser.Server.Implementations.Persistence if (item != null) { - _logger.Debug("Cleaning item {0} type: {1} path: {2}", item.Name, item.GetType().Name, item.Path ?? string.Empty); + _logger.Info("Cleaning item {0} type: {1} path: {2}", item.Name, item.GetType().Name, item.Path ?? string.Empty); await _libraryManager.DeleteItem(item, new DeleteOptions { @@ -198,6 +198,8 @@ namespace MediaBrowser.Server.Implementations.Persistence continue; } + _logger.Info("Deleting item from database {0} because path no longer exists. type: {1} path: {2}", libraryItem.Name, libraryItem.GetType().Name, libraryItem.Path ?? string.Empty); + await _libraryManager.DeleteItem(libraryItem, new DeleteOptions { DeleteFileLocation = false From 3e5bb74fccf02d5d540cbe4b9132a012ae7530a3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Nov 2015 15:45:19 -0500 Subject: [PATCH 3/3] update i/o methods --- .../Entities/AggregateFolder.cs | 4 ++-- .../Entities/CollectionFolder.cs | 4 ++-- .../Library/ILibraryManager.cs | 2 +- .../Library/LibraryManager.cs | 15 ++++++++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.cs index 14f8c1617..f843b10e4 100644 --- a/MediaBrowser.Controller/Entities/AggregateFolder.cs +++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs @@ -94,9 +94,9 @@ namespace MediaBrowser.Controller.Entities // Example: if \\server\movies exists, then strip out \\server\movies\action if (isPhysicalRoot) { - var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys); + var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Values); - fileSystemDictionary = paths.Select(FileSystem.GetDirectoryInfo).ToDictionary(i => i.FullName); + fileSystemDictionary = paths.ToDictionary(i => i.FullName); } args.FileSystemDictionary = fileSystemDictionary; diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 946d95a0b..0da253186 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -129,9 +129,9 @@ namespace MediaBrowser.Controller.Entities // Example: if \\server\movies exists, then strip out \\server\movies\action if (isPhysicalRoot) { - var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys); + var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Values); - fileSystemDictionary = paths.Select(FileSystem.GetDirectoryInfo).ToDictionary(i => i.FullName); + fileSystemDictionary = paths.ToDictionary(i => i.FullName); } args.FileSystemDictionary = fileSystemDictionary; diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index c7ab88524..2af53efa9 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -298,7 +298,7 @@ namespace MediaBrowser.Controller.Library /// /// The paths. /// IEnumerable{System.String}. - IEnumerable NormalizeRootPathList(IEnumerable paths); + IEnumerable NormalizeRootPathList(IEnumerable paths); /// /// Registers the item. diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 92acd08d1..fd9463e83 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -599,9 +599,9 @@ namespace MediaBrowser.Server.Implementations.Library // Example: if \\server\movies exists, then strip out \\server\movies\action if (isPhysicalRoot) { - var paths = NormalizeRootPathList(fileSystemDictionary.Keys); + var paths = NormalizeRootPathList(fileSystemDictionary.Values); - fileSystemDictionary = paths.Select(_fileSystem.GetDirectoryInfo).ToDictionary(i => i.FullName); + fileSystemDictionary = paths.ToDictionary(i => i.FullName); } args.FileSystemDictionary = fileSystemDictionary; @@ -616,9 +616,12 @@ namespace MediaBrowser.Server.Implementations.Library return ResolveItem(args); } - public IEnumerable NormalizeRootPathList(IEnumerable paths) + public IEnumerable NormalizeRootPathList(IEnumerable paths) { - var list = paths.Select(_fileSystem.NormalizePath) + var originalList = paths.ToList(); + + var list = originalList.Where(i => i.IsDirectory) + .Select(i => _fileSystem.NormalizePath(i.FullName)) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); @@ -630,7 +633,9 @@ namespace MediaBrowser.Server.Implementations.Library _logger.Info("Found duplicate path: {0}", dupe); } - return list.Except(dupes, StringComparer.OrdinalIgnoreCase); + var newList = list.Except(dupes, StringComparer.OrdinalIgnoreCase).Select(_fileSystem.GetDirectoryInfo).ToList(); + newList.AddRange(originalList.Where(i => !i.IsDirectory)); + return newList; } ///