From cc19c762b419fe427abb8d03a2625e2be796e443 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 24 May 2016 22:06:56 -0400 Subject: update refresh --- MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'MediaBrowser.Server.Implementations/Devices') diff --git a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs index 947933561..3dfc04c26 100644 --- a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs +++ b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs @@ -28,6 +28,7 @@ namespace MediaBrowser.Server.Implementations.Devices return base.IsVisible(user) && HasChildren(); } + [IgnoreDataMember] public override string CollectionType { get { return Model.Entities.CollectionType.Photos; } -- cgit v1.2.3 From ca100ff2d13b0bf885826e02e7c1ed6a4496694e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 30 May 2016 12:22:31 -0400 Subject: add null checks on session & device creation --- MediaBrowser.Server.Implementations/Devices/DeviceManager.cs | 5 +++++ MediaBrowser.Server.Implementations/Session/SessionManager.cs | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'MediaBrowser.Server.Implementations/Devices') diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index 6b1af8d2d..c3db9140c 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -51,6 +51,11 @@ namespace MediaBrowser.Server.Implementations.Devices public async Task RegisterDevice(string reportedId, string name, string appName, string appVersion, string usedByUserId) { + if (string.IsNullOrWhiteSpace(reportedId)) + { + throw new ArgumentNullException("reportedId"); + } + var device = GetDevice(reportedId) ?? new DeviceInfo { Id = reportedId diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 0dabcac4b..4386b785a 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -404,6 +404,10 @@ namespace MediaBrowser.Server.Implementations.Session /// SessionInfo. private async Task GetSessionInfo(string appName, string appVersion, string deviceId, string deviceName, string remoteEndPoint, User user) { + if (string.IsNullOrWhiteSpace(deviceId)) + { + throw new ArgumentNullException("deviceId"); + } var key = GetSessionKey(appName, deviceId); await _sessionLock.WaitAsync(CancellationToken.None).ConfigureAwait(false); -- cgit v1.2.3 From dc5f2dd440f0413c7de9766b7a630116e22afcec Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 29 Jun 2016 14:48:26 -0400 Subject: update logging --- .../BaseApplicationHost.cs | 4 +-- .../ScheduledTasks/ScheduledTaskWorker.cs | 39 ++++++++++------------ .../Serialization/JsonSerializer.cs | 8 +++-- .../Serialization/XmlSerializer.cs | 14 +++++--- .../Devices/DeviceRepository.cs | 20 +++++++---- 5 files changed, 48 insertions(+), 37 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Devices') diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index a76ab9f07..baf5afc1b 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -199,7 +199,7 @@ namespace MediaBrowser.Common.Implementations ILogManager logManager, IFileSystem fileSystem) { - XmlSerializer = new MediaBrowser.Common.Implementations.Serialization.XmlSerializer (fileSystem); + XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer")); FailedAssemblies = new List(); ApplicationPaths = applicationPaths; @@ -321,7 +321,7 @@ namespace MediaBrowser.Common.Implementations protected virtual IJsonSerializer CreateJsonSerializer() { - return new JsonSerializer(FileSystemManager); + return new JsonSerializer(FileSystemManager, LogManager.GetLogger("JsonSerializer")); } private void SetHttpLimit() diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 090966d2b..b34d57c42 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -122,30 +122,27 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { get { - if (_lastExecutionResult == null) - { - var path = GetHistoryFilePath(); + var path = GetHistoryFilePath(); - lock (_lastExecutionResultSyncLock) + lock (_lastExecutionResultSyncLock) + { + if (_lastExecutionResult == null) { - if (_lastExecutionResult == null) + try + { + _lastExecutionResult = JsonSerializer.DeserializeFromFile(path); + } + catch (DirectoryNotFoundException) + { + // File doesn't exist. No biggie + } + catch (FileNotFoundException) + { + // File doesn't exist. No biggie + } + catch (Exception ex) { - try - { - return JsonSerializer.DeserializeFromFile(path); - } - catch (DirectoryNotFoundException) - { - // File doesn't exist. No biggie - } - catch (FileNotFoundException) - { - // File doesn't exist. No biggie - } - catch (Exception ex) - { - Logger.ErrorException("Error deserializing {0}", ex, path); - } + Logger.ErrorException("Error deserializing {0}", ex, path); } } } diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index 6610cd3ff..5dbbe5373 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -2,6 +2,7 @@ using System; using System.IO; using CommonIO; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Implementations.Serialization { @@ -11,10 +12,12 @@ namespace MediaBrowser.Common.Implementations.Serialization public class JsonSerializer : IJsonSerializer { private readonly IFileSystem _fileSystem; - - public JsonSerializer(IFileSystem fileSystem) + private readonly ILogger _logger; + + public JsonSerializer(IFileSystem fileSystem, ILogger logger) { _fileSystem = fileSystem; + _logger = logger; Configure(); } @@ -65,6 +68,7 @@ namespace MediaBrowser.Common.Implementations.Serialization private Stream OpenFile(string path) { + _logger.Debug("Deserializing file {0}", path); return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072); } diff --git a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs index 189fb7afc..290524921 100644 --- a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.IO; using System.Xml; using CommonIO; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Implementations.Serialization { @@ -12,12 +13,14 @@ namespace MediaBrowser.Common.Implementations.Serialization /// public class XmlSerializer : IXmlSerializer { - private IFileSystem _fileSystem; + private readonly IFileSystem _fileSystem; + private readonly ILogger _logger; - public XmlSerializer(IFileSystem fileSystem) - { - _fileSystem = fileSystem; - } + public XmlSerializer(IFileSystem fileSystem, ILogger logger) + { + _fileSystem = fileSystem; + _logger = logger; + } // Need to cache these // http://dotnetcodebox.blogspot.com/2013/01/xmlserializer-class-may-result-in.html @@ -91,6 +94,7 @@ namespace MediaBrowser.Common.Implementations.Serialization /// System.Object. public object DeserializeFromFile(Type type, string file) { + _logger.Debug("Deserializing file {0}", file); using (var stream = _fileSystem.OpenRead(file)) { return DeserializeFromStream(type, stream); diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs index 368d21322..6e67af82b 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs @@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.Devices private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - private List _devices; + private Dictionary _devices; public DeviceRepository(IApplicationPaths appPaths, IJsonSerializer json, ILogger logger, IFileSystem fileSystem) { @@ -46,12 +46,12 @@ namespace MediaBrowser.Server.Implementations.Devices public Task SaveDevice(DeviceInfo device) { var path = Path.Combine(GetDevicePath(device.Id), "device.json"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); lock (_syncLock) { _json.SerializeToFile(device, path); - _devices = null; + _devices[device.Id] = device; } return Task.FromResult(true); } @@ -95,9 +95,15 @@ namespace MediaBrowser.Server.Implementations.Devices { if (_devices == null) { - _devices = LoadDevices().ToList(); + _devices = new Dictionary(StringComparer.OrdinalIgnoreCase); + + var devices = LoadDevices().ToList(); + foreach (var device in devices) + { + _devices[device.Id] = device; + } } - return _devices.ToList(); + return _devices.Values.ToList(); } } @@ -144,7 +150,7 @@ namespace MediaBrowser.Server.Implementations.Devices catch (DirectoryNotFoundException) { } - + _devices = null; } @@ -174,7 +180,7 @@ namespace MediaBrowser.Server.Implementations.Devices public void AddCameraUpload(string deviceId, LocalFileInfo file) { var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); lock (_syncLock) { -- cgit v1.2.3