From e3484bdcc204ae39e0bfdf08e758012a048d539c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 17 Dec 2014 17:39:17 -0500 Subject: [PATCH] 3.0.5464.40000 --- .../BaseApplicationHost.cs | 33 ++++++++++--------- .../Logging/NLogger.cs | 13 +++++++- .../Logging/NlogManager.cs | 8 ++++- MediaBrowser.Model/Logging/ILogManager.cs | 6 ++++ .../Sync/SyncJobProcessor.cs | 33 +++++++++++++++---- .../Sync/SyncManager.cs | 2 +- .../Sync/SyncScheduledTask.cs | 2 +- .../ApplicationHost.cs | 19 +++++++++++ MediaBrowser.ServerApplication/MainStartup.cs | 3 +- SharedVersion.cs | 4 +-- 10 files changed, 92 insertions(+), 31 deletions(-) diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 891a03d39..9e14d0ee8 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -294,19 +294,20 @@ namespace MediaBrowser.Common.Implementations public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, bool isStartup) { - if (isStartup) - { - logger.Info("Media Browser Server started"); - } + logger.LogMultiline("Media Browser", LogSeverity.Info, GetBaseExceptionMessage(appPaths)); + } - logger.Info("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs())); + protected static StringBuilder GetBaseExceptionMessage(IApplicationPaths appPaths) + { + var builder = new StringBuilder(); - logger.Info("Server: {0}", Environment.MachineName); - logger.Info("Operating system: {0}", Environment.OSVersion.ToString()); - logger.Info("Processor count: {0}", Environment.ProcessorCount); - logger.Info("64-Bit OS: {0}", Environment.Is64BitOperatingSystem); - logger.Info("64-Bit Process: {0}", Environment.Is64BitProcess); - logger.Info("Program data path: {0}", appPaths.ProgramDataPath); + builder.AppendLine(string.Format("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs()))); + + builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion)); + builder.AppendLine(string.Format("Processor count: {0}", Environment.ProcessorCount)); + builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem)); + builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess)); + builder.AppendLine(string.Format("Program data path: {0}", appPaths.ProgramDataPath)); Type type = Type.GetType("Mono.Runtime"); if (type != null) @@ -314,13 +315,13 @@ namespace MediaBrowser.Common.Implementations MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); if (displayName != null) { - logger.Info("Mono: " + displayName.Invoke(null, null)); + builder.AppendLine("Mono: " + displayName.Invoke(null, null)); } - } - - logger.Info("Application Path: {0}", appPaths.ApplicationPath); + } - logger.Info("*** When reporting issues please include the entire log file. ***".ToUpper()); + builder.AppendLine(string.Format("Application Path: {0}", appPaths.ApplicationPath)); + + return builder; } protected virtual IJsonSerializer CreateJsonSerializer() diff --git a/MediaBrowser.Common.Implementations/Logging/NLogger.cs b/MediaBrowser.Common.Implementations/Logging/NLogger.cs index c87b58f70..29b618890 100644 --- a/MediaBrowser.Common.Implementations/Logging/NLogger.cs +++ b/MediaBrowser.Common.Implementations/Logging/NLogger.cs @@ -14,6 +14,8 @@ namespace MediaBrowser.Common.Implementations.Logging /// private readonly NLog.Logger _logger; + private readonly ILogManager _logManager; + /// /// The _lock object /// @@ -23,8 +25,10 @@ namespace MediaBrowser.Common.Implementations.Logging /// Initializes a new instance of the class. /// /// The name. - public NLogger(string name) + /// The log manager. + public NLogger(string name, ILogManager logManager) { + _logManager = logManager; lock (LockObject) { _logger = NLog.LogManager.GetLogger(name); @@ -96,6 +100,13 @@ namespace MediaBrowser.Common.Implementations.Logging var messageText = LogHelper.GetLogMessage(exception); + var prefix = _logManager.ExceptionMessagePrefix; + + if (!string.IsNullOrWhiteSpace(prefix)) + { + messageText.Insert(0, prefix); + } + LogMultiline(message, level, messageText); } diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index b18c6b95a..77d9f80f9 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -34,6 +34,12 @@ namespace MediaBrowser.Common.Implementations.Logging /// The log file path. public string LogFilePath { get; private set; } + /// + /// Gets or sets the exception message prefix. + /// + /// The exception message prefix. + public string ExceptionMessagePrefix { get; set; } + /// /// Initializes a new instance of the class. /// @@ -159,7 +165,7 @@ namespace MediaBrowser.Common.Implementations.Logging /// ILogger. public ILogger GetLogger(string name) { - return new NLogger(name); + return new NLogger(name, this); } /// diff --git a/MediaBrowser.Model/Logging/ILogManager.cs b/MediaBrowser.Model/Logging/ILogManager.cs index 674d8fd16..59bb86756 100644 --- a/MediaBrowser.Model/Logging/ILogManager.cs +++ b/MediaBrowser.Model/Logging/ILogManager.cs @@ -13,6 +13,12 @@ namespace MediaBrowser.Model.Logging /// The log level. LogSeverity LogSeverity { get; set; } + /// + /// Gets or sets the exception message prefix. + /// + /// The exception message prefix. + string ExceptionMessagePrefix { get; set; } + /// /// Gets the logger. /// diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index e7631069f..6dda869ee 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -48,7 +48,7 @@ namespace MediaBrowser.Server.Implementations.Sync throw new InvalidOperationException("Cannot proceed with sync because user no longer exists."); } - var items = GetItemsForSync(job.RequestedItemIds, user) + var items = GetItemsForSync(job.RequestedItemIds, user, job.UnwatchedOnly) .ToList(); var jobItems = _syncRepo.GetJobItems(new SyncJobItemQuery @@ -171,12 +171,31 @@ namespace MediaBrowser.Server.Implementations.Sync return _syncRepo.Update(job); } - public IEnumerable GetItemsForSync(IEnumerable itemIds, User user) + public IEnumerable GetItemsForSync(IEnumerable itemIds, User user, bool unwatchedOnly) { - return itemIds + var items = itemIds .SelectMany(i => GetItemsForSync(i, user)) - .Where(_syncManager.SupportsSync) - .DistinctBy(i => i.Id); + .Where(_syncManager.SupportsSync); + + if (unwatchedOnly) + { + // Avoid implicitly captured closure + var currentUser = user; + + items = items.Where(i => + { + var video = i as Video; + + if (video != null) + { + return !video.IsPlayed(currentUser); + } + + return true; + }); + } + + return items.DistinctBy(i => i.Id); } private IEnumerable GetItemsForSync(string id, User user) @@ -200,8 +219,8 @@ namespace MediaBrowser.Server.Implementations.Sync .GetRecursiveChildren(user); return itemByName.GetTaggedItems(items); - } - + } + if (item.IsFolder) { var folder = (Folder)item; diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 5c699f010..664ec4038 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -49,7 +49,7 @@ namespace MediaBrowser.Server.Implementations.Sync var user = _userManager.GetUserById(request.UserId); var items = processor - .GetItemsForSync(request.ItemIds, user) + .GetItemsForSync(request.ItemIds, user, request.UnwatchedOnly) .ToList(); if (items.Any(i => !SupportsSync(i))) diff --git a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs index 47bab6e53..df03ab6f7 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs @@ -61,7 +61,7 @@ namespace MediaBrowser.Server.Implementations.Sync public bool IsHidden { - get { return false; } + get { return true; } } public bool IsEnabled diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 0db7893e5..eca600b33 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -251,6 +251,8 @@ namespace MediaBrowser.Server.Startup.Common _remotePackageName = remotePackageName; _supportsNativeWebSocket = supportsNativeWebSocket; NativeApp = nativeApp; + + SetBaseExceptionMessage(); } private Version _version; @@ -307,6 +309,23 @@ namespace MediaBrowser.Server.Startup.Common get { return NativeApp.SupportsAutoRunAtStartup; } } + private void SetBaseExceptionMessage() + { + var builder = GetBaseExceptionMessage(ApplicationPaths); + + // Skip if plugins haven't been loaded yet + //if (Plugins != null) + //{ + // var pluginString = string.Join("|", Plugins.Select(i => i.Name + "-" + i.Version.ToString()).ToArray()); + // builder.Insert(0, string.Format("Plugins: {0}{1}", pluginString, Environment.NewLine)); + //} + + builder.Insert(0, string.Format("Version: {0}{1}", ApplicationVersion, Environment.NewLine)); + builder.Insert(0, "*** Error Report ***" + Environment.NewLine); + + LogManager.ExceptionMessagePrefix = builder.ToString(); + } + /// /// Runs the startup tasks. /// diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index af0219bda..adc8eecb1 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Implementations.Logging; +using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Implementations; using MediaBrowser.Server.Startup.Common; diff --git a/SharedVersion.cs b/SharedVersion.cs index 33a1a70b9..d323dc7bc 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("3.0.*")] -//[assembly: AssemblyVersion("3.0.5463.3000")] +//[assembly: AssemblyVersion("3.0.*")] +[assembly: AssemblyVersion("3.0.5464.40000")]