From bfcd1b520fd79b893e721ba916ae5e1656407d2f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Aug 2017 02:43:41 -0400 Subject: merge common implementations and server implementations --- Emby.Server.Implementations/Logging/NLogger.cs | 224 +++++++++ Emby.Server.Implementations/Logging/NlogManager.cs | 553 +++++++++++++++++++++ 2 files changed, 777 insertions(+) create mode 100644 Emby.Server.Implementations/Logging/NLogger.cs create mode 100644 Emby.Server.Implementations/Logging/NlogManager.cs (limited to 'Emby.Server.Implementations/Logging') diff --git a/Emby.Server.Implementations/Logging/NLogger.cs b/Emby.Server.Implementations/Logging/NLogger.cs new file mode 100644 index 0000000000..c380a640f3 --- /dev/null +++ b/Emby.Server.Implementations/Logging/NLogger.cs @@ -0,0 +1,224 @@ +using System; +using System.Text; +using MediaBrowser.Model.Logging; + +namespace Emby.Server.Implementations.Logging +{ + /// + /// Class NLogger + /// + public class NLogger : ILogger + { + /// + /// The _logger + /// + private readonly NLog.Logger _logger; + + private readonly ILogManager _logManager; + + /// + /// The _lock object + /// + private static readonly object LockObject = new object(); + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// The log manager. + public NLogger(string name, ILogManager logManager) + { + _logManager = logManager; + lock (LockObject) + { + _logger = NLog.LogManager.GetLogger(name); + } + } + + /// + /// Infoes the specified message. + /// + /// The message. + /// The param list. + public void Info(string message, params object[] paramList) + { + _logger.Info(message, paramList); + } + + /// + /// Errors the specified message. + /// + /// The message. + /// The param list. + public void Error(string message, params object[] paramList) + { + _logger.Error(message, paramList); + } + + /// + /// Warns the specified message. + /// + /// The message. + /// The param list. + public void Warn(string message, params object[] paramList) + { + _logger.Warn(message, paramList); + } + + /// + /// Debugs the specified message. + /// + /// The message. + /// The param list. + public void Debug(string message, params object[] paramList) + { + if (_logManager.LogSeverity == LogSeverity.Info) + { + return; + } + + _logger.Debug(message, paramList); + } + + /// + /// Logs the exception. + /// + /// The message. + /// The exception. + /// The param list. + /// + public void ErrorException(string message, Exception exception, params object[] paramList) + { + LogException(LogSeverity.Error, message, exception, paramList); + } + + /// + /// Logs the exception. + /// + /// The level. + /// The message. + /// The exception. + /// The param list. + private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList) + { + message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". "); + + var messageText = LogHelper.GetLogMessage(exception); + + var prefix = _logManager.ExceptionMessagePrefix; + + if (!string.IsNullOrWhiteSpace(prefix)) + { + messageText.Insert(0, prefix); + } + + LogMultiline(message, level, messageText); + } + + /// + /// Formats the message. + /// + /// The message. + /// The param list. + /// System.String. + private static string FormatMessage(string message, params object[] paramList) + { + if (paramList != null) + { + for (var i = 0; i < paramList.Length; i++) + { + var obj = paramList[i]; + + message = message.Replace("{" + i + "}", (obj == null ? "null" : obj.ToString())); + } + } + + return message; + } + + /// + /// Logs the multiline. + /// + /// The message. + /// The severity. + /// Content of the additional. + public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent) + { + if (severity == LogSeverity.Debug && _logManager.LogSeverity == LogSeverity.Info) + { + return; + } + + additionalContent.Insert(0, message + Environment.NewLine); + + const char tabChar = '\t'; + + var text = additionalContent.ToString() + .Replace(Environment.NewLine, Environment.NewLine + tabChar) + .TrimEnd(tabChar); + + if (text.EndsWith(Environment.NewLine)) + { + text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase)); + } + + _logger.Log(GetLogLevel(severity), text); + } + + /// + /// Gets the log level. + /// + /// The severity. + /// NLog.LogLevel. + private NLog.LogLevel GetLogLevel(LogSeverity severity) + { + switch (severity) + { + case LogSeverity.Debug: + return NLog.LogLevel.Debug; + case LogSeverity.Error: + return NLog.LogLevel.Error; + case LogSeverity.Warn: + return NLog.LogLevel.Warn; + case LogSeverity.Fatal: + return NLog.LogLevel.Fatal; + case LogSeverity.Info: + return NLog.LogLevel.Info; + default: + throw new ArgumentException("Unknown LogSeverity: " + severity.ToString()); + } + } + + /// + /// Logs the specified severity. + /// + /// The severity. + /// The message. + /// The param list. + public void Log(LogSeverity severity, string message, params object[] paramList) + { + _logger.Log(GetLogLevel(severity), message, paramList); + } + + /// + /// Fatals the specified message. + /// + /// The message. + /// The param list. + public void Fatal(string message, params object[] paramList) + { + _logger.Fatal(message, paramList); + } + + /// + /// Fatals the exception. + /// + /// The message. + /// The exception. + /// The param list. + public void FatalException(string message, Exception exception, params object[] paramList) + { + LogException(LogSeverity.Fatal, message, exception, paramList); + } + } +} diff --git a/Emby.Server.Implementations/Logging/NlogManager.cs b/Emby.Server.Implementations/Logging/NlogManager.cs new file mode 100644 index 0000000000..77f8d02970 --- /dev/null +++ b/Emby.Server.Implementations/Logging/NlogManager.cs @@ -0,0 +1,553 @@ +using System; +using System.IO; +using System.Linq; +using MediaBrowser.Model.Logging; +using NLog; +using NLog.Config; +using NLog.Filters; +using NLog.Targets; +using NLog.Targets.Wrappers; + +namespace Emby.Server.Implementations.Logging +{ + /// + /// Class NlogManager + /// + public class NlogManager : ILogManager + { + #region Private Fields + + private LogSeverity _severity = LogSeverity.Debug; + + /// + /// Gets or sets the log directory. + /// + /// The log directory. + private readonly string LogDirectory; + + /// + /// Gets or sets the log file prefix. + /// + /// The log file prefix. + private readonly string LogFilePrefix; + + #endregion + + #region Event Declarations + + /// + /// Occurs when [logger loaded]. + /// + public event EventHandler LoggerLoaded; + + #endregion + + #region Public Properties + + /// + /// Gets the log file path. + /// + /// 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; } + + public string NLogConfigurationFilePath { get; set; } + + public LogSeverity LogSeverity + { + + get + { + return _severity; + } + + set + { + DebugFileWriter( + LogDirectory, String.Format( + "SET LogSeverity, _severity = [{0}], value = [{1}]", + _severity.ToString(), + value.ToString() + )); + + var changed = _severity != value; + + _severity = value; + + if (changed) + { + UpdateLogLevel(value); + } + + } + } + + #endregion + + #region Constructor(s) + + /// + /// Initializes a new instance of the class. + /// + /// The log directory. + /// The log file name prefix. + public NlogManager(string logDirectory, string logFileNamePrefix) + { + DebugFileWriter( + logDirectory, String.Format( + "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", + logDirectory, + logFileNamePrefix, + _severity.ToString() + )); + + LogDirectory = logDirectory; + LogFilePrefix = logFileNamePrefix; + + LogManager.Configuration = new LoggingConfiguration(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The log directory. + /// The log file name prefix. + public NlogManager(string logDirectory, string logFileNamePrefix, LogSeverity initialSeverity) : this(logDirectory, logFileNamePrefix) + { + _severity = initialSeverity; + + DebugFileWriter( + logDirectory, String.Format( + "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", + logDirectory, + logFileNamePrefix, + _severity.ToString() + )); + } + + #endregion + + #region Private Methods + + /// + /// Adds the file target. + /// + /// The path. + /// The level. + private void AddFileTarget(string path, LogSeverity level) + { + + DebugFileWriter( + LogDirectory, String.Format( + "AddFileTarget called, path = [{0}], level = [{1}].", + path, + level.ToString() + )); + + RemoveTarget("ApplicationLogFileWrapper"); + + // https://github.com/NLog/NLog/wiki/Performance + var wrapper = new AsyncTargetWrapper + { + OverflowAction = AsyncTargetWrapperOverflowAction.Block, + QueueLimit = 10000, + BatchSize = 500, + TimeToSleepBetweenBatches = 50 + }; + + wrapper.Name = "ApplicationLogFileWrapper"; + + var logFile = new FileTarget + { + FileName = path, + Layout = "${longdate} ${level} ${logger}: ${message}", + KeepFileOpen = true, + ConcurrentWrites = false + }; + + logFile.Name = "ApplicationLogFile"; + + wrapper.WrappedTarget = logFile; + + AddLogTarget(wrapper, level); + + } + + /// + /// Gets the log level. + /// + /// The severity. + /// LogLevel. + /// Unrecognized LogSeverity + private LogLevel GetLogLevel(LogSeverity severity) + { + switch (severity) + { + case LogSeverity.Debug: + return LogLevel.Debug; + case LogSeverity.Error: + return LogLevel.Error; + case LogSeverity.Fatal: + return LogLevel.Fatal; + case LogSeverity.Info: + return LogLevel.Info; + case LogSeverity.Warn: + return LogLevel.Warn; + default: + throw new ArgumentException("Unrecognized LogSeverity"); + } + } + + private void UpdateLogLevel(LogSeverity newLevel) + { + DebugFileWriter( + LogDirectory, String.Format( + "UpdateLogLevel called, newLevel = [{0}].", + newLevel.ToString() + )); + + var level = GetLogLevel(newLevel); + + var rules = LogManager.Configuration.LoggingRules; + + foreach (var rule in rules) + { + if (!rule.IsLoggingEnabledForLevel(level)) + { + rule.EnableLoggingForLevel(level); + } + foreach (var lev in rule.Levels.ToArray()) + { + if (lev < level) + { + rule.DisableLoggingForLevel(lev); + } + } + } + } + + private void AddCustomFilters(string defaultLoggerNamePattern, LoggingRule defaultRule) + { + DebugFileWriter( + LogDirectory, String.Format( + "AddCustomFilters called, defaultLoggerNamePattern = [{0}], defaultRule.LoggerNamePattern = [{1}].", + defaultLoggerNamePattern, + defaultRule.LoggerNamePattern + )); + + try + { + var customConfig = new NLog.Config.XmlLoggingConfiguration(NLogConfigurationFilePath); + + DebugFileWriter( + LogDirectory, String.Format( + "Custom Configuration Loaded, Rule Count = [{0}].", + customConfig.LoggingRules.Count.ToString() + )); + + foreach (var customRule in customConfig.LoggingRules) + { + + DebugFileWriter( + LogDirectory, String.Format( + "Read Custom Rule, LoggerNamePattern = [{0}], Targets = [{1}].", + customRule.LoggerNamePattern, + string.Join(",", customRule.Targets.Select(x => x.Name).ToList()) + )); + + if (customRule.LoggerNamePattern.Equals(defaultLoggerNamePattern)) + { + + if (customRule.Targets.Any((arg) => arg.Name.Equals(defaultRule.Targets.First().Name))) + { + + DebugFileWriter( + LogDirectory, String.Format( + "Custom rule filters can be applied to this target, Filter Count = [{0}].", + customRule.Filters.Count.ToString() + )); + + foreach (ConditionBasedFilter customFilter in customRule.Filters) + { + + DebugFileWriter( + LogDirectory, String.Format( + "Read Custom Filter, Filter = [{0}], Action = [{1}], Type = [{2}].", + customFilter.Condition.ToString(), + customFilter.Action.ToString(), + customFilter.GetType().ToString() + )); + + defaultRule.Filters.Add(customFilter); + + } + } + else + { + + DebugFileWriter( + LogDirectory, String.Format( + "Ignoring custom rule as [Target] does not match." + )); + + } + + } + else + { + + DebugFileWriter( + LogDirectory, String.Format( + "Ignoring custom rule as [LoggerNamePattern] does not match." + )); + + } + } + } + catch (Exception ex) + { + // Intentionally do nothing, prevent issues affecting normal execution. + DebugFileWriter( + LogDirectory, String.Format( + "Exception in AddCustomFilters, ex.Message = [{0}].", + ex.Message + ) + ); + + } + } + + #endregion + + #region Public Methods + + /// + /// Gets the logger. + /// + /// The name. + /// ILogger. + public MediaBrowser.Model.Logging.ILogger GetLogger(string name) + { + + DebugFileWriter( + LogDirectory, String.Format( + "GetLogger called, name = [{0}].", + name + )); + + return new NLogger(name, this); + + } + + /// + /// Adds the log target. + /// + /// The target. + /// The level. + public void AddLogTarget(Target target, LogSeverity level) + { + + DebugFileWriter( + LogDirectory, String.Format( + "AddLogTarget called, target.Name = [{0}], level = [{1}].", + target.Name, + level.ToString() + )); + + string loggerNamePattern = "*"; + var config = LogManager.Configuration; + var rule = new LoggingRule(loggerNamePattern, GetLogLevel(level), target); + + config.AddTarget(target.Name, target); + + AddCustomFilters(loggerNamePattern, rule); + + config.LoggingRules.Add(rule); + + LogManager.Configuration = config; + + } + + /// + /// Removes the target. + /// + /// The name. + public void RemoveTarget(string name) + { + + DebugFileWriter( + LogDirectory, String.Format( + "RemoveTarget called, name = [{0}].", + name + )); + + var config = LogManager.Configuration; + + var target = config.FindTargetByName(name); + + if (target != null) + { + foreach (var rule in config.LoggingRules.ToList()) + { + var contains = rule.Targets.Contains(target); + + rule.Targets.Remove(target); + + if (contains) + { + config.LoggingRules.Remove(rule); + } + } + + config.RemoveTarget(name); + LogManager.Configuration = config; + } + } + + public void AddConsoleOutput() + { + + DebugFileWriter( + LogDirectory, String.Format( + "AddConsoleOutput called." + )); + + RemoveTarget("ConsoleTargetWrapper"); + + var wrapper = new AsyncTargetWrapper(); + wrapper.Name = "ConsoleTargetWrapper"; + + var target = new ConsoleTarget() + { + Layout = "${level}, ${logger}, ${message}", + Error = false + }; + + target.Name = "ConsoleTarget"; + + wrapper.WrappedTarget = target; + + AddLogTarget(wrapper, LogSeverity); + + } + + public void RemoveConsoleOutput() + { + + DebugFileWriter( + LogDirectory, String.Format( + "RemoveConsoleOutput called." + )); + + RemoveTarget("ConsoleTargetWrapper"); + + } + + /// + /// Reloads the logger, maintaining the current log level. + /// + public void ReloadLogger() + { + ReloadLogger(LogSeverity); + } + + /// + /// Reloads the logger, using the specified logging level. + /// + /// The level. + public void ReloadLogger(LogSeverity level) + { + + DebugFileWriter( + LogDirectory, String.Format( + "ReloadLogger called, level = [{0}], LogFilePath (existing) = [{1}].", + level.ToString(), + LogFilePath + )); + + LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Floor(DateTime.Now.Ticks / 10000000) + ".txt"); + + Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath)); + + AddFileTarget(LogFilePath, level); + + LogSeverity = level; + + if (LoggerLoaded != null) + { + try + { + + DebugFileWriter( + LogDirectory, String.Format( + "ReloadLogger called, raised event LoggerLoaded." + )); + + LoggerLoaded(this, EventArgs.Empty); + + } + catch (Exception ex) + { + GetLogger("Logger").ErrorException("Error in LoggerLoaded event", ex); + } + } + } + + /// + /// Flushes this instance. + /// + public void Flush() + { + + DebugFileWriter( + LogDirectory, String.Format( + "Flush called." + )); + + LogManager.Flush(); + + } + + #endregion + + #region Conditional Debug Methods + + /// + /// DEBUG: Standalone method to write out debug to assist with logger development/troubleshooting. + /// + /// The output file will be written to the server's log directory. + /// Calls to the method are safe and will never throw any exceptions. + /// Method calls will be omitted unless the library is compiled with DEBUG defined. + /// + /// + private static void DebugFileWriter(string logDirectory, string message) + { +#if DEBUG + try + { + + System.IO.File.AppendAllText( + Path.Combine(logDirectory, "NlogManager.txt"), + String.Format( + "{0} : {1}{2}", + System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), + message, + System.Environment.NewLine + ) + ); + + } + catch (Exception ex) + { + // Intentionally do nothing, prevent issues affecting normal execution. + } +#endif + } + #endregion + } +} \ No newline at end of file -- cgit v1.2.3 From 56263a9fa26a93bbfa34f673be0e373572ec2fee Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Aug 2017 11:42:36 -0400 Subject: remove unused libs --- Emby.Server.Implementations/ApplicationHost.cs | 3 - .../Emby.Server.Implementations.csproj | 9 +- .../IO/MemoryStreamProvider.cs | 27 - Emby.Server.Implementations/Logging/NLogger.cs | 224 --------- Emby.Server.Implementations/Logging/NlogManager.cs | 553 --------------------- .../Logging/SimpleLogManager.cs | 301 +++++++++++ Emby.Server.Implementations/packages.config | 2 - MediaBrowser.Model/Logging/ILogManager.cs | 6 - .../MediaBrowser.Server.Mono.csproj | 3 - MediaBrowser.Server.Mono/packages.config | 1 - MediaBrowser.ServerApplication/MainStartup.cs | 2 +- .../MediaBrowser.ServerApplication.csproj | 3 - MediaBrowser.ServerApplication/packages.config | 1 - 13 files changed, 303 insertions(+), 832 deletions(-) delete mode 100644 Emby.Server.Implementations/Logging/NLogger.cs delete mode 100644 Emby.Server.Implementations/Logging/NlogManager.cs create mode 100644 Emby.Server.Implementations/Logging/SimpleLogManager.cs (limited to 'Emby.Server.Implementations/Logging') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 318f7d9121..b8506eb867 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1795,9 +1795,6 @@ namespace Emby.Server.Implementations // Include composable parts in the Photos assembly list.Add(GetAssembly(typeof(PhotoProvider))); - // Common implementations - list.Add(GetAssembly(typeof(TaskManager))); - // Emby.Server implementations list.Add(GetAssembly(typeof(InstallationManager))); diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 891d9cfc43..89b9325a25 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -434,8 +434,7 @@ - - + @@ -671,12 +670,6 @@ ..\packages\MediaBrowser.Naming.1.0.5\lib\portable-net45+win8\MediaBrowser.Naming.dll True - - ..\packages\Microsoft.IO.RecyclableMemoryStream.1.2.2\lib\net45\Microsoft.IO.RecyclableMemoryStream.dll - - - ..\packages\NLog.4.4.12\lib\net45\NLog.dll - ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll True diff --git a/Emby.Server.Implementations/IO/MemoryStreamProvider.cs b/Emby.Server.Implementations/IO/MemoryStreamProvider.cs index eca76203c5..e9ecb7e44f 100644 --- a/Emby.Server.Implementations/IO/MemoryStreamProvider.cs +++ b/Emby.Server.Implementations/IO/MemoryStreamProvider.cs @@ -1,35 +1,8 @@ using System.IO; using MediaBrowser.Model.IO; -using Microsoft.IO; namespace Emby.Server.Implementations.IO { - public class RecyclableMemoryStreamProvider : IMemoryStreamFactory - { - readonly RecyclableMemoryStreamManager _manager = new RecyclableMemoryStreamManager(); - - public MemoryStream CreateNew() - { - return _manager.GetStream(); - } - - public MemoryStream CreateNew(int capacity) - { - return _manager.GetStream("RecyclableMemoryStream", capacity); - } - - public MemoryStream CreateNew(byte[] buffer) - { - return _manager.GetStream("RecyclableMemoryStream", buffer, 0, buffer.Length); - } - - public bool TryGetBuffer(MemoryStream stream, out byte[] buffer) - { - buffer = stream.GetBuffer(); - return true; - } - } - public class MemoryStreamProvider : IMemoryStreamFactory { public MemoryStream CreateNew() diff --git a/Emby.Server.Implementations/Logging/NLogger.cs b/Emby.Server.Implementations/Logging/NLogger.cs deleted file mode 100644 index c380a640f3..0000000000 --- a/Emby.Server.Implementations/Logging/NLogger.cs +++ /dev/null @@ -1,224 +0,0 @@ -using System; -using System.Text; -using MediaBrowser.Model.Logging; - -namespace Emby.Server.Implementations.Logging -{ - /// - /// Class NLogger - /// - public class NLogger : ILogger - { - /// - /// The _logger - /// - private readonly NLog.Logger _logger; - - private readonly ILogManager _logManager; - - /// - /// The _lock object - /// - private static readonly object LockObject = new object(); - - /// - /// Initializes a new instance of the class. - /// - /// The name. - /// The log manager. - public NLogger(string name, ILogManager logManager) - { - _logManager = logManager; - lock (LockObject) - { - _logger = NLog.LogManager.GetLogger(name); - } - } - - /// - /// Infoes the specified message. - /// - /// The message. - /// The param list. - public void Info(string message, params object[] paramList) - { - _logger.Info(message, paramList); - } - - /// - /// Errors the specified message. - /// - /// The message. - /// The param list. - public void Error(string message, params object[] paramList) - { - _logger.Error(message, paramList); - } - - /// - /// Warns the specified message. - /// - /// The message. - /// The param list. - public void Warn(string message, params object[] paramList) - { - _logger.Warn(message, paramList); - } - - /// - /// Debugs the specified message. - /// - /// The message. - /// The param list. - public void Debug(string message, params object[] paramList) - { - if (_logManager.LogSeverity == LogSeverity.Info) - { - return; - } - - _logger.Debug(message, paramList); - } - - /// - /// Logs the exception. - /// - /// The message. - /// The exception. - /// The param list. - /// - public void ErrorException(string message, Exception exception, params object[] paramList) - { - LogException(LogSeverity.Error, message, exception, paramList); - } - - /// - /// Logs the exception. - /// - /// The level. - /// The message. - /// The exception. - /// The param list. - private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList) - { - message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". "); - - var messageText = LogHelper.GetLogMessage(exception); - - var prefix = _logManager.ExceptionMessagePrefix; - - if (!string.IsNullOrWhiteSpace(prefix)) - { - messageText.Insert(0, prefix); - } - - LogMultiline(message, level, messageText); - } - - /// - /// Formats the message. - /// - /// The message. - /// The param list. - /// System.String. - private static string FormatMessage(string message, params object[] paramList) - { - if (paramList != null) - { - for (var i = 0; i < paramList.Length; i++) - { - var obj = paramList[i]; - - message = message.Replace("{" + i + "}", (obj == null ? "null" : obj.ToString())); - } - } - - return message; - } - - /// - /// Logs the multiline. - /// - /// The message. - /// The severity. - /// Content of the additional. - public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent) - { - if (severity == LogSeverity.Debug && _logManager.LogSeverity == LogSeverity.Info) - { - return; - } - - additionalContent.Insert(0, message + Environment.NewLine); - - const char tabChar = '\t'; - - var text = additionalContent.ToString() - .Replace(Environment.NewLine, Environment.NewLine + tabChar) - .TrimEnd(tabChar); - - if (text.EndsWith(Environment.NewLine)) - { - text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase)); - } - - _logger.Log(GetLogLevel(severity), text); - } - - /// - /// Gets the log level. - /// - /// The severity. - /// NLog.LogLevel. - private NLog.LogLevel GetLogLevel(LogSeverity severity) - { - switch (severity) - { - case LogSeverity.Debug: - return NLog.LogLevel.Debug; - case LogSeverity.Error: - return NLog.LogLevel.Error; - case LogSeverity.Warn: - return NLog.LogLevel.Warn; - case LogSeverity.Fatal: - return NLog.LogLevel.Fatal; - case LogSeverity.Info: - return NLog.LogLevel.Info; - default: - throw new ArgumentException("Unknown LogSeverity: " + severity.ToString()); - } - } - - /// - /// Logs the specified severity. - /// - /// The severity. - /// The message. - /// The param list. - public void Log(LogSeverity severity, string message, params object[] paramList) - { - _logger.Log(GetLogLevel(severity), message, paramList); - } - - /// - /// Fatals the specified message. - /// - /// The message. - /// The param list. - public void Fatal(string message, params object[] paramList) - { - _logger.Fatal(message, paramList); - } - - /// - /// Fatals the exception. - /// - /// The message. - /// The exception. - /// The param list. - public void FatalException(string message, Exception exception, params object[] paramList) - { - LogException(LogSeverity.Fatal, message, exception, paramList); - } - } -} diff --git a/Emby.Server.Implementations/Logging/NlogManager.cs b/Emby.Server.Implementations/Logging/NlogManager.cs deleted file mode 100644 index 77f8d02970..0000000000 --- a/Emby.Server.Implementations/Logging/NlogManager.cs +++ /dev/null @@ -1,553 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using MediaBrowser.Model.Logging; -using NLog; -using NLog.Config; -using NLog.Filters; -using NLog.Targets; -using NLog.Targets.Wrappers; - -namespace Emby.Server.Implementations.Logging -{ - /// - /// Class NlogManager - /// - public class NlogManager : ILogManager - { - #region Private Fields - - private LogSeverity _severity = LogSeverity.Debug; - - /// - /// Gets or sets the log directory. - /// - /// The log directory. - private readonly string LogDirectory; - - /// - /// Gets or sets the log file prefix. - /// - /// The log file prefix. - private readonly string LogFilePrefix; - - #endregion - - #region Event Declarations - - /// - /// Occurs when [logger loaded]. - /// - public event EventHandler LoggerLoaded; - - #endregion - - #region Public Properties - - /// - /// Gets the log file path. - /// - /// 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; } - - public string NLogConfigurationFilePath { get; set; } - - public LogSeverity LogSeverity - { - - get - { - return _severity; - } - - set - { - DebugFileWriter( - LogDirectory, String.Format( - "SET LogSeverity, _severity = [{0}], value = [{1}]", - _severity.ToString(), - value.ToString() - )); - - var changed = _severity != value; - - _severity = value; - - if (changed) - { - UpdateLogLevel(value); - } - - } - } - - #endregion - - #region Constructor(s) - - /// - /// Initializes a new instance of the class. - /// - /// The log directory. - /// The log file name prefix. - public NlogManager(string logDirectory, string logFileNamePrefix) - { - DebugFileWriter( - logDirectory, String.Format( - "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", - logDirectory, - logFileNamePrefix, - _severity.ToString() - )); - - LogDirectory = logDirectory; - LogFilePrefix = logFileNamePrefix; - - LogManager.Configuration = new LoggingConfiguration(); - } - - /// - /// Initializes a new instance of the class. - /// - /// The log directory. - /// The log file name prefix. - public NlogManager(string logDirectory, string logFileNamePrefix, LogSeverity initialSeverity) : this(logDirectory, logFileNamePrefix) - { - _severity = initialSeverity; - - DebugFileWriter( - logDirectory, String.Format( - "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", - logDirectory, - logFileNamePrefix, - _severity.ToString() - )); - } - - #endregion - - #region Private Methods - - /// - /// Adds the file target. - /// - /// The path. - /// The level. - private void AddFileTarget(string path, LogSeverity level) - { - - DebugFileWriter( - LogDirectory, String.Format( - "AddFileTarget called, path = [{0}], level = [{1}].", - path, - level.ToString() - )); - - RemoveTarget("ApplicationLogFileWrapper"); - - // https://github.com/NLog/NLog/wiki/Performance - var wrapper = new AsyncTargetWrapper - { - OverflowAction = AsyncTargetWrapperOverflowAction.Block, - QueueLimit = 10000, - BatchSize = 500, - TimeToSleepBetweenBatches = 50 - }; - - wrapper.Name = "ApplicationLogFileWrapper"; - - var logFile = new FileTarget - { - FileName = path, - Layout = "${longdate} ${level} ${logger}: ${message}", - KeepFileOpen = true, - ConcurrentWrites = false - }; - - logFile.Name = "ApplicationLogFile"; - - wrapper.WrappedTarget = logFile; - - AddLogTarget(wrapper, level); - - } - - /// - /// Gets the log level. - /// - /// The severity. - /// LogLevel. - /// Unrecognized LogSeverity - private LogLevel GetLogLevel(LogSeverity severity) - { - switch (severity) - { - case LogSeverity.Debug: - return LogLevel.Debug; - case LogSeverity.Error: - return LogLevel.Error; - case LogSeverity.Fatal: - return LogLevel.Fatal; - case LogSeverity.Info: - return LogLevel.Info; - case LogSeverity.Warn: - return LogLevel.Warn; - default: - throw new ArgumentException("Unrecognized LogSeverity"); - } - } - - private void UpdateLogLevel(LogSeverity newLevel) - { - DebugFileWriter( - LogDirectory, String.Format( - "UpdateLogLevel called, newLevel = [{0}].", - newLevel.ToString() - )); - - var level = GetLogLevel(newLevel); - - var rules = LogManager.Configuration.LoggingRules; - - foreach (var rule in rules) - { - if (!rule.IsLoggingEnabledForLevel(level)) - { - rule.EnableLoggingForLevel(level); - } - foreach (var lev in rule.Levels.ToArray()) - { - if (lev < level) - { - rule.DisableLoggingForLevel(lev); - } - } - } - } - - private void AddCustomFilters(string defaultLoggerNamePattern, LoggingRule defaultRule) - { - DebugFileWriter( - LogDirectory, String.Format( - "AddCustomFilters called, defaultLoggerNamePattern = [{0}], defaultRule.LoggerNamePattern = [{1}].", - defaultLoggerNamePattern, - defaultRule.LoggerNamePattern - )); - - try - { - var customConfig = new NLog.Config.XmlLoggingConfiguration(NLogConfigurationFilePath); - - DebugFileWriter( - LogDirectory, String.Format( - "Custom Configuration Loaded, Rule Count = [{0}].", - customConfig.LoggingRules.Count.ToString() - )); - - foreach (var customRule in customConfig.LoggingRules) - { - - DebugFileWriter( - LogDirectory, String.Format( - "Read Custom Rule, LoggerNamePattern = [{0}], Targets = [{1}].", - customRule.LoggerNamePattern, - string.Join(",", customRule.Targets.Select(x => x.Name).ToList()) - )); - - if (customRule.LoggerNamePattern.Equals(defaultLoggerNamePattern)) - { - - if (customRule.Targets.Any((arg) => arg.Name.Equals(defaultRule.Targets.First().Name))) - { - - DebugFileWriter( - LogDirectory, String.Format( - "Custom rule filters can be applied to this target, Filter Count = [{0}].", - customRule.Filters.Count.ToString() - )); - - foreach (ConditionBasedFilter customFilter in customRule.Filters) - { - - DebugFileWriter( - LogDirectory, String.Format( - "Read Custom Filter, Filter = [{0}], Action = [{1}], Type = [{2}].", - customFilter.Condition.ToString(), - customFilter.Action.ToString(), - customFilter.GetType().ToString() - )); - - defaultRule.Filters.Add(customFilter); - - } - } - else - { - - DebugFileWriter( - LogDirectory, String.Format( - "Ignoring custom rule as [Target] does not match." - )); - - } - - } - else - { - - DebugFileWriter( - LogDirectory, String.Format( - "Ignoring custom rule as [LoggerNamePattern] does not match." - )); - - } - } - } - catch (Exception ex) - { - // Intentionally do nothing, prevent issues affecting normal execution. - DebugFileWriter( - LogDirectory, String.Format( - "Exception in AddCustomFilters, ex.Message = [{0}].", - ex.Message - ) - ); - - } - } - - #endregion - - #region Public Methods - - /// - /// Gets the logger. - /// - /// The name. - /// ILogger. - public MediaBrowser.Model.Logging.ILogger GetLogger(string name) - { - - DebugFileWriter( - LogDirectory, String.Format( - "GetLogger called, name = [{0}].", - name - )); - - return new NLogger(name, this); - - } - - /// - /// Adds the log target. - /// - /// The target. - /// The level. - public void AddLogTarget(Target target, LogSeverity level) - { - - DebugFileWriter( - LogDirectory, String.Format( - "AddLogTarget called, target.Name = [{0}], level = [{1}].", - target.Name, - level.ToString() - )); - - string loggerNamePattern = "*"; - var config = LogManager.Configuration; - var rule = new LoggingRule(loggerNamePattern, GetLogLevel(level), target); - - config.AddTarget(target.Name, target); - - AddCustomFilters(loggerNamePattern, rule); - - config.LoggingRules.Add(rule); - - LogManager.Configuration = config; - - } - - /// - /// Removes the target. - /// - /// The name. - public void RemoveTarget(string name) - { - - DebugFileWriter( - LogDirectory, String.Format( - "RemoveTarget called, name = [{0}].", - name - )); - - var config = LogManager.Configuration; - - var target = config.FindTargetByName(name); - - if (target != null) - { - foreach (var rule in config.LoggingRules.ToList()) - { - var contains = rule.Targets.Contains(target); - - rule.Targets.Remove(target); - - if (contains) - { - config.LoggingRules.Remove(rule); - } - } - - config.RemoveTarget(name); - LogManager.Configuration = config; - } - } - - public void AddConsoleOutput() - { - - DebugFileWriter( - LogDirectory, String.Format( - "AddConsoleOutput called." - )); - - RemoveTarget("ConsoleTargetWrapper"); - - var wrapper = new AsyncTargetWrapper(); - wrapper.Name = "ConsoleTargetWrapper"; - - var target = new ConsoleTarget() - { - Layout = "${level}, ${logger}, ${message}", - Error = false - }; - - target.Name = "ConsoleTarget"; - - wrapper.WrappedTarget = target; - - AddLogTarget(wrapper, LogSeverity); - - } - - public void RemoveConsoleOutput() - { - - DebugFileWriter( - LogDirectory, String.Format( - "RemoveConsoleOutput called." - )); - - RemoveTarget("ConsoleTargetWrapper"); - - } - - /// - /// Reloads the logger, maintaining the current log level. - /// - public void ReloadLogger() - { - ReloadLogger(LogSeverity); - } - - /// - /// Reloads the logger, using the specified logging level. - /// - /// The level. - public void ReloadLogger(LogSeverity level) - { - - DebugFileWriter( - LogDirectory, String.Format( - "ReloadLogger called, level = [{0}], LogFilePath (existing) = [{1}].", - level.ToString(), - LogFilePath - )); - - LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Floor(DateTime.Now.Ticks / 10000000) + ".txt"); - - Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath)); - - AddFileTarget(LogFilePath, level); - - LogSeverity = level; - - if (LoggerLoaded != null) - { - try - { - - DebugFileWriter( - LogDirectory, String.Format( - "ReloadLogger called, raised event LoggerLoaded." - )); - - LoggerLoaded(this, EventArgs.Empty); - - } - catch (Exception ex) - { - GetLogger("Logger").ErrorException("Error in LoggerLoaded event", ex); - } - } - } - - /// - /// Flushes this instance. - /// - public void Flush() - { - - DebugFileWriter( - LogDirectory, String.Format( - "Flush called." - )); - - LogManager.Flush(); - - } - - #endregion - - #region Conditional Debug Methods - - /// - /// DEBUG: Standalone method to write out debug to assist with logger development/troubleshooting. - /// - /// The output file will be written to the server's log directory. - /// Calls to the method are safe and will never throw any exceptions. - /// Method calls will be omitted unless the library is compiled with DEBUG defined. - /// - /// - private static void DebugFileWriter(string logDirectory, string message) - { -#if DEBUG - try - { - - System.IO.File.AppendAllText( - Path.Combine(logDirectory, "NlogManager.txt"), - String.Format( - "{0} : {1}{2}", - System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), - message, - System.Environment.NewLine - ) - ); - - } - catch (Exception ex) - { - // Intentionally do nothing, prevent issues affecting normal execution. - } -#endif - } - #endregion - } -} \ No newline at end of file diff --git a/Emby.Server.Implementations/Logging/SimpleLogManager.cs b/Emby.Server.Implementations/Logging/SimpleLogManager.cs new file mode 100644 index 0000000000..1a50f162a1 --- /dev/null +++ b/Emby.Server.Implementations/Logging/SimpleLogManager.cs @@ -0,0 +1,301 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Model.Logging; + +namespace Emby.Server.Implementations.Logging +{ + public class SimpleLogManager : ILogManager, IDisposable + { + public LogSeverity LogSeverity { get; set; } + public string ExceptionMessagePrefix { get; set; } + private FileLogger _fileLogger; + + private readonly string LogDirectory; + private readonly string LogFilePrefix; + public string DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff"; + + public SimpleLogManager(string logDirectory, string logFileNamePrefix) + { + LogDirectory = logDirectory; + LogFilePrefix = logFileNamePrefix; + } + + public ILogger GetLogger(string name) + { + return new NamedLogger(name, this); + } + + public void ReloadLogger(LogSeverity severity) + { + LogSeverity = severity; + + var logger = _fileLogger; + if (logger != null) + { + logger.Dispose(); + } + + var path = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Floor(DateTime.Now.Ticks / 10000000) + ".txt"); + + _fileLogger = new FileLogger(path); + + if (LoggerLoaded != null) + { + try + { + + LoggerLoaded(this, EventArgs.Empty); + + } + catch (Exception ex) + { + GetLogger("Logger").ErrorException("Error in LoggerLoaded event", ex); + } + } + } + + public event EventHandler LoggerLoaded; + + public void Flush() + { + var logger = _fileLogger; + if (logger != null) + { + logger.Flush(); + } + } + + private bool _console = true; + public void AddConsoleOutput() + { + _console = true; + } + + public void RemoveConsoleOutput() + { + _console = false; + } + + public void Log(string message) + { + if (_console) + { + Console.WriteLine(message); + } + + var logger = _fileLogger; + if (logger != null) + { + message = DateTime.Now.ToString(DateTimeFormat) + " " + message; + + logger.Log(message); + } + } + + public void Dispose() + { + var logger = _fileLogger; + if (logger != null) + { + logger.Dispose(); + } + + _fileLogger = null; + } + } + + public class FileLogger : IDisposable + { + private readonly Stream _fileStream; + + private bool _disposed; + private readonly CancellationTokenSource _cancellationTokenSource; + private readonly BlockingCollection _queue = new BlockingCollection(); + + public FileLogger(string path) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + _fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read); + _cancellationTokenSource = new CancellationTokenSource(); + + Task.Factory.StartNew(LogInternal, _cancellationTokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); + } + + private void LogInternal() + { + while (!_cancellationTokenSource.IsCancellationRequested) + { + try + { + var any = false; + + foreach (var message in _queue.GetConsumingEnumerable()) + { + any = true; + + var bytes = Encoding.UTF8.GetBytes(message + Environment.NewLine); + _fileStream.Write(bytes, 0, bytes.Length); + } + + if (any) + { + _fileStream.Flush(); + } + } + catch + { + + } + } + } + + public void Log(string message) + { + if (_disposed) + { + return; + } + + _queue.Add(message); + } + + public void Flush() + { + if (_disposed) + { + return; + } + + _fileStream.Flush(); + } + + public void Dispose() + { + _cancellationTokenSource.Cancel(); + + _disposed = true; + + _fileStream.Flush(); + _fileStream.Dispose(); + } + } + + public class NamedLogger : ILogger + { + public string Name { get; private set; } + private readonly SimpleLogManager _logManager; + + public NamedLogger(string name, SimpleLogManager logManager) + { + Name = name; + _logManager = logManager; + } + + public void Info(string message, params object[] paramList) + { + Log(LogSeverity.Info, message, paramList); + } + + public void Error(string message, params object[] paramList) + { + Log(LogSeverity.Error, message, paramList); + } + + public void Warn(string message, params object[] paramList) + { + Log(LogSeverity.Warn, message, paramList); + } + + public void Debug(string message, params object[] paramList) + { + if (_logManager.LogSeverity == LogSeverity.Info) + { + return; + } + Log(LogSeverity.Debug, message, paramList); + } + + public void Fatal(string message, params object[] paramList) + { + Log(LogSeverity.Fatal, message, paramList); + } + + public void FatalException(string message, Exception exception, params object[] paramList) + { + ErrorException(message, exception, paramList); + } + + public void ErrorException(string message, Exception exception, params object[] paramList) + { + LogException(LogSeverity.Error, message, exception, paramList); + } + + private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList) + { + message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". "); + + var messageText = LogHelper.GetLogMessage(exception); + + var prefix = _logManager.ExceptionMessagePrefix; + + if (!string.IsNullOrWhiteSpace(prefix)) + { + messageText.Insert(0, prefix); + } + + LogMultiline(message, level, messageText); + } + + private static string FormatMessage(string message, params object[] paramList) + { + if (paramList != null) + { + for (var i = 0; i < paramList.Length; i++) + { + var obj = paramList[i]; + + message = message.Replace("{" + i + "}", (obj == null ? "null" : obj.ToString())); + } + } + + return message; + } + + public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent) + { + if (severity == LogSeverity.Debug && _logManager.LogSeverity == LogSeverity.Info) + { + return; + } + + additionalContent.Insert(0, message + Environment.NewLine); + + const char tabChar = '\t'; + + var text = additionalContent.ToString() + .Replace(Environment.NewLine, Environment.NewLine + tabChar) + .TrimEnd(tabChar); + + if (text.EndsWith(Environment.NewLine)) + { + text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase)); + } + + Log(severity, text); + } + + public void Log(LogSeverity severity, string message, params object[] paramList) + { + message = severity + " " + Name + ": " + FormatMessage(message, paramList); + + _logManager.Log(message); + } + } +} diff --git a/Emby.Server.Implementations/packages.config b/Emby.Server.Implementations/packages.config index fc28b26539..0933cd5e43 100644 --- a/Emby.Server.Implementations/packages.config +++ b/Emby.Server.Implementations/packages.config @@ -2,8 +2,6 @@ - - diff --git a/MediaBrowser.Model/Logging/ILogManager.cs b/MediaBrowser.Model/Logging/ILogManager.cs index 59bb867563..218f13eb4b 100644 --- a/MediaBrowser.Model/Logging/ILogManager.cs +++ b/MediaBrowser.Model/Logging/ILogManager.cs @@ -31,12 +31,6 @@ namespace MediaBrowser.Model.Logging /// void ReloadLogger(LogSeverity severity); - /// - /// Gets the log file path. - /// - /// The log file path. - string LogFilePath { get; } - /// /// Occurs when [logger loaded]. /// diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index bb113bf03a..a0b1d526a2 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -51,9 +51,6 @@ False ..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll - - ..\packages\NLog.4.4.12\lib\net45\NLog.dll - ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll True diff --git a/MediaBrowser.Server.Mono/packages.config b/MediaBrowser.Server.Mono/packages.config index c77327e228..525a0098c8 100644 --- a/MediaBrowser.Server.Mono/packages.config +++ b/MediaBrowser.Server.Mono/packages.config @@ -1,7 +1,6 @@  - diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 7f72473ea5..169ac2eefe 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -73,7 +73,7 @@ namespace MediaBrowser.ServerApplication var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); - var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); + var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 41015a98b7..cb7c92a886 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -73,9 +73,6 @@ ..\ThirdParty\emby\Emby.Server.Sync.dll - - ..\packages\NLog.4.4.12\lib\net45\NLog.dll - ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll True diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config index ed953e299a..3af1bcf4d8 100644 --- a/MediaBrowser.ServerApplication/packages.config +++ b/MediaBrowser.ServerApplication/packages.config @@ -1,6 +1,5 @@  - -- cgit v1.2.3 From a7dcf7191a71bfefd4a8c69d24d2eec53973bb83 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 17 Aug 2017 16:19:02 -0400 Subject: add fixes for .net core --- .../AppBase/BaseApplicationPaths.cs | 9 ++-- Emby.Server.Implementations/ApplicationHost.cs | 56 +++++++++++----------- .../Cryptography/CertificateGenerator.cs | 42 +++++++++++++++- .../EnvironmentInfo/EnvironmentInfo.cs | 20 +++++--- .../HttpClientManager/HttpClientManager.cs | 10 ++-- Emby.Server.Implementations/Library/UserManager.cs | 6 +-- .../Logging/SimpleLogManager.cs | 4 +- Emby.Server.Implementations/Net/SocketFactory.cs | 23 ++++++--- .../ServerApplicationPaths.cs | 4 +- MediaBrowser.Model/Session/PlaybackProgressInfo.cs | 2 +- MediaBrowser.Server.Mono/MonoAppHost.cs | 2 +- MediaBrowser.Server.Mono/Program.cs | 49 +++++-------------- .../ImageEncoderHelper.cs | 1 - MediaBrowser.ServerApplication/MainStartup.cs | 16 ++----- .../MediaBrowser.ServerApplication.csproj | 4 -- MediaBrowser.ServerApplication/WindowsAppHost.cs | 4 +- 16 files changed, 132 insertions(+), 120 deletions(-) (limited to 'Emby.Server.Implementations/Logging') diff --git a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs index 54d1d53023..1e63aa1a6d 100644 --- a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs +++ b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs @@ -13,15 +13,12 @@ namespace Emby.Server.Implementations.AppBase /// /// Initializes a new instance of the class. /// - protected BaseApplicationPaths(string programDataPath, string appFolderPath, Action createDirectoryFn) + protected BaseApplicationPaths(string programDataPath, string appFolderPath) { ProgramDataPath = programDataPath; ProgramSystemPath = appFolderPath; - CreateDirectoryFn = createDirectoryFn; } - protected Action CreateDirectoryFn; - public string ProgramDataPath { get; private set; } /// @@ -45,7 +42,7 @@ namespace Emby.Server.Implementations.AppBase { _dataDirectory = Path.Combine(ProgramDataPath, "data"); - CreateDirectoryFn(_dataDirectory); + Directory.CreateDirectory(_dataDirectory); } return _dataDirectory; @@ -152,7 +149,7 @@ namespace Emby.Server.Implementations.AppBase { _cachePath = Path.Combine(ProgramDataPath, "cache"); - CreateDirectoryFn(_cachePath); + Directory.CreateDirectory(_cachePath); } return _cachePath; diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 3ad8fe7df9..bc88d652c4 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -111,6 +111,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Threading.Tasks; +using Emby.Server.Core.Cryptography; using Emby.Server.Implementations.Archiving; using Emby.Server.Implementations.Cryptography; using Emby.Server.Implementations.Diagnostics; @@ -368,8 +369,6 @@ namespace Emby.Server.Implementations internal IPowerManagement PowerManagement { get; private set; } internal IImageEncoder ImageEncoder { get; private set; } - private readonly Action _certificateGenerator; - private readonly Func _defaultUserNameFactory; protected IProcessFactory ProcessFactory { get; private set; } protected ITimerFactory TimerFactory { get; private set; } protected ICryptoProvider CryptographyProvider = new CryptographyProvider(); @@ -394,10 +393,7 @@ namespace Emby.Server.Implementations IEnvironmentInfo environmentInfo, IImageEncoder imageEncoder, ISystemEvents systemEvents, - IMemoryStreamFactory memoryStreamFactory, - INetworkManager networkManager, - Action certificateGenerator, - Func defaultUsernameFactory) + INetworkManager networkManager) { // hack alert, until common can target .net core BaseExtensions.CryptographyProvider = CryptographyProvider; @@ -407,7 +403,7 @@ namespace Emby.Server.Implementations NetworkManager = networkManager; EnvironmentInfo = environmentInfo; SystemEvents = systemEvents; - MemoryStreamFactory = memoryStreamFactory; + MemoryStreamFactory = new MemoryStreamProvider(); FailedAssemblies = new List(); @@ -421,9 +417,7 @@ namespace Emby.Server.Implementations Logger = LogManager.GetLogger("App"); StartupOptions = options; - _certificateGenerator = certificateGenerator; _releaseAssetFilename = releaseAssetFilename; - _defaultUserNameFactory = defaultUsernameFactory; PowerManagement = powerManagement; ImageEncoder = imageEncoder; @@ -917,7 +911,7 @@ namespace Emby.Server.Implementations AuthenticationRepository = GetAuthenticationRepository(); RegisterSingleInstance(AuthenticationRepository); - UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, CryptographyProvider, _defaultUserNameFactory()); + UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, CryptographyProvider); RegisterSingleInstance(UserManager); LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager); @@ -1257,7 +1251,7 @@ namespace Emby.Server.Implementations case MediaBrowser.Model.System.Architecture.X64: return new[] { - "https://embydata.com/downloads/ffmpeg/osx/ffmpeg-x64-20170308.7z" + "https://embydata.com/downloads/ffmpeg/osx/ffmpeg-x64-20170308.7z" }; } @@ -1271,12 +1265,12 @@ namespace Emby.Server.Implementations case MediaBrowser.Model.System.Architecture.X64: return new[] { - "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win64.7z" + "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win64.7z" }; case MediaBrowser.Model.System.Architecture.X86: return new[] { - "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win32.7z" + "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win32.7z" }; } @@ -1290,12 +1284,12 @@ namespace Emby.Server.Implementations case MediaBrowser.Model.System.Architecture.X64: return new[] { - "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-64bit-static.7z" + "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-64bit-static.7z" }; case MediaBrowser.Model.System.Architecture.X86: return new[] { - "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-32bit-static.7z" + "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-32bit-static.7z" }; } @@ -1442,17 +1436,17 @@ namespace Emby.Server.Implementations StartServer(); LibraryManager.AddParts(GetExports(), - GetExports(), - GetExports(), - GetExports(), - GetExports(), - GetExports()); + GetExports(), + GetExports(), + GetExports(), + GetExports(), + GetExports()); ProviderManager.AddParts(GetExports(), - GetExports(), - GetExports(), - GetExports(), - GetExports()); + GetExports(), + GetExports(), + GetExports(), + GetExports()); ImageProcessor.AddParts(GetExports()); @@ -1652,7 +1646,7 @@ namespace Emby.Server.Implementations try { - _certificateGenerator(certPath, certHost, password); + CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, password, Logger); } catch (Exception ex) { @@ -2158,7 +2152,7 @@ namespace Emby.Server.Implementations list.Remove(plugin); Plugins = list.ToArray(); } - + /// /// Checks for update. /// @@ -2176,7 +2170,7 @@ namespace Emby.Server.Implementations } var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename, - "MBServer", "Mbserver.zip", cacheLength, cancellationToken).ConfigureAwait(false); + "MBServer", "Mbserver.zip", cacheLength, cancellationToken).ConfigureAwait(false); HasUpdateAvailable = result.IsUpdateAvailable; @@ -2314,12 +2308,18 @@ namespace Emby.Server.Implementations NotifyPendingRestart(); } + private bool _disposed; /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// public void Dispose() { - Dispose(true); + if (!_disposed) + { + _disposed = true; + + Dispose(true); + } } /// diff --git a/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs b/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs index 2600d74702..b4c84a6003 100644 --- a/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs +++ b/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Security.Cryptography; +using System.Xml; namespace Emby.Server.Core.Cryptography { @@ -27,7 +28,11 @@ namespace Emby.Server.Core.Cryptography DateTime notAfter = DateTime.Now.AddYears(10); RSA issuerKey = RSA.Create(); +#if NET46 issuerKey.FromXmlString(MonoTestRootAgency); +#else + RSACryptoServiceProviderExtensions.FromXmlString(issuerKey, MonoTestRootAgency); +#endif RSA subjectKey = RSA.Create(); // serial number MUST be positive @@ -44,7 +49,7 @@ namespace Emby.Server.Core.Cryptography cb.NotAfter = notAfter; cb.SubjectName = subject; cb.SubjectPublicKey = subjectKey; - + // signature cb.Hash = "SHA256"; byte[] rawcert = cb.Sign(issuerKey); @@ -66,4 +71,39 @@ namespace Emby.Server.Core.Cryptography p12.SaveToFile(fileName); } } + + public static class RSACryptoServiceProviderExtensions + { + public static void FromXmlString(RSA rsa, string xmlString) + { + RSAParameters parameters = new RSAParameters(); + + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xmlString); + + if (xmlDoc.DocumentElement.Name.Equals("RSAKeyValue")) + { + foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) + { + switch (node.Name) + { + case "Modulus": parameters.Modulus = Convert.FromBase64String(node.InnerText); break; + case "Exponent": parameters.Exponent = Convert.FromBase64String(node.InnerText); break; + case "P": parameters.P = Convert.FromBase64String(node.InnerText); break; + case "Q": parameters.Q = Convert.FromBase64String(node.InnerText); break; + case "DP": parameters.DP = Convert.FromBase64String(node.InnerText); break; + case "DQ": parameters.DQ = Convert.FromBase64String(node.InnerText); break; + case "InverseQ": parameters.InverseQ = Convert.FromBase64String(node.InnerText); break; + case "D": parameters.D = Convert.FromBase64String(node.InnerText); break; + } + } + } + else + { + throw new Exception("Invalid XML RSA key."); + } + + rsa.ImportParameters(parameters); + } + } } diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs index 0999fa1418..f86279f372 100644 --- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -6,16 +6,16 @@ namespace Emby.Server.Implementations.EnvironmentInfo { public class EnvironmentInfo : IEnvironmentInfo { - public Architecture? CustomArchitecture { get; set; } - public MediaBrowser.Model.System.OperatingSystem? CustomOperatingSystem { get; set; } + private Architecture? _customArchitecture; + private MediaBrowser.Model.System.OperatingSystem? _customOperatingSystem; public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem { get { - if (CustomOperatingSystem.HasValue) + if (_customOperatingSystem.HasValue) { - return CustomOperatingSystem.Value; + return _customOperatingSystem.Value; } switch (Environment.OSVersion.Platform) @@ -30,6 +30,10 @@ namespace Emby.Server.Implementations.EnvironmentInfo return MediaBrowser.Model.System.OperatingSystem.Windows; } + set + { + _customOperatingSystem = value; + } } public string OperatingSystemName @@ -60,13 +64,17 @@ namespace Emby.Server.Implementations.EnvironmentInfo { get { - if (CustomArchitecture.HasValue) + if (_customArchitecture.HasValue) { - return CustomArchitecture.Value; + return _customArchitecture.Value; } return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86; } + set + { + _customArchitecture = value; + } } public string GetEnvironmentVariable(string name) diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index 1017953ba7..f512b723d8 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -66,8 +66,10 @@ namespace Emby.Server.Implementations.HttpClientManager // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c ServicePointManager.Expect100Continue = false; - // Trakt requests sometimes fail without this +#if NET46 +// Trakt requests sometimes fail without this ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls; +#endif } /// @@ -428,7 +430,7 @@ namespace Emby.Server.Implementations.HttpClientManager try { var bytes = options.RequestContentBytes ?? - Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty); + Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty); httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded"; @@ -727,7 +729,7 @@ namespace Emby.Server.Implementations.HttpClientManager } var webException = ex as WebException - ?? ex.InnerException as WebException; + ?? ex.InnerException as WebException; if (webException != null) { @@ -762,7 +764,7 @@ namespace Emby.Server.Implementations.HttpClientManager } var operationCanceledException = ex as OperationCanceledException - ?? ex.InnerException as OperationCanceledException; + ?? ex.InnerException as OperationCanceledException; if (operationCanceledException != null) { diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs index 019b8162af..211c54ceea 100644 --- a/Emby.Server.Implementations/Library/UserManager.cs +++ b/Emby.Server.Implementations/Library/UserManager.cs @@ -71,9 +71,8 @@ namespace Emby.Server.Implementations.Library private readonly IServerApplicationHost _appHost; private readonly IFileSystem _fileSystem; private readonly ICryptoProvider _cryptographyProvider; - private readonly string _defaultUserName; - public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func imageProcessorFactory, Func dtoServiceFactory, Func connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ICryptoProvider cryptographyProvider, string defaultUserName) + public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func imageProcessorFactory, Func dtoServiceFactory, Func connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ICryptoProvider cryptographyProvider) { _logger = logger; UserRepository = userRepository; @@ -86,7 +85,6 @@ namespace Emby.Server.Implementations.Library _jsonSerializer = jsonSerializer; _fileSystem = fileSystem; _cryptographyProvider = cryptographyProvider; - _defaultUserName = defaultUserName; ConfigurationManager = configurationManager; Users = new List(); @@ -381,7 +379,7 @@ namespace Emby.Server.Implementations.Library // There always has to be at least one user. if (users.Count == 0) { - var name = MakeValidUsername(_defaultUserName); + var name = MakeValidUsername(Environment.UserName); var user = InstantiateNewUser(name); diff --git a/Emby.Server.Implementations/Logging/SimpleLogManager.cs b/Emby.Server.Implementations/Logging/SimpleLogManager.cs index 1a50f162a1..5c83766fe8 100644 --- a/Emby.Server.Implementations/Logging/SimpleLogManager.cs +++ b/Emby.Server.Implementations/Logging/SimpleLogManager.cs @@ -138,10 +138,10 @@ namespace Emby.Server.Implementations.Logging foreach (var message in _queue.GetConsumingEnumerable()) { - any = true; - var bytes = Encoding.UTF8.GetBytes(message + Environment.NewLine); _fileStream.Write(bytes, 0, bytes.Length); + + any = true; } if (any) diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.cs index ab3bd0b315..f78fbdfd72 100644 --- a/Emby.Server.Implementations/Net/SocketFactory.cs +++ b/Emby.Server.Implementations/Net/SocketFactory.cs @@ -69,8 +69,8 @@ namespace Emby.Server.Implementations.Net if (remotePort < 0) throw new ArgumentException("remotePort cannot be less than zero.", "remotePort"); var addressFamily = remoteAddress.AddressFamily == IpAddressFamily.InterNetwork - ? AddressFamily.InterNetwork - : AddressFamily.InterNetworkV6; + ? AddressFamily.InterNetwork + : AddressFamily.InterNetworkV6; var retVal = new Socket(addressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp); @@ -82,7 +82,7 @@ namespace Emby.Server.Implementations.Net { // This is not supported on all operating systems (qnap) } - + try { return new UdpSocket(retVal, new IpEndPointInfo(remoteAddress, remotePort)); @@ -139,11 +139,11 @@ namespace Emby.Server.Implementations.Net throw; } } - + /// - /// Creates a new UDP acceptSocket that is a member of the SSDP multicast local admin group and binds it to the specified local port. - /// - /// An implementation of the interface used by RSSDP components to perform acceptSocket operations. + /// Creates a new UDP acceptSocket that is a member of the SSDP multicast local admin group and binds it to the specified local port. + /// + /// An implementation of the interface used by RSSDP components to perform acceptSocket operations. public ISocket CreateSsdpUdpSocket(IpAddressInfo localIpAddress, int localPort) { if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort"); @@ -186,7 +186,16 @@ namespace Emby.Server.Implementations.Net try { + // not supported on all platforms. throws on ubuntu with .net core 2.0 retVal.ExclusiveAddressUse = false; + } + catch (SocketException) + { + + } + + try + { //retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive); diff --git a/Emby.Server.Implementations/ServerApplicationPaths.cs b/Emby.Server.Implementations/ServerApplicationPaths.cs index b4b2bb139e..675b0d78cd 100644 --- a/Emby.Server.Implementations/ServerApplicationPaths.cs +++ b/Emby.Server.Implementations/ServerApplicationPaths.cs @@ -13,8 +13,8 @@ namespace Emby.Server.Implementations /// /// Initializes a new instance of the class. /// - public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath, Action createDirectoryFn) - : base(programDataPath, appFolderPath, createDirectoryFn) + public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath) + : base(programDataPath, appFolderPath) { ApplicationResourcesPath = applicationResourcesPath; } diff --git a/MediaBrowser.Model/Session/PlaybackProgressInfo.cs b/MediaBrowser.Model/Session/PlaybackProgressInfo.cs index 5f81f7269a..0319f67117 100644 --- a/MediaBrowser.Model/Session/PlaybackProgressInfo.cs +++ b/MediaBrowser.Model/Session/PlaybackProgressInfo.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Model.Session /// The position ticks. public long? PositionTicks { get; set; } - public long? playbackStartTimeTicks { get; set; } + public long? PlaybackStartTimeTicks { get; set; } /// /// Gets or sets the volume level. diff --git a/MediaBrowser.Server.Mono/MonoAppHost.cs b/MediaBrowser.Server.Mono/MonoAppHost.cs index 1153d0f7db..e51324ec4d 100644 --- a/MediaBrowser.Server.Mono/MonoAppHost.cs +++ b/MediaBrowser.Server.Mono/MonoAppHost.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Server.Mono { public class MonoAppHost : ApplicationHost { - public MonoAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action certificateGenerator, Func defaultUsernameFactory) : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory) + public MonoAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager) : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, networkManager) { } diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index c50f97fc12..73a568ca97 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -21,7 +21,6 @@ using Emby.Server.Implementations.Networking; using MediaBrowser.Model.IO; using MediaBrowser.Model.System; using Mono.Unix.Native; -using NLog; using ILogger = MediaBrowser.Model.Logging.ILogger; using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certificate; @@ -48,7 +47,7 @@ namespace MediaBrowser.Server.Mono var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath); - var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); + var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Info); logManager.AddConsoleOutput(); @@ -84,9 +83,7 @@ namespace MediaBrowser.Server.Mono var appFolderPath = Path.GetDirectoryName(applicationPath); - Action createDirectoryFn = s => Directory.CreateDirectory(s); - - return new ServerApplicationPaths(programDataPath, appFolderPath, Path.GetDirectoryName(applicationPath), createDirectoryFn); + return new ServerApplicationPaths(programDataPath, appFolderPath, Path.GetDirectoryName(applicationPath)); } private static readonly TaskCompletionSource ApplicationTaskCompletionSource = new TaskCompletionSource(); @@ -113,10 +110,7 @@ namespace MediaBrowser.Server.Mono environmentInfo, imageEncoder, new SystemEvents(logManager.GetLogger("SystemEvents")), - new MemoryStreamProvider(), - new NetworkManager(logManager.GetLogger("NetworkManager")), - GenerateCertificate, - () => Environment.UserName); + new NetworkManager(logManager.GetLogger("NetworkManager"))); if (options.ContainsOption("-v")) { @@ -141,11 +135,6 @@ namespace MediaBrowser.Server.Mono Task.WaitAll(task); } - private static void GenerateCertificate(string certPath, string certHost, string certPassword) - { - CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, certPassword, _logger); - } - private static MonoEnvironmentInfo GetEnvironmentInfo() { var info = new MonoEnvironmentInfo(); @@ -156,39 +145,38 @@ namespace MediaBrowser.Server.Mono if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase)) { - //info.OperatingSystem = Startup.Common.OperatingSystem.Osx; + info.OperatingSystem = Model.System.OperatingSystem.OSX; } else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase)) { - //info.OperatingSystem = Startup.Common.OperatingSystem.Linux; + info.OperatingSystem = Model.System.OperatingSystem.Linux; } else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase)) { - //info.OperatingSystem = Startup.Common.OperatingSystem.Bsd; - info.IsBsd = true; + info.OperatingSystem = Model.System.OperatingSystem.BSD; } var archX86 = new Regex("(i|I)[3-6]86"); if (archX86.IsMatch(uname.machine)) { - info.CustomArchitecture = Architecture.X86; + info.SystemArchitecture = Architecture.X86; } else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase)) { - info.CustomArchitecture = Architecture.X64; + info.SystemArchitecture = Architecture.X64; } else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase)) { - info.CustomArchitecture = Architecture.Arm; + info.SystemArchitecture = Architecture.Arm; } else if (System.Environment.Is64BitOperatingSystem) { - info.CustomArchitecture = Architecture.X64; + info.SystemArchitecture = Architecture.X64; } else { - info.CustomArchitecture = Architecture.X86; + info.SystemArchitecture = Architecture.X86; } return info; @@ -308,24 +296,9 @@ namespace MediaBrowser.Server.Mono public class MonoEnvironmentInfo : EnvironmentInfo { - public bool IsBsd { get; set; } - public override string GetUserId() { return Syscall.getuid().ToString(CultureInfo.InvariantCulture); } - - public override Model.System.OperatingSystem OperatingSystem - { - get - { - if (IsBsd) - { - return Model.System.OperatingSystem.BSD; - } - - return base.OperatingSystem; - } - } } } diff --git a/MediaBrowser.ServerApplication/ImageEncoderHelper.cs b/MediaBrowser.ServerApplication/ImageEncoderHelper.cs index 77e6c65fec..0e99bbbad1 100644 --- a/MediaBrowser.ServerApplication/ImageEncoderHelper.cs +++ b/MediaBrowser.ServerApplication/ImageEncoderHelper.cs @@ -1,6 +1,5 @@ using System; using Emby.Drawing; -using Emby.Drawing.ImageMagick; using Emby.Drawing.Skia; using Emby.Server.Core; using Emby.Server.Implementations; diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index fba8f48118..6635cddb7b 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -236,18 +236,16 @@ namespace MediaBrowser.ServerApplication var resourcesPath = Path.GetDirectoryName(applicationPath); - Action createDirectoryFn = s => Directory.CreateDirectory(s); - if (runAsService) { var systemPath = Path.GetDirectoryName(applicationPath); var programDataPath = Path.GetDirectoryName(systemPath); - return new ServerApplicationPaths(programDataPath, appFolderPath, resourcesPath, createDirectoryFn); + return new ServerApplicationPaths(programDataPath, appFolderPath, resourcesPath); } - return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), appFolderPath, resourcesPath, createDirectoryFn); + return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), appFolderPath, resourcesPath); } /// @@ -316,10 +314,7 @@ namespace MediaBrowser.ServerApplication environmentInfo, new NullImageEncoder(), new SystemEvents(logManager.GetLogger("SystemEvents")), - new MemoryStreamProvider(), - new Networking.NetworkManager(logManager.GetLogger("NetworkManager")), - GenerateCertificate, - () => Environment.UserDomainName); + new Networking.NetworkManager(logManager.GetLogger("NetworkManager"))); var initProgress = new Progress(); @@ -366,11 +361,6 @@ namespace MediaBrowser.ServerApplication } } - private static void GenerateCertificate(string certPath, string certHost, string certPassword) - { - CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, certPassword, _logger); - } - private static ServerNotifyIcon _serverNotifyIcon; private static TaskScheduler _mainTaskScheduler; private static void ShowTrayIcon() diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index eed5bab8d3..2ee2acfc2e 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -201,10 +201,6 @@ {805844ab-e92f-45e6-9d99-4f6d48d129a5} Emby.Dlna - - {6cfee013-6e7c-432b-ac37-cabf0880c69a} - Emby.Drawing.ImageMagick - {2312da6d-ff86-4597-9777-bceec32d96dd} Emby.Drawing.Skia diff --git a/MediaBrowser.ServerApplication/WindowsAppHost.cs b/MediaBrowser.ServerApplication/WindowsAppHost.cs index c872d96e2d..d72bd532e1 100644 --- a/MediaBrowser.ServerApplication/WindowsAppHost.cs +++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs @@ -25,8 +25,8 @@ namespace MediaBrowser.ServerApplication { public class WindowsAppHost : ApplicationHost { - public WindowsAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action certificateGenerator, Func defaultUsernameFactory) - : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory) + public WindowsAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager) + : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, networkManager) { } -- cgit v1.2.3