diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.cs index 3cc6a4379d..b4127a91f1 100644 --- a/MediaBrowser.Dlna/DlnaManager.cs +++ b/MediaBrowser.Dlna/DlnaManager.cs @@ -29,6 +29,8 @@ namespace MediaBrowser.Dlna private readonly IJsonSerializer _jsonSerializer; private readonly IServerApplicationHost _appHost; + private readonly Dictionary _profiles = new Dictionary(StringComparer.Ordinal); + public DlnaManager(IXmlSerializer xmlSerializer, IFileSystem fileSystem, IApplicationPaths appPaths, @@ -300,20 +302,31 @@ namespace MediaBrowser.Dlna private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type) { - try + lock (_profiles) { - var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); + DeviceProfile profile; + if (_profiles.TryGetValue(path, out profile)) + { + return profile; + } + + try + { + profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - profile.Id = path.ToLower().GetMD5().ToString("N"); - profile.ProfileType = type; + profile.Id = path.ToLower().GetMD5().ToString("N"); + profile.ProfileType = type; - return profile; - } - catch (Exception ex) - { - _logger.ErrorException("Error parsing profile xml: {0}", ex, path); + _profiles[path] = profile; - return null; + return profile; + } + catch (Exception ex) + { + _logger.ErrorException("Error parsing profile xml: {0}", ex, path); + + return null; + } } } @@ -428,7 +441,7 @@ namespace MediaBrowser.Dlna var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml"; var path = Path.Combine(UserProfilesPath, newFilename); - _xmlSerializer.SerializeToFile(profile, path); + SaveProfile(profile, path); } public void UpdateProfile(DeviceProfile profile) @@ -455,6 +468,15 @@ namespace MediaBrowser.Dlna _fileSystem.DeleteFile(current.Path); } + SaveProfile(profile, path); + } + + private void SaveProfile(DeviceProfile profile, string path) + { + lock (_profiles) + { + _profiles[path] = profile; + } _xmlSerializer.SerializeToFile(profile, path); } diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs index 3c4b477d53..79872b1004 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs @@ -162,6 +162,8 @@ namespace MediaBrowser.Server.Implementations.Connect { var path = CacheFilePath; + _logger.Info("Loading data from {0}", path); + try { var endpoint = _fileSystem.ReadAllText(path, Encoding.UTF8); diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index ce39601fd1..8dbea707d1 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -359,7 +359,7 @@ namespace MediaBrowser.Server.Implementations.Connect { var path = CacheFilePath; - _logger.Debug("Loading data from {0}", path); + _logger.Info("Loading data from {0}", path); try {