diff options
Diffstat (limited to 'MediaBrowser.Common.Implementations')
16 files changed, 296 insertions, 102 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 7bd0ca7482..80f017f52b 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -211,6 +211,8 @@ namespace MediaBrowser.Common.Implementations JsonSerializer = CreateJsonSerializer(); Logger = LogManager.GetLogger("App"); + OnLoggerLoaded(true); + LogManager.LoggerLoaded += (s, e) => OnLoggerLoaded(false); IsFirstRun = !ConfigurationManager.CommonConfiguration.IsStartupWizardCompleted; progress.Report(2); @@ -219,16 +221,11 @@ namespace MediaBrowser.Common.Implementations ? LogSeverity.Debug : LogSeverity.Info; - // Put the app config in the log for troubleshooting purposes - Logger.LogMultiline("Application Configuration:", LogSeverity.Info, new StringBuilder(JsonSerializer.SerializeToString(ConfigurationManager.CommonConfiguration))); - progress.Report(3); DiscoverTypes(); progress.Report(14); - Logger.Info("Version {0} initializing", ApplicationVersion); - SetHttpLimit(); progress.Report(15); @@ -245,6 +242,47 @@ namespace MediaBrowser.Common.Implementations progress.Report(100); } + protected virtual void OnLoggerLoaded(bool isFirstLoad) + { + Logger.Info("Application version: {0}", ApplicationVersion); + + if (!isFirstLoad) + { + LogEnvironmentInfo(Logger, ApplicationPaths); + } + + // Put the app config in the log for troubleshooting purposes + Logger.LogMultiline("Application configuration:", LogSeverity.Info, new StringBuilder(JsonSerializer.SerializeToString(ConfigurationManager.CommonConfiguration))); + + if (Plugins != null) + { + var pluginBuilder = new StringBuilder(); + + foreach (var plugin in Plugins) + { + pluginBuilder.AppendLine(string.Format("{0} {1}", plugin.Name, plugin.Version)); + } + + Logger.LogMultiline("Plugins:", LogSeverity.Info, pluginBuilder); + } + } + + public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths) + { + logger.Info("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs())); + + 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); + + logger.Info("Application Path: {0}", appPaths.ApplicationPath); + + logger.Info("*** When reporting issues please include the entire log file. ***".ToUpper()); + } + protected virtual IJsonSerializer CreateJsonSerializer() { return new JsonSerializer(); @@ -342,6 +380,7 @@ namespace MediaBrowser.Common.Implementations /// </summary> protected virtual void FindParts() { + ConfigurationManager.AddParts(GetExports<IConfigurationFactory>()); Plugins = GetExports<IPlugin>(); } @@ -393,7 +432,7 @@ namespace MediaBrowser.Common.Implementations HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager, ConfigurationManager); RegisterSingleInstance(HttpClient); - NetworkManager = CreateNetworkManager(); + NetworkManager = CreateNetworkManager(LogManager.GetLogger("NetworkManager")); RegisterSingleInstance(NetworkManager); SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager, LogManager); @@ -461,7 +500,7 @@ namespace MediaBrowser.Common.Implementations } } - protected abstract INetworkManager CreateNetworkManager(); + protected abstract INetworkManager CreateNetworkManager(ILogger logger); /// <summary> /// Creates an instance of type and resolves all constructor dependancies @@ -631,6 +670,7 @@ namespace MediaBrowser.Common.Implementations return parts; } + private Version _version; /// <summary> /// Gets the current application version /// </summary> @@ -639,7 +679,7 @@ namespace MediaBrowser.Common.Implementations { get { - return GetType().Assembly.GetName().Version; + return _version ?? (_version = GetType().Assembly.GetName().Version); } } diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index 8c4840ea71..cb6121c9ff 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -1,10 +1,13 @@ -using System.IO; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; namespace MediaBrowser.Common.Implementations.Configuration @@ -26,6 +29,16 @@ namespace MediaBrowser.Common.Implementations.Configuration public event EventHandler<EventArgs> ConfigurationUpdated; /// <summary> + /// Occurs when [configuration updating]. + /// </summary> + public event EventHandler<ConfigurationUpdateEventArgs> NamedConfigurationUpdating; + + /// <summary> + /// Occurs when [named configuration updated]. + /// </summary> + public event EventHandler<ConfigurationUpdateEventArgs> NamedConfigurationUpdated; + + /// <summary> /// Gets the logger. /// </summary> /// <value>The logger.</value> @@ -74,6 +87,9 @@ namespace MediaBrowser.Common.Implementations.Configuration } } + private ConfigurationStore[] _configurationStores = {}; + private IConfigurationFactory[] _configurationFactories; + /// <summary> /// Initializes a new instance of the <see cref="BaseConfigurationManager" /> class. /// </summary> @@ -89,10 +105,14 @@ namespace MediaBrowser.Common.Implementations.Configuration UpdateCachePath(); } - /// <summary> - /// The _save lock - /// </summary> - private readonly object _configurationSaveLock = new object(); + public void AddParts(IEnumerable<IConfigurationFactory> factories) + { + _configurationFactories = factories.ToArray(); + + _configurationStores = _configurationFactories + .SelectMany(i => i.GetConfigurations()) + .ToArray(); + } /// <summary> /// Saves the configuration. @@ -103,7 +123,7 @@ namespace MediaBrowser.Common.Implementations.Configuration Directory.CreateDirectory(Path.GetDirectoryName(path)); - lock (_configurationSaveLock) + lock (_configurationSyncLock) { XmlSerializer.SerializeToFile(CommonConfiguration, path); } @@ -144,8 +164,8 @@ namespace MediaBrowser.Common.Implementations.Configuration /// </summary> private void UpdateCachePath() { - ((BaseApplicationPaths)CommonApplicationPaths).CachePath = string.IsNullOrEmpty(CommonConfiguration.CachePath) ? - null : + ((BaseApplicationPaths)CommonApplicationPaths).CachePath = string.IsNullOrEmpty(CommonConfiguration.CachePath) ? + null : CommonConfiguration.CachePath; } @@ -168,5 +188,70 @@ namespace MediaBrowser.Common.Implementations.Configuration } } } + + private readonly ConcurrentDictionary<string, object> _configurations = new ConcurrentDictionary<string, object>(); + + private string GetConfigurationFile(string key) + { + return Path.Combine(CommonApplicationPaths.ConfigurationDirectoryPath, key.ToLower() + ".xml"); + } + + public object GetConfiguration(string key) + { + return _configurations.GetOrAdd(key, k => + { + var file = GetConfigurationFile(key); + + var configurationType = _configurationStores + .First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)) + .ConfigurationType; + + lock (_configurationSyncLock) + { + return ConfigurationHelper.GetXmlConfiguration(configurationType, file, XmlSerializer); + } + }); + } + + public void SaveConfiguration(string key, object configuration) + { + var configurationType = GetConfigurationType(key); + + if (configuration.GetType() != configurationType) + { + throw new ArgumentException("Expected configuration type is " + configurationType.Name); + } + + EventHelper.FireEventIfNotNull(NamedConfigurationUpdating, this, new ConfigurationUpdateEventArgs + { + Key = key, + NewConfiguration = configuration + + }, Logger); + + _configurations.AddOrUpdate(key, configuration, (k, v) => configuration); + + var path = GetConfigurationFile(key); + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + lock (_configurationSyncLock) + { + XmlSerializer.SerializeToFile(configuration, path); + } + + EventHelper.FireEventIfNotNull(NamedConfigurationUpdated, this, new ConfigurationUpdateEventArgs + { + Key = key, + NewConfiguration = configuration + + }, Logger); + } + + public Type GetConfigurationType(string key) + { + return _configurationStores + .First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)) + .ConfigurationType; + } } } diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 5efb39cbc0..11a5cdf083 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -107,7 +107,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager return client; } - private PropertyInfo _httpBehaviorPropertyInfo; private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression) { var request = (HttpWebRequest)WebRequest.Create(options.Url); @@ -118,7 +117,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); - request.KeepAlive = options.EnableKeepAlive; + if (options.EnableKeepAlive) + { + request.KeepAlive = true; + } + request.Method = method; request.Pipelined = true; request.Timeout = 20000; @@ -133,21 +136,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager request.Referer = options.Referer; } -#if !__MonoCS__ - if (options.EnableKeepAlive) - { - // This is a hack to prevent KeepAlive from getting disabled internally by the HttpWebRequest - // May need to remove this for mono - var sp = request.ServicePoint; - if (_httpBehaviorPropertyInfo == null) - { - _httpBehaviorPropertyInfo = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic); - } - - _httpBehaviorPropertyInfo.SetValue(sp, (byte)0, null); - } -#endif - return request; } diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index dfe93c5c93..2d67ec9756 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -367,5 +367,20 @@ namespace MediaBrowser.Common.Implementations.IO return newPath; } + + public string GetFileNameWithoutExtension(FileSystemInfo info) + { + if (info is DirectoryInfo) + { + return info.Name; + } + + return Path.GetFileNameWithoutExtension(info.FullName); + } + + public string GetFileNameWithoutExtension(string path) + { + return Path.GetFileNameWithoutExtension(path); + } } } diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj index f06d1bc672..abb2f20896 100644 --- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj +++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj @@ -48,17 +48,17 @@ <RunPostBuildEvent>Always</RunPostBuildEvent> </PropertyGroup> <ItemGroup> - <Reference Include="NLog, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> + <Reference Include="NLog, Version=3.1.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\NLog.3.0.0.0\lib\net45\NLog.dll</HintPath> + <HintPath>..\packages\NLog.3.1.0.0\lib\net45\NLog.dll</HintPath> </Reference> <Reference Include="SimpleInjector, Version=2.5.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\SimpleInjector.2.5.0\lib\net45\SimpleInjector.dll</HintPath> + <HintPath>..\packages\SimpleInjector.2.5.2\lib\net45\SimpleInjector.dll</HintPath> </Reference> - <Reference Include="SimpleInjector.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL"> + <Reference Include="SimpleInjector.Diagnostics, Version=2.5.2.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\SimpleInjector.2.5.0\lib\net45\SimpleInjector.Diagnostics.dll</HintPath> + <HintPath>..\packages\SimpleInjector.2.5.2\lib\net45\SimpleInjector.Diagnostics.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Configuration" /> @@ -122,7 +122,7 @@ </ItemGroup> <ItemGroup /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <Import Project="$(SolutionDir)\.nuget\nuget.targets" Condition=" '$(ConfigurationName)' != 'Release Mono' " /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" /> <PropertyGroup> <PostBuildEvent Condition=" '$(ConfigurationName)' != 'Release Mono' ">if '$(ConfigurationName)' == 'Release' ( xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i @@ -135,4 +135,4 @@ xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i <Target Name="AfterBuild"> </Target> --> -</Project>
\ No newline at end of file +</Project> diff --git a/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs b/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs index e15c32518e..8159be6340 100644 --- a/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs +++ b/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs @@ -1,4 +1,5 @@ -using System; +using MediaBrowser.Model.Logging; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -10,6 +11,13 @@ namespace MediaBrowser.Common.Implementations.Networking { public abstract class BaseNetworkManager { + protected ILogger Logger { get; private set; } + + protected BaseNetworkManager(ILogger logger) + { + Logger = logger; + } + /// <summary> /// Gets the machine's local ip address /// </summary> @@ -26,6 +34,81 @@ namespace MediaBrowser.Common.Implementations.Networking return GetLocalIpAddressesFallback(); } + public bool IsInLocalNetwork(string endpoint) + { + return IsInLocalNetworkInternal(endpoint, true); + } + + public bool IsInLocalNetworkInternal(string endpoint, bool resolveHost) + { + if (string.IsNullOrWhiteSpace(endpoint)) + { + throw new ArgumentNullException("endpoint"); + } + + const int lengthMatch = 4; + + if (endpoint.Length >= lengthMatch) + { + var prefix = endpoint.Substring(0, lengthMatch); + + if (GetLocalIpAddresses() + .Any(i => i.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))) + { + return true; + } + } + + // Private address space: + // http://en.wikipedia.org/wiki/Private_network + + var isPrivate = + + // If url was requested with computer name, we may see this + endpoint.IndexOf("::", StringComparison.OrdinalIgnoreCase) != -1 || + + endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("192.", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("172.", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase); + + if (isPrivate) + { + return true; + } + + IPAddress address; + if (resolveHost && !IPAddress.TryParse(endpoint, out address)) + { + var host = new Uri(endpoint).DnsSafeHost; + + Logger.Debug("Resolving host {0}", host); + + try + { + address = GetIpAddresses(host).FirstOrDefault(); + + if (address != null) + { + Logger.Debug("{0} resolved to {1}", host, address); + + return IsInLocalNetworkInternal(address.ToString(), false); + } + } + catch (Exception ex) + { + Logger.ErrorException("Error resovling hostname {0}", ex, host); + } + } + + return false; + } + + public IEnumerable<IPAddress> GetIpAddresses(string hostName) + { + return Dns.GetHostAddresses(hostName); + } + private IEnumerable<IPAddress> GetIPsDefault() { foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) @@ -63,7 +146,7 @@ namespace MediaBrowser.Common.Implementations.Networking .Select(i => i.ToString()) .Reverse(); } - + /// <summary> /// Gets a random port number that is currently available /// </summary> diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 68222d8436..0dc67f8c00 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -547,6 +547,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks if (ex != null) { result.ErrorMessage = ex.Message; + result.LongErrorMessage = ex.StackTrace; } var path = GetHistoryFilePath(); diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index ddaa8df7d0..fcb7b159b8 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -46,7 +46,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks return new ITaskTrigger[] { // At startup - new StartupTrigger (), + new StartupTrigger {DelayMs = 60000}, // Every so often new IntervalTrigger { Interval = TimeSpan.FromHours(24)} diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs index e5c5638c01..3b0c02dc6b 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -43,7 +43,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks return new ITaskTrigger[] { // At startup - new StartupTrigger (), + new StartupTrigger {DelayMs = 30000}, // Every so often new IntervalTrigger { Interval = TimeSpan.FromHours(24)} diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs index f70b849eea..e31fc4abef 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -41,7 +41,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks return new ITaskTrigger[] { // At startup - new StartupTrigger (), + new StartupTrigger(), // Every so often new IntervalTrigger { Interval = TimeSpan.FromHours(24)} diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs index 641d402bda..6a9443ad73 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs @@ -52,7 +52,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks return new ITaskTrigger[] { // At startup - new StartupTrigger (), + new StartupTrigger(), // Every so often new IntervalTrigger { Interval = TimeSpan.FromHours(24)} diff --git a/MediaBrowser.Common.Implementations/Security/UsageReporter.cs b/MediaBrowser.Common.Implementations/Security/UsageReporter.cs index 6982d49fde..89ca0a0e47 100644 --- a/MediaBrowser.Common.Implementations/Security/UsageReporter.cs +++ b/MediaBrowser.Common.Implementations/Security/UsageReporter.cs @@ -26,16 +26,13 @@ namespace MediaBrowser.Common.Implementations.Security var mac = _networkManager.GetMacAddress(); - var plugins = string.Join("|", _applicationHost.Plugins.Select(i => i.Name).ToArray()); - var data = new Dictionary<string, string> { { "feature", _applicationHost.Name }, { "mac", mac }, { "ver", _applicationHost.ApplicationVersion.ToString() }, { "platform", Environment.OSVersion.VersionString }, - { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower()}, - { "plugins", plugins} + { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower()} }; return _httpClient.Post(Constants.Constants.MbAdminUrl + "service/registration/ping", data, cancellationToken); diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index 130e21b6ef..e7fd121788 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -210,25 +210,5 @@ namespace MediaBrowser.Common.Implementations.Serialization return ServiceStack.Text.JsonSerializer.SerializeToString(obj, obj.GetType()); } - - /// <summary> - /// Serializes to bytes. - /// </summary> - /// <param name="obj">The obj.</param> - /// <returns>System.Byte[][].</returns> - /// <exception cref="System.ArgumentNullException">obj</exception> - public byte[] SerializeToBytes(object obj) - { - if (obj == null) - { - throw new ArgumentNullException("obj"); - } - - using (var stream = new MemoryStream()) - { - SerializeToStream(obj, stream); - return stream.ToArray(); - } - } } } diff --git a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs index 06c60dacda..cef744753a 100644 --- a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs @@ -91,20 +91,5 @@ namespace MediaBrowser.Common.Implementations.Serialization return DeserializeFromStream(type, stream); } } - - /// <summary> - /// Serializes to bytes. - /// </summary> - /// <param name="obj">The obj.</param> - /// <returns>System.Byte[][].</returns> - public byte[] SerializeToBytes(object obj) - { - using (var stream = new MemoryStream()) - { - SerializeToStream(obj, stream); - - return stream.ToArray(); - } - } } } diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index 895c430767..e4c88e6568 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// <param name="newVersion">The new version.</param> private void OnPluginUpdated(IPlugin plugin, PackageVersionInfo newVersion) { - _logger.Info("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.version, newVersion.classification); + _logger.Info("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.versionStr ?? string.Empty, newVersion.classification); EventHelper.FireEventIfNotNull(PluginUpdated, this, new GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> { Argument = new Tuple<IPlugin, PackageVersionInfo>(plugin, newVersion) }, _logger); @@ -87,7 +87,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// <param name="package">The package.</param> private void OnPluginInstalled(PackageVersionInfo package) { - _logger.Info("New plugin installed: {0} {1} {2}", package.name, package.version, package.classification); + _logger.Info("New plugin installed: {0} {1} {2}", package.name, package.versionStr ?? string.Empty, package.classification); EventHelper.FireEventIfNotNull(PluginInstalled, this, new GenericEventArgs<PackageVersionInfo> { Argument = package }, _logger); @@ -133,6 +133,16 @@ namespace MediaBrowser.Common.Implementations.Updates _logger = logger; } + private Version GetPackageVersion(PackageVersionInfo version) + { + return new Version(ValueOrDefault(version.versionStr, "0.0.0.1")); + } + + private static string ValueOrDefault(string str, string def) + { + return string.IsNullOrEmpty(str) ? def : str; + } + /// <summary> /// Gets all available packages. /// </summary> @@ -167,17 +177,27 @@ namespace MediaBrowser.Common.Implementations.Updates { if (_lastPackageListResult != null) { - // Let dev users get results more often for testing purposes - var cacheLength = _config.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev - ? TimeSpan.FromMinutes(3) - : TimeSpan.FromHours(6); + TimeSpan cacheLength; + + switch (_config.CommonConfiguration.SystemUpdateLevel) + { + case PackageVersionClass.Beta: + cacheLength = TimeSpan.FromMinutes(30); + break; + case PackageVersionClass.Dev: + cacheLength = TimeSpan.FromMinutes(3); + break; + default: + cacheLength = TimeSpan.FromHours(6); + break; + } if ((DateTime.UtcNow - _lastPackageListResult.Item2) < cacheLength) { return _lastPackageListResult.Item1; } } - + using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); @@ -197,7 +217,7 @@ namespace MediaBrowser.Common.Implementations.Updates foreach (var package in packages) { package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl)) - .OrderByDescending(v => v.version).ToList(); + .OrderByDescending(GetPackageVersion).ToList(); } // Remove packages with no versions @@ -211,7 +231,7 @@ namespace MediaBrowser.Common.Implementations.Updates foreach (var package in packages) { package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl)) - .OrderByDescending(v => v.version).ToList(); + .OrderByDescending(GetPackageVersion).ToList(); } if (packageType.HasValue) @@ -264,7 +284,7 @@ namespace MediaBrowser.Common.Implementations.Updates { var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); - var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase)) + var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase)) ?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (package == null) @@ -272,7 +292,7 @@ namespace MediaBrowser.Common.Implementations.Updates return null; } - return package.versions.FirstOrDefault(v => v.version.Equals(version) && v.classification == classification); + return package.versions.FirstOrDefault(v => GetPackageVersion(v).Equals(version) && v.classification == classification); } /// <summary> @@ -300,7 +320,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// <returns>PackageVersionInfo.</returns> public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) { - var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase)) + var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase)) ?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (package == null) @@ -309,7 +329,7 @@ namespace MediaBrowser.Common.Implementations.Updates } return package.versions - .OrderByDescending(v => v.version) + .OrderByDescending(GetPackageVersion) .FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, currentServerVersion)); } @@ -338,7 +358,7 @@ namespace MediaBrowser.Common.Implementations.Updates { var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, _config.CommonConfiguration.SystemUpdateLevel); - return latestPluginInfo != null && latestPluginInfo.version != null && latestPluginInfo.version > p.Version ? latestPluginInfo : null; + return latestPluginInfo != null && GetPackageVersion(latestPluginInfo) > p.Version ? latestPluginInfo : null; }).Where(i => i != null).ToList(); diff --git a/MediaBrowser.Common.Implementations/packages.config b/MediaBrowser.Common.Implementations/packages.config index f00c85d717..4f2a4c2244 100644 --- a/MediaBrowser.Common.Implementations/packages.config +++ b/MediaBrowser.Common.Implementations/packages.config @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="NLog" version="3.0.0.0" targetFramework="net45" /> + <package id="NLog" version="3.1.0.0" targetFramework="net45" /> <package id="sharpcompress" version="0.10.2" targetFramework="net45" /> - <package id="SimpleInjector" version="2.5.0" targetFramework="net45" /> + <package id="SimpleInjector" version="2.5.2" targetFramework="net45" /> </packages>
\ No newline at end of file |
